- 论坛徽章:
- 0
|
贴个在实际运行的脚本,只隐去了IP、网关信息,供参考。
基本符合楼主的思路。
ifconfig eth0 电信IP1 netmask 255.255.255.248
ifconfig eth0:0 电信IP2 netmask 255.255.255.255
ifconfig eth0:1 电信IP3 netmask 255.255.255.255
ifconfig eth0:2 电信IP4 netmask 255.255.255.255
ifconfig eth0:3 电信IP5 netmask 255.255.255.255
ifconfig eth1 网通IP1 netmask 255.255.255.248
ifconfig eth1:0 网通IP2 netmask 255.255.255.255
ifconfig eth1:1 网通IP3 netmask 255.255.255.255
ifconfig eth1:2 网通IP4 netmask 255.255.255.255
ifconfig eth1:3 网通IP5 netmask 255.255.255.255
ifconfig eth2 内网IP netmask 255.255.255.0
ifconfig eth3 停火区IP netmask 255.255.255.0
modprobe ip_nat_ftp
insmod ip_conntrack_ftp
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1048576 > /proc/sys/net/ipv4/ip_conntrack_max
echo 600 > /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_timeout_established
ip route add default via 电信局端IP table ctc
ip route add default via 网通局端IP table cnc
route add default gw 电信局端IP
route add -net 58.16.0.0/14 gw 网通局端IP
route add -net 58.21.0.0/16 gw 网通局端IP
route add -net 58.22.0.0/15 gw 网通局端IP
route add -net 58.100.0.0/16 gw 网通局端IP
route add -net 58.144.0.0/16 gw 网通局端IP
route add -net 58.240.0.0/15 gw 网通局端IP
route add -net 58.244.0.0/14 gw 网通局端IP
route add -net 58.248.0.0/13 gw 网通局端IP
route add -net 60.0.0.0/13 gw 网通局端IP
route add -net 60.8.0.0/15 gw 网通局端IP
route add -net 60.13.0.0/16 gw 网通局端IP
route add -net 60.14.0.0/15 gw 网通局端IP
route add -net 60.16.0.0/13 gw 网通局端IP
route add -net 60.24.0.0/14 gw 网通局端IP
route add -net 60.31.0.0/16 gw 网通局端IP
route add -net 60.218.0.0/15 gw 网通局端IP
route add -net 60.220.0.0/14 gw 网通局端IP
route add -net 61.48.0.0/13 gw 网通局端IP
route add -net 61.133.0.0/17 gw 网通局端IP
route add -net 61.134.128.0/17 gw 网通局端IP
route add -net 61.135.0.0/16 gw 网通局端IP
route add -net 61.136.64.0/18 gw 网通局端IP
route add -net 61.137.128.0/17 gw 网通局端IP
route add -net 61.138.0.0/16 gw 网通局端IP
route add -net 61.139.128.0/18 gw 网通局端IP
route add -net 61.148.0.0/15 gw 网通局端IP
route add -net 61.156.0.0/16 gw 网通局端IP
route add -net 61.158.0.0/16 gw 网通局端IP
route add -net 61.159.0.0/18 gw 网通局端IP
route add -net 61.161.0.0/18 gw 网通局端IP
route add -net 61.161.128.0/17 gw 网通局端IP
route add -net 61.162.0.0/15 gw 网通局端IP
route add -net 61.167.0.0/16 gw 网通局端IP
route add -net 61.168.0.0/16 gw 网通局端IP
route add -net 61.176.0.0/16 gw 网通局端IP
route add -net 61.179.0.0/16 gw 网通局端IP
route add -net 61.181.0.0/16 gw 网通局端IP
route add -net 61.182.0.0/16 gw 网通局端IP
route add -net 61.189.0.0/17 gw 网通局端IP
route add -net 116.2.0.0/15 gw 网通局端IP
route add -net 116.95.0.0/16 gw 网通局端IP
route add -net 116.112.0.0/14 gw 网通局端IP
route add -net 116.116.0.0/15 gw 网通局端IP
route add -net 117.8.0.0/13 gw 网通局端IP
route add -net 118.72.0.0/13 gw 网通局端IP
route add -net 118.80.0.0/15 gw 网通局端IP
route add -net 118.212.0.0/16 gw 网通局端IP
route add -net 119.4.0.0/14 gw 网通局端IP
route add -net 119.36.0.0/16 gw 网通局端IP
route add -net 119.39.0.0/16 gw 网通局端IP
route add -net 119.48.0.0/13 gw 网通局端IP
route add -net 121.16.0.0/13 gw 网通局端IP
route add -net 121.24.0.0/14 gw 网通局端IP
route add -net 121.28.0.0/15 gw 网通局端IP
route add -net 121.31.0.0/16 gw 网通局端IP
route add -net 122.96.0.0/15 gw 网通局端IP
route add -net 122.136.0.0/13 gw 网通局端IP
route add -net 122.156.0.0/14 gw 网通局端IP
route add -net 122.192.0.0/14 gw 网通局端IP
route add -net 123.4.0.0/14 gw 网通局端IP
route add -net 123.8.0.0/13 gw 网通局端IP
route add -net 123.112.0.0/12 gw 网通局端IP
route add -net 123.128.0.0/13 gw 网通局端IP
route add -net 123.138.0.0/15 gw 网通局端IP
route add -net 123.144.0.0/14 gw 网通局端IP
route add -net 123.148.0.0/16 gw 网通局端IP
route add -net 123.152.0.0/13 gw 网通局端IP
route add -net 123.188.0.0/14 gw 网通局端IP
route add -net 123.232.0.0/14 gw 网通局端IP
route add -net 124.64.0.0/15 gw 网通局端IP
route add -net 124.66.0.0/17 gw 网通局端IP
route add -net 124.67.0.0/16 gw 网通局端IP
route add -net 124.88.0.0/16 gw 网通局端IP
route add -net 124.89.0.0/17 gw 网通局端IP
route add -net 124.89.128.0/17 gw 网通局端IP
route add -net 124.90.0.0/15 gw 网通局端IP
route add -net 124.92.0.0/14 gw 网通局端IP
route add -net 124.160.0.0/16 gw 网通局端IP
route add -net 124.161.0.0/16 gw 网通局端IP
route add -net 124.162.0.0/16 gw 网通局端IP
route add -net 124.163.0.0/16 gw 网通局端IP
route add -net 124.164.0.0/14 gw 网通局端IP
route add -net 125.32.0.0/16 gw 网通局端IP
route add -net 125.33.0.0/16 gw 网通局端IP
route add -net 125.34.0.0/16 gw 网通局端IP
route add -net 125.35.128.0/17 gw 网通局端IP
route add -net 125.36.0.0/14 gw 网通局端IP
route add -net 125.40.0.0/13 gw 网通局端IP
route add -net 125.211.0.0/16 gw 网通局端IP
route add -net 202.38.143.0/24 gw 网通局端IP
route add -net 202.96.0.0/18 gw 网通局端IP
route add -net 202.96.64.0/21 gw 网通局端IP
route add -net 202.96.72.0/21 gw 网通局端IP
route add -net 202.97.128.0/18 gw 网通局端IP
route add -net 202.97.192.0/19 gw 网通局端IP
route add -net 202.97.224.0/21 gw 网通局端IP
route add -net 202.97.240.0/20 gw 网通局端IP
route add -net 202.98.0.0/21 gw 网通局端IP
route add -net 202.98.8.0/21 gw 网通局端IP
route add -net 202.99.64.0/19 gw 网通局端IP
route add -net 202.99.96.0/21 gw 网通局端IP
route add -net 202.99.128.0/19 gw 网通局端IP
route add -net 202.99.160.0/21 gw 网通局端IP
route add -net 202.99.168.0/21 gw 网通局端IP
route add -net 202.99.176.0/20 gw 网通局端IP
route add -net 202.99.208.0/20 gw 网通局端IP
route add -net 202.99.224.0/21 gw 网通局端IP
route add -net 202.99.232.0/21 gw 网通局端IP
route add -net 202.99.240.0/20 gw 网通局端IP
route add -net 202.102.128.0/21 gw 网通局端IP
route add -net 202.102.224.0/21 gw 网通局端IP
route add -net 202.102.232.0/21 gw 网通局端IP
route add -net 202.106.0.0/16 gw 网通局端IP
route add -net 202.107.0.0/17 gw 网通局端IP
route add -net 202.108.0.0/16 gw 网通局端IP
route add -net 202.110.0.0/18 gw 网通局端IP
route add -net 202.110.64.0/18 gw 网通局端IP
route add -net 202.111.128.0/19 gw 网通局端IP
route add -net 203.93.8.0/24 gw 网通局端IP
route add -net 203.93.192.0/18 gw 网通局端IP
route add -net 210.13.0.0/18 gw 网通局端IP
route add -net 210.13.64.0/18 gw 网通局端IP
route add -net 210.13.128.0/17 gw 网通局端IP
route add -net 210.14.160.0/19 gw 网通局端IP
route add -net 210.14.192.0/19 gw 网通局端IP
route add -net 210.15.32.0/19 gw 网通局端IP
route add -net 210.15.96.0/19 gw 网通局端IP
route add -net 210.15.128.0/18 gw 网通局端IP
route add -net 210.21.0.0/17 gw 网通局端IP
route add -net 210.51.0.0/16 gw 网通局端IP
route add -net 210.52.128.0/17 gw 网通局端IP
route add -net 210.53.0.0/17 gw 网通局端IP
route add -net 210.53.128.0/17 gw 网通局端IP
route add -net 210.82.0.0/15 gw 网通局端IP
route add -net 218.8.0.0/15 gw 网通局端IP
route add -net 218.10.0.0/16 gw 网通局端IP
route add -net 218.11.0.0/16 gw 网通局端IP
route add -net 218.12.0.0/16 gw 网通局端IP
route add -net 218.21.128.0/17 gw 网通局端IP
route add -net 218.24.0.0/15 gw 网通局端IP
route add -net 218.27.0.0/16 gw 网通局端IP
route add -net 218.56.0.0/14 gw 网通局端IP
route add -net 218.60.0.0/14 gw 网通局端IP
route add -net 218.67.128.0/17 gw 网通局端IP
route add -net 218.104.0.0/14 gw 网通局端IP
route add -net 218.108.0.0/16 gw 网通局端IP
route add -net 219.82.0.0/16 gw 网通局端IP
route add -net 219.154.0.0/15 gw 网通局端IP
route add -net 219.156.0.0/14 gw 网通局端IP
route add -net 220.252.0.0/16 gw 网通局端IP
route add -net 221.0.0.0/13 gw 网通局端IP
route add -net 221.10.0.0/16 gw 网通局端IP
route add -net 221.11.0.0/17 gw 网通局端IP
route add -net 221.11.128.0/18 gw 网通局端IP
route add -net 221.11.224.0/19 gw 网通局端IP
route add -net 221.12.0.0/17 gw 网通局端IP
route add -net 221.12.128.0/18 gw 网通局端IP
route add -net 221.13.0.0/18 gw 网通局端IP
route add -net 221.13.64.0/19 gw 网通局端IP
route add -net 221.13.128.0/17 gw 网通局端IP
route add -net 221.14.0.0/15 gw 网通局端IP
route add -net 221.192.0.0/13 gw 网通局端IP
route add -net 221.200.0.0/13 gw 网通局端IP
route add -net 221.204.0.0/14 gw 网通局端IP
route add -net 221.212.0.0/15 gw 网通局端IP
route add -net 221.216.0.0/13 gw 网通局端IP
route add -net 222.128.0.0/14 gw 网通局端IP
route add -net 222.132.0.0/14 gw 网通局端IP
route add -net 222.136.0.0/13 gw 网通局端IP
route add -net 222.160.0.0/15 gw 网通局端IP
route add -net 222.162.0.0/16 gw 网通局端IP
route add -net 222.163.0.0/17 gw 网通局端IP
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 电信IP4
iptables -t nat -A POSTROUTING -o eth1 -j SNAT --to-source 网通IP1
iptables -t nat -A PREROUTING -d 电信IP1 -i eth+ -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.0.90:80
iptables -t nat -A PREROUTING -d 电信IP1 -i eth+ -p tcp -m tcp --dport 20 -j DNAT --to-destination 172.16.0.92:20
iptables -t nat -A PREROUTING -d 电信IP1 -i eth+ -p tcp -m tcp --dport 21 -j DNAT --to-destination 172.16.0.92:21
iptables -t nat -A PREROUTING -d 电信IP1 -i eth+ -p tcp -m tcp --dport 81 -j DNAT --to-destination 139.1.1.119:4899
#iptables -t nat -A PREROUTING -d 电信IP2 -i eth+ -p tcp -m tcp --dport 22 -j DNAT --to-destination 172.16.0.91:22
iptables -t nat -A PREROUTING -d 电信IP2 -i eth+ -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.0.91:80
iptables -t nat -A PREROUTING -d 电信IP3 -i eth+ -p tcp -m tcp --dport 20 -j DNAT --to-destination 172.16.0.92
iptables -t nat -A PREROUTING -d 电信IP3 -i eth+ -p tcp -m tcp --dport 21 -j DNAT --to-destination 172.16.0.92:21
iptables -t nat -A PREROUTING -d 电信IP3 -i eth+ -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.0.92:80
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 3081 -j DNAT --to-destination 172.16.0.201:80
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 3082 -j DNAT --to-destination 172.16.0.202:80
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.0.2:80
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 4899 -j DNAT --to-destination 139.1.1.20:4899
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 8899 -j DNAT --to-destination 139.1.1.77:8899
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 3389 -j DNAT --to-destination 139.1.1.150:3389
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 5631 -j DNAT --to-destination 172.16.0.2:5631
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 5632 -j DNAT --to-destination 172.16.0.2:5632
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 3022 -j DNAT --to-destination 172.16.0.203:3022
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 3080 -j DNAT --to-destination 172.16.0.203:3080
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 3333 -j DNAT --to-destination 172.16.0.203:3333
iptables -t nat -A PREROUTING -d 电信IP5 -i eth+ -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.0.94:80
iptables -t nat -A PREROUTING -d 电信IP5 -i eth+ -p tcp -m tcp --dport 25 -j DNAT --to-destination 172.16.0.94:25
iptables -t nat -A PREROUTING -d 电信IP5 -i eth+ -p tcp -m tcp --dport 110 -j DNAT --to-destination 172.16.0.94:110
iptables -t nat -A PREROUTING -d 电信IP5 -i eth+ -p tcp -m tcp --dport 143 -j DNAT --to-destination 172.16.0.94:143
iptables -t nat -A PREROUTING -d 网通IP1 -i eth+ -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.0.90:80
iptables -t nat -A PREROUTING -d 网通IP1 -i eth+ -p tcp -m tcp --dport 4899 -j DNAT --to-destination 139.1.1.20:4899
iptables -t nat -A PREROUTING -d 网通IP1 -i eth+ -p tcp -m tcp --dport 8899 -j DNAT --to-destination 139.1.1.77:8899
iptables -t nat -A PREROUTING -d 网通IP2 -i eth+ -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.0.91:80
iptables -t nat -A PREROUTING -d 网通IP2 -i eth+ -p tcp -m tcp --dport 20 -j DNAT --to-destination 172.16.0.92
iptables -t nat -A PREROUTING -d 网通IP2 -i eth+ -p tcp -m tcp --dport 21 -j DNAT --to-destination 172.16.0.92:21
iptables -t nat -A PREROUTING -d 网通IP2 -i eth+ -p tcp -m tcp --dport 3080 -j DNAT --to-destination 172.16.0.203:3080
iptables -t nat -A PREROUTING -d 电信IP4 -i eth+ -p tcp -m tcp --dport 3333 -j DNAT --to-destination 172.16.0.203:3333
iptables -t nat -A PREROUTING -d 网通IP2 -i eth+ -p tcp -m tcp --dport 3081 -j DNAT --to-destination 172.16.0.201:80
iptables -t nat -A PREROUTING -d 网通IP2 -i eth+ -p tcp -m tcp --dport 3082 -j DNAT --to-destination 172.16.0.202:80
iptables -t nat -A PREROUTING -d 网通IP3 -i eth+ -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.0.3:80
iptables -t nat -A PREROUTING -d 网通IP3 -i eth+ -p tcp -m tcp --dport 5631 -j DNAT --to-destination 172.16.0.3:5631
iptables -t nat -A PREROUTING -d 网通IP3 -i eth+ -p tcp -m tcp --dport 5632 -j DNAT --to-destination 172.16.0.3:5632
iptables -t nat -A PREROUTING -d 网通IP3 -i eth+ -p tcp -m tcp --dport 2501:2600 -j DNAT --to-destination 172.16.0.3
iptables -t nat -A PREROUTING -d 网通IP4 -i eth+ -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.0.94:80
iptables -t nat -A PREROUTING -d 网通IP4 -i eth+ -p tcp -m tcp --dport 25 -j DNAT --to-destination 172.16.0.94:25
iptables -t nat -A PREROUTING -d 网通IP4 -i eth+ -p tcp -m tcp --dport 110 -j DNAT --to-destination 172.16.0.94:110
iptables -t nat -A PREROUTING -d 网通IP4 -i eth+ -p tcp -m tcp --dport 443 -j DNAT --to-destination 172.16.0.94:443
iptables -t nat -A PREROUTING -d 网通IP5 -i eth+ -p tcp -m tcp --dport 20 -j DNAT --to-destination 172.16.0.92
iptables -t nat -A PREROUTING -d 网通IP5 -i eth+ -p tcp -m tcp --dport 21 -j DNAT --to-destination 172.16.0.92:21
iptables -t nat -A PREROUTING -d 网通IP5 -i eth+ -p tcp -m tcp --dport 80 -j DNAT --to-destination 172.16.0.92:80
iptables -t nat -A PREROUTING -d 电信IP2 -i eth+ -p tcp -m tcp --dport 3389 -j DNAT --to-destination 139.1.1.41:3389
iptables -A INPUT -i eth0 -d 电信网段/29 -p icmp -j DROP
iptables -A INPUT -i eth1 -d 网通网段/29 -p icmp -j DROP
ip rule add fwmark 1 table ctc
ip rule add fwmark 2 table cnc
iptables -t mangle -A PREROUTING -i eth0 -m conntrack --ctstate NEW -j CONNMARK --set-mark 0x1
iptables -t mangle -A PREROUTING -i eth1 -m conntrack --ctstate NEW -j CONNMARK --set-mark 0x2
iptables -t mangle -A POSTROUTING -o eth0 -m conntrack --ctstate NEW -j CONNMARK --set-mark 0x1
iptables -t mangle -A POSTROUTING -o eth1 -m conntrack --ctstate NEW -j CONNMARK --set-mark 0x2
iptables -t mangle -A PREROUTING -i eth2 -m conntrack --ctstate ESTABLISHED,RELATED -j CONNMARK --restore-mark
iptables -t mangle -A PREROUTING -i eth3 -m conntrack --ctstate ESTABLISHED,RELATED -j CONNMARK --restore-mark
iptables -t mangle -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j CONNMARK --restore-mark
另外还需要修改/etc/iproute2/rt_tables
增加下列两行
243 ctc
242 cnc
[ 本帖最后由 在风中飘荡 于 2008-7-21 11:59 编辑 ] |
|