LINUX系统的双网卡双IP(双链路)实现方式
当你的服务器为了不间断的向外提供服务,需要选择两个或两个以上的运营商的数据接入时。路由就成为一个问题,如何使电信的客户使用电信的链路,网通的客户使用网通的链路访问服务器。下面就如何实现这一功能作详细的介绍:
第一种方法
Vi /etc/rt.sh
#!/bin/bash
IF1=eth0
IP1=电信IP
P1_NET=电信网段/掩码
IP1_GW=电信网关
IF2=eth1
IP2=网通IP
P2_NET=网通网段/掩码
IP2_GW=网通网关
ip route add $P1_NET dev $IF1 src $IP1 table TEL
ip route add default via $IP1_GW table TEL
ip route add $P2_NET dev $IF2 src $IP2 table EDU
ip route add default via $IP2_GW table EDU
ip route add default via $IP1_GW
ip route flush cache
ip rule add from $IP1 table TEL
ip rule add from $IP2 table EDU
记住wq保存
vi /etc/iproute2/rt_tables
# reserved values
#255 local
#254 main
#253 default
#0 unspec
#
# local
#
#1 inr.ruhep
252 TEL
251 CNC
后wq保存
命令行下启用这个脚本:
chmod 750 /etc/rt.sh
命令行下每次运行这个脚本:
./etc/rt.sh
上面两条命令只对当前有效,当服务器重启时无效,为了让服务器每次重启后自动运行脚本则:
Vi /etc/rc.d/rc.local
/etc/rt.sh
这是一种方法,不一定是很好使,你可以试试
第二种方法
Vi /etc/rc.local
ip route add default via 电信网关 table 10
ip rule add from 电信IP table 10
ip route add default via 网通网关table 11
ip rule add from 网通IP table 11
第三种方法
vi /usr/local/bin/gw.sh
#!/bin/sh
/sbin/ip rule add from 网通网段/掩码 pref 10000 table cnc
/sbin/ip route add default via 网通网关 table cnc
/sbin/ip route flush cache
~
vi /usr/local/bin/cncip.sh
/sbin/ip ru ls|grep 20001:|awk '{print "ip ru del to", $5," pref 20001 table cnc"}'|sh
/sbin/ip rule add to 121.100.128.0/17 pref 20001 table cnc
/sbin/ip rule add to 121.100.128.0/19 pref 20001 table cnc
/sbin/ip rule add to 121.16.0.0/13 pref 20001 table cnc
/sbin/ip rule add to 121.24.0.0/14 pref 20001 table cnc
/sbin/ip rule add to 121.28.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 121.30.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 121.31.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 121.51.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 121.89.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 122.0.128.0/17 pref 20001 table cnc
/sbin/ip rule add to 122.198.192.0/18 pref 20001 table cnc
/sbin/ip rule add to 124.128.0.0/13 pref 20001 table cnc
/sbin/ip rule add to 124.128.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.160.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.160.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.161.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.161.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.162.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.162.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.163.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.163.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.164.0.0/14 pref 20001 table cnc
/sbin/ip rule add to 124.164.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.198.0.0/18 pref 20001 table cnc
/sbin/ip rule add to 124.198.192.0/18 pref 20001 table cnc
/sbin/ip rule add to 124.21.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.248.64.0/18 pref 20001 table cnc
/sbin/ip rule add to 124.254.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.64.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 124.66.0.0/17 pref 20001 table cnc
/sbin/ip rule add to 124.67.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.88.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.89.0.0/17 pref 20001 table cnc
/sbin/ip rule add to 124.89.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.89.128.0/17 pref 20001 table cnc
/sbin/ip rule add to 124.90.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 124.90.0/16 pref 20001 table cnc
/sbin/ip rule add to 124.92.0.0/14 pref 20001 table cnc
/sbin/ip rule add to 124.92.0/16 pref 20001 table cnc
/sbin/ip rule add to 125.32.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 125.33.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 125.34.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 125.35.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 125.35.128.0/17 pref 20001 table cnc
/sbin/ip rule add to 125.36.0.0/14 pref 20001 table cnc
/sbin/ip rule add to 125.40.0.0/13 pref 20001 table cnc
/sbin/ip rule add to 202.102.128.0/18 pref 20001 table cnc
/sbin/ip rule add to 202.102.224.0/19 pref 20001 table cnc
/sbin/ip rule add to 202.106.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 202.107.0.0/17 pref 20001 table cnc
/sbin/ip rule add to 202.108.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 202.110.0.0/18 pref 20001 table cnc
/sbin/ip rule add to 202.110.192.0/18 pref 20001 table cnc
/sbin/ip rule add to 202.110.64.0/18 pref 20001 table cnc
/sbin/ip rule add to 202.111.128.0/19 pref 20001 table cnc
/sbin/ip rule add to 202.111.160.0/19 pref 20001 table cnc
/sbin/ip rule add to 202.142.16.0/14 pref 20001 table cnc
/sbin/ip rule add to 202.142.16.0/20 pref 20001 table cnc
/sbin/ip rule add to 202.74.208.0/22 pref 20001 table cnc
/sbin/ip rule add to 202.74.8.0/20 pref 20001 table cnc
/sbin/ip rule add to 202.74.8.0/21 pref 20001 table cnc
/sbin/ip rule add to 202.75.144.0/20 pref 20001 table cnc
/sbin/ip rule add to 202.75.208.0/22 pref 20001 table cnc
/sbin/ip rule add to 202.75.212.0/22 pref 20001 table cnc
/sbin/ip rule add to 202.75.212/19 pref 20001 table cnc
/sbin/ip rule add to 202.76.160.0/19 pref 20001 table cnc
/sbin/ip rule add to 202.96.64.0/19 pref 20001 table cnc
/sbin/ip rule add to 202.97.128.0/19 pref 20001 table cnc
/sbin/ip rule add to 202.97.160.0/19 pref 20001 table cnc
/sbin/ip rule add to 202.97.192.0/18 pref 20001 table cnc
/sbin/ip rule add to 202.98.0.0/19 pref 20001 table cnc
/sbin/ip rule add to 202.99.0.0/23 pref 20001 table cnc
/sbin/ip rule add to 202.99.128.0/18 pref 20001 table cnc
/sbin/ip rule add to 202.99.192.0/19 pref 20001 table cnc
/sbin/ip rule add to 202.99.224.0/19 pref 20001 table cnc
/sbin/ip rule add to 202.99.64.0/18 pref 20001 table cnc
/sbin/ip rule add to 203.166.160.0/19 pref 20001 table cnc
/sbin/ip rule add to 203.93.0.0/25 pref 20001 table cnc
/sbin/ip rule add to 203.93.0.0/25 pref 20001 table cnc
/sbin/ip rule add to 203.93.141.0/24 pref 20001 table cnc
/sbin/ip rule add to 210.12.128.0/24 pref 20001 table cnc
/sbin/ip rule add to 210.12.192.0/24 pref 20001 table cnc
/sbin/ip rule add to 210.14.160.0/18 pref 20001 table cnc
/sbin/ip rule add to 210.21.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 210.21.0.0/17 pref 20001 table cnc
/sbin/ip rule add to 210.22.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 210.51.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 210.52.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 210.52.64.0/18 pref 20001 table cnc
/sbin/ip rule add to 210.53.8.0/23 pref 20001 table cnc
/sbin/ip rule add to 210.74.128.0/19 pref 20001 table cnc
/sbin/ip rule add to 210.74.96.0/19 pref 20001 table cnc
/sbin/ip rule add to 210.75.144.0/20 pref 20001 table cnc
/sbin/ip rule add to 210.76.160.0/19 pref 20001 table cnc
/sbin/ip rule add to 210.78.0.0/19 pref 20001 table cnc
/sbin/ip rule add to 210.82.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 210.83.0.0/20 pref 20001 table cnc
/sbin/ip rule add to 210.83.224.0/19 pref 20001 table cnc
/sbin/ip rule add to 211.152.32.0/19 pref 20001 table cnc
/sbin/ip rule add to 218.10.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 218.104.0.0/14 pref 20001 table cnc
/sbin/ip rule add to 218.104.128.0/20 pref 20001 table cnc
/sbin/ip rule add to 218.104.160.0/19 pref 20001 table cnc
/sbin/ip rule add to 218.104.192.0/21 pref 20001 table cnc
/sbin/ip rule add to 218.104.200.0/21 pref 20001 table cnc
/sbin/ip rule add to 218.104.216.0/21 pref 20001 table cnc
/sbin/ip rule add to 218.104.224.0/19 pref 20001 table cnc
/sbin/ip rule add to 218.104.96.0/20 pref 20001 table cnc
/sbin/ip rule add to 218.106.112.0/20 pref 20001 table cnc
/sbin/ip rule add to 218.106.128.0/21 pref 20001 table cnc
/sbin/ip rule add to 218.106.144.0/20 pref 20001 table cnc
/sbin/ip rule add to 218.106.208.0/20 pref 20001 table cnc
/sbin/ip rule add to 218.106.96.0/22 pref 20001 table cnc
/sbin/ip rule add to 218.107.0.0/18 pref 20001 table cnc
/sbin/ip rule add to 218.107.192.0/19 pref 20001 table cnc
/sbin/ip rule add to 218.11.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 218.12.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 218.21.128.0/17 pref 20001 table cnc
/sbin/ip rule add to 218.24.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 218.26.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 218.27.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 218.28.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 218.56.0.0/14 pref 20001 table cnc
/sbin/ip rule add to 218.60.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 218.62.0.0/17 pref 20001 table cnc
/sbin/ip rule add to 218.67.128.0/17 pref 20001 table cnc
/sbin/ip rule add to 218.68.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 218.7.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 218.8.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 219.154.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 219.156.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 219.158.0.0/20 pref 20001 table cnc
/sbin/ip rule add to 219.158.32.0/19 pref 20001 table cnc
/sbin/ip rule add to 219.159.0.0/18 pref 20001 table cnc
/sbin/ip rule add to 220.114.204.0/18 pref 20001 table cnc
/sbin/ip rule add to 220.248.0.0/14 pref 20001 table cnc
/sbin/ip rule add to 220.248.128.0/19 pref 20001 table cnc
/sbin/ip rule add to 220.248.128.0/20 pref 20001 table cnc
/sbin/ip rule add to 220.248.192.0/19 pref 20001 table cnc
/sbin/ip rule add to 220.249.128.0/18 pref 20001 table cnc
/sbin/ip rule add to 220.249.192.0/18 pref 20001 table cnc
/sbin/ip rule add to 220.249.64.0/18 pref 20001 table cnc
/sbin/ip rule add to 220.250.0.0/19 pref 20001 table cnc
/sbin/ip rule add to 220.252.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 221.0.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 221.10.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 221.11.0.0/17 pref 20001 table cnc
/sbin/ip rule add to 221.11.128.0/18 pref 20001 table cnc
/sbin/ip rule add to 221.11.192.0/19 pref 20001 table cnc
/sbin/ip rule add to 221.11.224.0/19 pref 20001 table cnc
/sbin/ip rule add to 221.12.0.0/17 pref 20001 table cnc
/sbin/ip rule add to 221.12.128.0/18 pref 20001 table cnc
/sbin/ip rule add to 221.13.0.0/18 pref 20001 table cnc
/sbin/ip rule add to 221.13.128.0/17 pref 20001 table cnc
/sbin/ip rule add to 221.13.64.0/19 pref 20001 table cnc
/sbin/ip rule add to 221.13.96.0/19 pref 20001 table cnc
/sbin/ip rule add to 221.14.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 221.192.0.0/14 pref 20001 table cnc
/sbin/ip rule add to 221.196.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 221.198.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 221.199.0.0/17 pref 20001 table cnc
/sbin/ip rule add to 221.199.128.0/18 pref 20001 table cnc
/sbin/ip rule add to 221.199.192.0/20 pref 20001 table cnc
/sbin/ip rule add to 221.199.224.0/23 pref 20001 table cnc
/sbin/ip rule add to 221.200.0.0/14 pref 20001 table cnc
/sbin/ip rule add to 221.2.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 221.204.0.0/15 pref 20001 table cnc
/sbin/ip rule add to 221.206.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 221.207.0.0/18 pref 20001 table cnc
/sbin/ip rule add to 221.207.128.0/17 pref 20001 table cnc
/sbin/ip rule add to 221.207.64.0/18 pref 20001 table cnc
/sbin/ip rule add to 221.208.0.0/14 pref 20001 table cnc
/sbin/ip rule add to 221.213.0.0/16 pref 20001 table cnc
/sbin/ip rule add to 221.214.0.0/15 pref 20001 table cnc
- 最新评论