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

本文介绍了一种在一台服务器上同时配置电信和网通双栈网络的方法。通过设置两个不同的默认网关,实现不同运营商间的流量分离。具体步骤包括修改路由表、设置网关和源地址等。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
我的博客已迁移到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命令

wKioL1WpBN6AkuV4AAF4h4beglo963.jpg










本文转自 xdoujiang 51CTO博客,原文链接:http://blog.51cto.com/7938217/1675792,如需转载请自行联系原作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值