您的位置:首页 > 其它

iproute2配置电信网通(策略路由)

2015-07-17 21:30 435 查看
我的博客已迁移到xdoujiang.com请去那边和我交流
cat ip.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 [[ $? -ne 0 ]]
then
echo '252 cnc' >> /etc/iproute2/rt_tables
echo '251 ctc' >> /etc/iproute2/rt_tables
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 $cnceth 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命令


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iproute ip