近期业务需求需要配置多线
电信IP:113.108.222.106
掩码:255.255.255.240
电信网关:113.108.222.97
联通IP:122.13.72.123
掩码:255.255.255.240
联通网关:122.13.72.113
移动IP:183.232.72.178
掩码:255.255.255.240
移动网关:183.232.72.1
centos单网卡多线配置
首先复制2份虚拟网卡
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1
然后编辑三张网卡配置信息
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:26:6C:F0:24:74
TYPE=Ethernet
UUID=701696b6-b01b-45aa-bfdd-aca1563e6072
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=113.108.222.106
NETMASK=255.255.255.240
GATEWAY=113.108.222.97
# vim /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0 记得网卡名称要修改
HWADDR=00:26:6C:F0:24:74
TYPE=Ethernet
UUID=701696b6-b01b-45aa-bfdd-aca1563e6072
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=122.13.72.123 记得ip地址要对应的Ip地址
NETMASK=255.255.255.240
#GATEWAY=122.13.72.113 记得网关注释掉
# vim /etc/sysconfig/network-scripts/ifcfg-eth0:1
DEVICE=eth0:1 记得网卡名称要修改
HWADDR=00:26:6C:F0:24:74
TYPE=Ethernet
UUID=701696b6-b01b-45aa-bfdd-aca1563e6072
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=183.232.72.178 记得ip地址要对应的Ip地址
NETMASK=255.255.255.240
#GATEWAY=183.232.72.1 记得网关注释掉
好了三块网卡信息都配置正确了
现在来配置路由表
# vim /etc/iproute2/rt_tables 编辑路由表信息
#
# reserved values
#
255local
254main
253default
252tel 这条是添加的代表电信
251cnc 这条是添加的代表联通
250cmc 这条是添加的代表移动
0unspec
#
# local
#
#1inr.ruhep
然后在执行一下命令
ip route flush table tel 刷新路由表
ip route add default via 113.108.222.97 dev eth0 src 113.108.222.106 table tel 电信路由表,源113.108.222.106通过113.108.222.97网关出去
ip rule add from 113.108.222.106 table tel 来自113.108.222.106
ip route flush table cnc
ip route add default via 122.13.72.113 dev eth0:0 src 122.13.72.123 table cnc
ip rule add from 122.13.72.123 table cnc
ip route flush table cmc
ip route add default via 183.232.72.177 dev eth0:1 src 183.232.72.178 table cmc
ip rule add from 183.232.72.178 table cmc
执行就可以通了,但是重启就消失了。
配置network启动脚本文件 在结尾exit 0之前增加如下内容:
# vi /etc/rc.d/init.d/network
ip rule add from 113.108.222.106 table tel 来自113.108.222.106
ip route flush table cnc
ip route add default via 122.13.72.113 dev eth0:0 src 122.13.72.123 table cnc
ip rule add from 122.13.72.123 table cnc
ip route flush table cmc
ip route add default via 183.232.72.177 dev eth0:1 src 183.232.72.178 table cmc
ip rule add from 183.232.72.178 table cmc
exit 0
7、重启系统或网络可能失效,请加入启动脚本:
如果是ubuntu/debian,系统启动脚本是/etc/rc.local
如果是RedHat/centos,系统启动脚本是/etc/rc.d/rc.local
如果是ubuntu/debian,网络启动脚本是/etc/init.d/networking
如果是RedHat/centos,网络启动脚本是/etc/rc.d/init.d/network
本文出自 “笑尔编个核\壳?” 博客,请务必保留此出处http://webjin.blog.51cto.com/722625/1403106