差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

兩邊的前次修訂版 前次修改
下次修改
前次修改
tech:multiisp [2012/03/27 18:14] – [設定程序] jonathantech:multiisp [2012/04/26 09:42] (目前版本) jonathan
行 1: 行 1:
 +====== 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}}