茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1730064 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_00003.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

小企鵝開談 : [分享]一張網卡 bind 兩個不同網段的 IP

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15773
[分享]一張網卡 bind 兩個不同網段的 IP
冷日當年發mail問半天的問題,現在看起來是找到解決法了。
冷日順便就po上來ㄌㄡ。

一張網卡 bind 兩個不同網段的 IP

環境: 兩條對外網路, 兩個 ATU-R 均接到 Hub, 電腦接 Hub


IP1 100.100.100.100/24 Gateway 100.100.100.254
IP2 200.200.200.200/24 Gateway 200.200.200.254

ifconfig eth0 100.100.100.100 netmask 255.255.255.0
ifconfig eth0:0 200.200.200.200 netmask 255.255.255.0

由於 default gateway 只能設一個, 所以會有其中一個 IP 不通



必需用 ip route2 來解決這個問題
kernel option 中的 IP: policy routing 必需勾選(CONFIG_IP_MULTIPLE_TABLES)
否則在使用 ip rule 時會出現如下錯誤訊息

# ip rule list
RTNETLINK error: Invalid argument
dump terminated


先在 /etc/iproute2/rt_tables 下建兩個 table

echo "100 line1" >> /etc/iproute2/rt_tables 
echo "200 line2" >> /etc/iproute2/rt_tables

# 設定 line1 的 gateway

ip route add default via 100.100.100.254 table line1

# 設定 line2 的 gateway
ip route add default via 200.200.200.254 table line2

# 指定從 100.100.100.100 進來的連線走 rule line1
ip rule add from 100.100.100.100 table line1 

# 指定從 200.200.200.200 進來的連線走 rule line1
ip rule add from 200.200.200.200 table line2</p>

設完後, 從外面連兩個 IP 都可以通



連外負載平衡
kernel option 中的 IP: equal cost multipath 必需勾選(CONFIG_IP_ROUTE_MULTIPATH)
指定 multipath

ip route add default scope global nexthop via 100.100.100.254 dev eth0 weight 1 nexthop via 200.200.200.254 dev eth0 weight 1

設完後就達成 line1 line2 路由平衡, 可以調整 weight 參數來決定 line1 或 line2 的比重
ip route list 會看到 default 如下
default 
        nexthop via 100.100.100.254  dev eth0 weight 1
        nexthop via 200.200.200.254  dev eth0 weight 1</p>

ref. http://lartc.org/

前一個主題 | 下一個主題 | | | |

討論串




Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|