cat net.sh
#!/bin/bash
#--------------------------------------------------
#Author:jimmygong
#Email:jimmygong@taomee.com
#FileName:ip.sh
#Function:
#Version:1.0
#Created:2015-07-17
#--------------------------------------------------
rttable=`cat /etc/iproute2/rt_tables|egrep "251|252"`
if [[ $? -eq 1 ]]
then
echo ‘252 cnc‘ >> /etc/iproute2/rt_tables
echo ‘251 ctc‘ >> /etc/iproute2/rt_tables
else
exit 1
fi
ctcgw=1.1.1.1
cncgw=2.2.2.2
ctceth=eth0
cnceth=eth2
ctcip=`cat /etc/sysconfig/network-scripts/ifcfg-$ctceth|grep -i ^ipaddr|awk -F \= ‘{print $2}‘`
cncip=`cat /etc/sysconfig/network-scripts/ifcfg-$cnceth|grep -i ^ipaddr|awk -F \= ‘{print $2}‘`
ip route flush table ctc
ip route add default via $ctcgw dev $ctceth src $ctcip table ctc
ip rule add from $ctcip table ctc
ip route flush table cnc
ip route add default via $cncgw dev $cnteth src $cncip table cnc
ip rule add from $cncip table cnc
一些说明
1、配置说明
表255 local(本地路由表)
表254 main(主路由表)
表253 default(默认路由表)
2、查看路由表内容
ip route list table ctc
default via 1.1.1.1 dev eth0 src 111.111.111.111
ip route list table cnc
default via 2.2.2.2 dev eth2 src 222.222.222.222
3、需要安装iproute包(也就是ip命令)
yum -y install iproute
4、变量说明
ctcgw 表示电信网关
cncgw 表示网通网关
ctceth 使用eth0 接电信外网ip
cnceth 使用eth2 接网通外网ip
eth1 接的内网
5、ip命令本文出自 “7928217” 博客,请务必保留此出处http://7938217.blog.51cto.com/7928217/1675792
原文:http://7938217.blog.51cto.com/7928217/1675792