顯示頁面舊版反向連結Fold/unfold all回到頁頂 本頁是唯讀的,您可以看到原始碼,但不能更動它。您如果覺得它不應被鎖上,請詢問管理員。 ====== CentOS 兩張網卡接兩個 ISP 的 Route 設定 ====== * 一台主機的兩張網卡各連接一個 ISP 的網路 * 希望透過哪張網卡過來的連線, 可以直接由那張網卡回去 * 這台主機的相關環境如下: * eth0 : 192.168.11.248 / 255.255.255.0 (Gateway pdc.e2160 : 192.168.11.251) * eth1 : 192.168.12.246 / 255.255.255.0 (Gateway c2q.q9400 : 192.168.12.250) * 預設 default gateway 走 192.168.11.251 有異常時, 自動改走 192.168.12.250 ===== 設定程序 ===== * 編輯 rt_tables<code sh> vi /etc/iproute2/rt_tables </code><file> : # # local # #1 inr.ruhep 1 c2q.q9400 2 pdc.e2160 </file> * 定義 route 規則<code sh> ip route add 192.168.11.0/24 dev eth0 src 192.168.11.248 table pdc.e2160 ip route add default via 192.168.11.251 table pdc.e2160 ip rule add from 192.168.11.248 table pdc.e2160 ip route add 192.168.12.0/24 dev eth1 src 192.168.12.246 table c2q.q9400 ip route add default via 192.168.12.250 table c2q.q9400 ip rule add from 192.168.12.246 table c2q.q9400 ip route add default scope global nexthop via 192.168.11.251 dev eth0 weight 1 nexthop via 192.168.12.250 dev eth1 weight 4 </code> * 編輯 route-ethx rule-ethx<code sh> vi /etc/sysconfig/network-scripts/route-eth0 </code><file> 192.168.11.0/24 dev eth0 src 192.168.11.248 table pdc.e2160 default via 192.168.11.251 table pdc.e2160 </file><code sh> vi /etc/sysconfig/network-scripts/rule-eth0 </code><file> from 192.168.11.248 table pdc.e2160 </file><code sh> vi /etc/sysconfig/network-scripts/route-eth1 </code><file> 192.168.12.0/24 dev eth1 src 192.168.12.246 table c2q.q9400 default via 192.168.12.250 table c2q.q9400 default scope global nexthop via 192.168.11.251 dev eth0 weight 1 nexthop via 192.168.12.250 dev eth1 weight 4 </file><code sh> vi /etc/sysconfig/network-scripts/rule-eth1 </code><file> from 192.168.12.246 table c2q.q9400 </file> * 檢視設定結果<code sh> [root@xen-server ~]# ip route show 192.168.12.0/24 dev eth1 proto kernel scope link src 192.168.12.246 192.168.11.0/24 dev eth0 proto kernel scope link src 192.168.11.248 169.254.0.0/16 dev eth1 scope link default nexthop via 192.168.11.251 dev eth0 weight 1 nexthop via 192.168.12.250 dev eth1 weight 4 </code> ===== 發生異常強制設定程序 ===== * 假設 eth0 : 192.168.11.248 / 255.255.255.0 (Gateway pdc.e2160 : 192.168.11.251) 這個 ISP 確定短時間無法修復, 簡單的拿掉設定方式如下: <code sh> vi /etc/sysconfig/network-scripts/route-eth1 </code><file> 192.168.12.0/24 dev eth1 src 192.168.12.246 table c2q.q9400 default via 192.168.12.250 table c2q.q9400 #default scope global nexthop via 192.168.11.251 dev eth0 weight 1 nexthop via 192.168.12.250 dev eth1 weight 4 default scope global nexthop via 192.168.12.250 dev eth1 weight 4 </file><code sh> service network restart </code> * 檢視設定結果<code sh> [root@xen-server ~]# ip route show 192.168.12.0/24 dev eth1 proto kernel scope link src 192.168.12.246 192.168.11.0/24 dev eth0 proto kernel scope link src 192.168.11.248 169.254.0.0/16 dev eth1 scope link default via 192.168.12.250 dev eth1 </code> ===== 參考資料 ===== * http://lartc.org/howto/lartc.rpdb.multiple-links.html * http://tech.gaeatimes.com/index.php/archive/how-to-load-balancing-failover-with-dual-multi-wan-adsl-cable-connections-on-linux/ {{tag>network multi-isp}} tech/multiisp.txt 上一次變更: 2012/04/26 01:42由 jonathan