Linux下电信网通双线路实现方式

  Linux下电信网通双线路实现方式是这样,三块网卡,eth0 为LAN口,eth1 为第一个WAN口,接电信线路,eth2为第二个WAN口,接网通线路。我这里都是按照固定IP方式配置的,如果是要PPPOE则自己配置PPPOE部分,我这里主要是给大家提供策略部分。

  将从两个WAN口出去的数据包MASQUERADE
  /sbin/iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
  /sbin/iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE

  然后,给系统增加一个标示为100的路由表,增加一个默认网关,这个默认网关是网通提供的网关。呵呵,为什么我的帖子里的多路由表总用100呢,呵呵。
  ip route add 0/0 via 218.59.*.* table 100
  然后给系统主路由表配置网关,这个网关是电信的网关
  ip route add 0/0 via 219.146.*.*
  然后添加路由规则,让所有通向网通的数据查询标示为100的路由表:
  ip rule add to 60.0.0.0/13 table 100
ip rule add to 60.8.0.0/15 table 100
ip rule add to 60.10.0.0/16 table 100
..........
  规则比较多,大概有100多条,应该是完整的包括了网通的所有IP子网,我会给出完整规则。
  这样,通向网通的数据会查询路由表100,而通向其他的地方的数据,这里指定电信,则会通向电信。当然,如果有更复杂的应用,譬如还有教育网的线路,我相信大家也知道怎么做了,再增加路由表,再增加策略就可以了。
  这个配置方式给北方的朋友使用了,觉得效果很好,我希望对大家也有帮助。要注意的是,在配置网卡的时候,先不要配置网关,不要使用老的ifconfig命令来配置网关,而要使用iproute2来配置网关,否则会造成冲突,或者 使用 ip route replace 命令来替换 ip route add 命令。
  整个配置文件如下:(并没有包括端口过滤的配置,大家根据需要自己配置)居然附件只能上传jpg和 gif 呵呵,我把脚本后缀加了个.jpg ,通过右键属性,把文件下下来,自己改回来吧。

#For ChinaUnix By Fushuyong,Wuhan
#!/bin/sh
echo "1" >; /proc/sys/net/ipv4/ip_forward
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp

#NAT the two red inte***ce
/sbin/iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
/sbin/iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE

#Add a route table name 100 for CNC addresses
ip route add 0/0 via 219.146.*.*
ip route add 0/0 via 218.59.*.* table 100

#Add the route rules for the CNC addresses
ip rule add to 60.0.0.0/13 table 100
ip rule add to 60.8.0.0/15 table 100
ip rule add to 60.10.0.0/16 table 100
ip rule add to 60.12.0.0/16 table 100
ip rule add to 60.13.0.0/18 table 100
ip rule add to 60.13.128.0/17 table 100
ip rule add to 60.16.0.0/12 table 100
ip rule add to 60.208.0.0/13 table 100
ip rule add to 60.216.0.0/15 table 100
ip rule add to 60.220.0.0/14 table 100
ip rule add to 61.48.0.0/13 table 100
ip rule add to 61.133.0.0/17 table 100
ip rule add to 61.135.0.0/16 table 100
ip rule add to 61.136.64.0/18 table 100
ip rule add to 61.137.128.0/17 table 100
ip rule add to 61.138.0.0/17 table 100
ip rule add to 61.138.128.0/18 table 100
ip rule add to 61.139.128.0/18 table 100
ip rule add to 61.148.0.0/15 table 100
ip rule add to 61.156.0.0/16 table 100
ip rule add to 61.158.128.0/17 table 100
ip rule add to 61.159.0.0/18 table 100
ip rule add to 61.161.0.0/18 table 100
ip rule add to 61.161.128.0/17 table 100
ip rule add to 61.167.0.0/16 table 100
ip rule add to 61.168.0.0/16 table 100
ip rule add to 61.176.0.0/16 table 100
ip rule add to 61.179.0.0/16 table 100
ip rule add to 61.180.128.0/17 table 100
ip rule add to 61.181.0.0/16 table 100
ip rule add to 61.182.0.0/16 table 100
ip rule add to 61.189.0.0/17 table 100
ip rule add to 202.96.0.0/18 table 100
ip rule add to 202.96.64.0/19 table 100
ip rule add to 202.97.128.0/17 table 100
ip rule add to 202.98.0.0/19 table 100
ip rule add to 202.99.0.0/16 table 100
ip rule add to 202.102.128.0/18 table 100
ip rule add to 202.102.224.0/19 table 100
ip rule add to 202.106.0.0/16 table 100
ip rule add to 202.107.0.0/17 table 100
ip rule add to 202.108.0.0/16 table 100
ip rule add to 202.110.0.0/17 table 100
ip rule add to 202.110.192.0/18 table 100
ip rule add to 202.111.128.0/18 table 100
ip rule add to 218.7.0.0/16 table 100
ip rule add to 218.8.0.0/14 table 100
ip rule add to 218.12.0.0/16 table 100
ip rule add to 218.24.0.0/14 table 100
ip rule add to 218.28.0.0/15 table 100
ip rule add to 218.56.0.0/14 table 100
ip rule add to 218.60.0.0/15 table 100
ip rule add to 218.67.128.0/17 table 100
ip rule add to 218.68.0.0/15 table 100
ip rule add to 221.0.0.0/14 table 100
ip rule add to 221.4.0.0/15 table 100
ip rule add to 221.6.0.0/16 table 100
ip rule add to 221.7.0.0/18 table 100
ip rule add to 221.7.64.0/19 table 100
ip rule add to 221.7.128.0/17 table 100
ip rule add to 221.8.0.0/15 table 100
ip rule add to 221.10.0.0/16 table 100
ip rule add to 221.11.128.0/18 table 100
ip rule add to 221.11.0.0/17 table 100
ip rule add to 221.11.192.0/19 table 100
ip rule add to 221.12.0.0/17 table 100
ip rule add to 221.12.128.0/18 table 100
ip rule add to 221.13.0.0/18 table 100
ip rule add to 221.13.64.0/19 table 100
ip rule add to 221.13.128.0/17 table 100
ip rule add to 221.14.0.0/15 table 100
ip rule add to 221.192.0.0/14 table 100
ip rule add to 221.196.0.0/15 table 100
ip rule add to 221.198.0.0/16 table 100
ip rule add to 221.199.0.0/19 table 100
ip rule add to 221.199.32.0/20 table 100
ip rule add to 221.199.128.0/18 table 100
ip rule add to 221.199.192.0/20 table 100
ip rule add to 221.200.0.0/14 table 100
ip rule add to 221.204.0.0/15 table 100
ip rule add to 221.207.0.0/18 table 100
ip rule add to 221.208.0.0/14 table 100
ip rule add to 221.212.0.0/15 table 100
ip rule add to 221.216.0.0/13 table 100
ip rule add to 222.128.0.0/12 table 100
ip rule add to 222.160.0.0/15 table 100
ip rule add to 222.162.0.0/16 table 100
ip rule add to 222.163.0.0/19 table 100

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/caf499bdaa3a8f1a64691ba9c200a19a.html