IT貓撲網(wǎng):您身邊最放心的安全下載站! 最新更新|軟件分類|軟件專題|手機(jī)版|論壇轉(zhuǎn)貼|軟件發(fā)布

您當(dāng)前所在位置: 首頁系統(tǒng)集成網(wǎng)絡(luò)管理 → 用Linux搭建網(wǎng)吧雙線路(電信,網(wǎng)通)

用Linux搭建網(wǎng)吧雙線路(電信,網(wǎng)通)

時(shí)間:2015-06-28 00:00:00 來源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評論(0)

實(shí)現(xiàn)方式是這樣,三塊網(wǎng)卡,eth0 為LAN口,eth1 為第一個(gè)WAN口,接電信線路,eth2為第二個(gè)WAN口,接網(wǎng)通線路。
將從兩個(gè)WAN口出去的數(shù)據(jù)包MASQUERADE
代碼:

/sbin/iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
/sbin/iptables -t nat -A POSTROUTING -o e th2 -j MASQUERADE 然后,給系統(tǒng)增加一個(gè)標(biāo)示為100的路由表,增加一個(gè)默認(rèn)網(wǎng)關(guān),這個(gè)默認(rèn)網(wǎng)關(guān)是網(wǎng)通提供的網(wǎng)關(guān)。

代碼:

ip route add 0/0 via 218.59.*.* table 100 然后給系統(tǒng)主路由表配置網(wǎng)關(guān),這個(gè)網(wǎng)關(guān)是電信的網(wǎng)關(guān) 代碼:

ip route add 0/0 via 219.146.*.* 然后添加路由規(guī)則,讓所有通向網(wǎng)通的數(shù)據(jù)查詢標(biāo)示為100的路由表: 復(fù)制內(nèi)容到剪貼板

代碼:

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
.......... 規(guī)則比較多,大概有100多條,應(yīng)該是完整的包括了網(wǎng)通的所有IP子網(wǎng),我會(huì)給出完整規(guī)則。
這樣,通向網(wǎng)通的數(shù)據(jù)會(huì)查詢路由表100,而通向其他的地方的數(shù)據(jù),這里指定電信,則會(huì)通向電信。當(dāng)然,如果有更復(fù)雜的應(yīng)用,譬如還有教育網(wǎng)的線路,我相信大家也知道怎么做了,再增加路由表,再增加策略就可以了。

這個(gè)配置方式給北方的朋友使用了,覺得效果很好,我希望對大家也有幫助。要注意的是,在配置網(wǎng)卡的時(shí)候,先不要配置網(wǎng)關(guān),不要使用老的ifconfig命令來配置網(wǎng)關(guān),而要使用iproute2來配置網(wǎng)關(guān),否則會(huì)造成沖突,或者 使用 ip route replace 命令來替換 ip route add 命令。

整個(gè)配置文件如下:(并沒有包括端口過濾的配置,大家根據(jù)需要自己配置)。 復(fù)制內(nèi)容到剪貼板
代碼:


#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 interface
/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

關(guān)鍵詞標(biāo)簽:Linux,網(wǎng)吧雙線路

相關(guān)閱讀

文章評論
發(fā)表評論

熱門文章 路由器地址大全-各品牌路由設(shè)置地址 路由器地址大全-各品牌路由設(shè)置地址 各品牌的ADSL與路由器出廠默認(rèn)IP、帳號、密碼 各品牌的ADSL與路由器出廠默認(rèn)IP、帳號、密碼 Nslookup命令詳解-域名DNS診斷 Nslookup命令詳解-域名DNS診斷 站長裝備:十大網(wǎng)站管理員服務(wù)器工具軟件 站長裝備:十大網(wǎng)站管理員服務(wù)器工具軟件

相關(guān)下載

    人氣排行 各品牌的ADSL與路由器出廠默認(rèn)IP、帳號、密碼 路由器地址大全-各品牌路由設(shè)置地址 騰達(dá)路由器怎么設(shè)置?騰達(dá)路由器設(shè)置教程 ADSL雙線負(fù)載均衡設(shè)置詳細(xì)圖文教程 路由表說明(詳解route print) Nslookup命令詳解-域名DNS診斷 網(wǎng)管員實(shí)際工作的一天 網(wǎng)管必會(huì)!了解交換機(jī)控制端口流量