Linux 多网卡多路由实现策略路由
2016-06-16 11:48
369 查看
两个不在一段的IP看成一个电信一个网通来设置 就可以了。centos无问题
1. vi /etc/iproute2/rt_tables,增加网通和电信两个路由表
251 tel 电信路由表
252 cnc 网通路由表
2. 给网卡绑定两个地址用于电信和网通两个线路
ip addr add 192.168.0.2/24 dev eth0
ip addr add 10.0.0.2/24 dev eth1
3、分别设置电信和网通的路由表
电信路由表:
#确保找到本地子网
ip route add 192.168.0..0/24 via 192.168.0.2 dev eth0table tel
#内部回环网络
ip route add 127.0.0.0/8 dev lo table tel
#192.168.0.1为电信网络默认网关地址
ip route add default via 192.168.0.1 dev eth0 table tel
网通线路路由表:
#确保找到本地子网
ip route add 10.0.0.0/24 via 10.0.0.2 dev eth1 table cnc
#内部回环网络
ip route add 127.0.0.0/8 dev lo table cnc
#10.0.0.1是网通的默认网关
ip route add default via 10.0.0.1 dev eth1 table cnc
4、电信和网通各有自己的路由表,制定策略,让192.168.0.2的回应数据包走电信的路由表路由,10.0.0.2的回应数据包走网通的路由表路由
ip rule add from 192.168.0.1 table tel
ip rule add from 10.0.0.1 table cnc
最后考虑特殊情况的网管需要批量添加IP到路由才能过,简化一下
ip rule del from 192.168.0.0/24 table tel
ip rule del from 10.0.0.0/24 table cnc
其二
网络配置,以服务器A为例,注意注释默认网关
cat/etc/sysconfig/network-scripts/ifcfg-ens4f0 DEVICE=ens4f0ONBOOT=yesBOOTPROTO=staticTYPE=EthernetIPADDR=172.31.192.201NETMASK=255.255.255.0#GATEWAY=172.31.192.254 cat/etc/sysconfig/network-scripts/ifcfg-ens9f0 DEVICE=ens9f0ONBOOT=yesBOOTPROTO=staticTYPE=EthernetIPADDR=172.31.196.1NETMASK=255.255.255.0#GATEWAY=172.31.196.254
策略路由配置注意配置名称一定要吻合
#编辑rt_tables
echo "192 net_192 " >>/etc/iproute2/rt_tables
echo "196 net_196 " >>/etc/iproute2/rt_tables
#清空net_192路由表
ip route flush table net_192
# 添加一个路由规则到 net_192 表,这条规则是 net_192 这个路由表中数据包默认使用源 IP 172.31.192.201 通过 ens4f0 走网关 172.31.192.254
ip route add default via 172.31.192.254 dev ens4f0 src172.31.192.201 table net_192
#来自 172.31.192.201 的数据包,使用 net_192 路由表的路由规则
ip rule add from 172.31.192.201 table net_192
#清空net_196路由表
ip route flush table net_196
#添加一个路由规则到 net_196 表,这条规则是 net_196 这个路由表中数据包默认使用源 IP 172.31.196.1 通过 ens9f0 走网关 172.31.196.254
ip route add default via 172.31.196.254 dev ens9f0 src172.31.196.1 table net_196
#来自 172.31.196.1 的数据包,使用 net_196 路由表的路由规则
ip rule add from 172.31.196.1 table net_196
#添加默认网关
route add default gw 172.31.192.254
#如果需要自启动生效可以写进配置文件也可以加入rc.local
vi /etc/rc.local
ip route flush table net_192
ip route add default via 172.31.192.254 dev ens4f0 src172.31.192.201 table net_192
ip rule add from 172.31.192.201 table net_192
ip route flush table net_196
ip route add default via 172.31.196.254 dev ens9f0 src172.31.196.1 table net_196
ip rule add from 172.31.196.1 table net_196
route add default gw 172.31.192.254
#查看路由表
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
169.254.0.0 0.0.0.0 255.255.0.0 U 1006 0 0 ens9f0
169.254.0.0 0.0.0.0 255.255.0.0 U 1008 0 0 ens4f0
169.254.0.0 0.0.0.0 255.255.0.0 U 1014 0 0 br-ex
169.254.0.0 0.0.0.0 255.255.0.0 U 1015 0 0 br-int
172.31.192.0 0.0.0.0 255.255.255.0 U 0 0 0 ens4f0
172.31.196.0 0.0.0.0 255.255.255.0 U 0 0 0 ens9f0
#在接入测试服务器上验证连通性
ping 172.31.192.201
ping 172.31.196.1
1. vi /etc/iproute2/rt_tables,增加网通和电信两个路由表
251 tel 电信路由表
252 cnc 网通路由表
2. 给网卡绑定两个地址用于电信和网通两个线路
ip addr add 192.168.0.2/24 dev eth0
ip addr add 10.0.0.2/24 dev eth1
3、分别设置电信和网通的路由表
电信路由表:
#确保找到本地子网
ip route add 192.168.0..0/24 via 192.168.0.2 dev eth0table tel
#内部回环网络
ip route add 127.0.0.0/8 dev lo table tel
#192.168.0.1为电信网络默认网关地址
ip route add default via 192.168.0.1 dev eth0 table tel
网通线路路由表:
#确保找到本地子网
ip route add 10.0.0.0/24 via 10.0.0.2 dev eth1 table cnc
#内部回环网络
ip route add 127.0.0.0/8 dev lo table cnc
#10.0.0.1是网通的默认网关
ip route add default via 10.0.0.1 dev eth1 table cnc
4、电信和网通各有自己的路由表,制定策略,让192.168.0.2的回应数据包走电信的路由表路由,10.0.0.2的回应数据包走网通的路由表路由
ip rule add from 192.168.0.1 table tel
ip rule add from 10.0.0.1 table cnc
最后考虑特殊情况的网管需要批量添加IP到路由才能过,简化一下
ip rule del from 192.168.0.0/24 table tel
ip rule del from 10.0.0.0/24 table cnc
其二
网卡显示名称 | IP地址 | 子网掩码 | 网关 | 备注 |
ens4f0 | 172.31.192.201 | 255.255.255.0 | 172.31.192.254 | 服务器A |
ens9f0 | 172.31.196.1 | 255.255.255.0 | 172.31.196.254 | 服务器A |
ens4f0 | 172.31.192.202 | 255.255.255.0 | 172.31.192.254 | 服务器B |
ens9f0 | 172.31.196.2 | 255.255.255.0 | 172.31.196.254 | 服务器B |
/ | 172.25.168.44 | 255.255.255.0 | 172.25.168.254 | 接入测试 |
cat/etc/sysconfig/network-scripts/ifcfg-ens4f0 DEVICE=ens4f0ONBOOT=yesBOOTPROTO=staticTYPE=EthernetIPADDR=172.31.192.201NETMASK=255.255.255.0#GATEWAY=172.31.192.254 cat/etc/sysconfig/network-scripts/ifcfg-ens9f0 DEVICE=ens9f0ONBOOT=yesBOOTPROTO=staticTYPE=EthernetIPADDR=172.31.196.1NETMASK=255.255.255.0#GATEWAY=172.31.196.254
策略路由配置注意配置名称一定要吻合
#编辑rt_tables
echo "192 net_192 " >>/etc/iproute2/rt_tables
echo "196 net_196 " >>/etc/iproute2/rt_tables
#清空net_192路由表
ip route flush table net_192
# 添加一个路由规则到 net_192 表,这条规则是 net_192 这个路由表中数据包默认使用源 IP 172.31.192.201 通过 ens4f0 走网关 172.31.192.254
ip route add default via 172.31.192.254 dev ens4f0 src172.31.192.201 table net_192
#来自 172.31.192.201 的数据包,使用 net_192 路由表的路由规则
ip rule add from 172.31.192.201 table net_192
#清空net_196路由表
ip route flush table net_196
#添加一个路由规则到 net_196 表,这条规则是 net_196 这个路由表中数据包默认使用源 IP 172.31.196.1 通过 ens9f0 走网关 172.31.196.254
ip route add default via 172.31.196.254 dev ens9f0 src172.31.196.1 table net_196
#来自 172.31.196.1 的数据包,使用 net_196 路由表的路由规则
ip rule add from 172.31.196.1 table net_196
#添加默认网关
route add default gw 172.31.192.254
#如果需要自启动生效可以写进配置文件也可以加入rc.local
vi /etc/rc.local
ip route flush table net_192
ip route add default via 172.31.192.254 dev ens4f0 src172.31.192.201 table net_192
ip rule add from 172.31.192.201 table net_192
ip route flush table net_196
ip route add default via 172.31.196.254 dev ens9f0 src172.31.196.1 table net_196
ip rule add from 172.31.196.1 table net_196
route add default gw 172.31.192.254
#查看路由表
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
169.254.0.0 0.0.0.0 255.255.0.0 U 1006 0 0 ens9f0
169.254.0.0 0.0.0.0 255.255.0.0 U 1008 0 0 ens4f0
169.254.0.0 0.0.0.0 255.255.0.0 U 1014 0 0 br-ex
169.254.0.0 0.0.0.0 255.255.0.0 U 1015 0 0 br-int
172.31.192.0 0.0.0.0 255.255.255.0 U 0 0 0 ens4f0
172.31.196.0 0.0.0.0 255.255.255.0 U 0 0 0 ens9f0
#在接入测试服务器上验证连通性
ping 172.31.192.201
ping 172.31.196.1
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍