Linux雙網絡卡雙IP雙閘道器

2021-06-25 10:06:30 字數 2274 閱讀 3754

ubuntu雙網絡卡雙ip.不同閘道器.不同子網.如何同時ping通兩塊網絡卡的解決方法,

伺服器環境如下:、

系統:ubuntu 9.04 x64 server

電信ip(tel):114.80.0.4 netmask 255.255.255.128 gateway 114.80.0.3

聯通ip(cnc):112.65.0.2 netmask 255.255.255.0 gateway 112.65.0.1

1.配置網絡卡資訊

# vi /etc/network/inte***ces

auto lo 

iface lo inet loopback

# the primary network inte***ce 

auto eth0 

iface eth0 inet static 

address 114.80.0.4 

netmask 255.255.255.128 

gateway 114.80.0.3 

# dns-* options are implemented by the resolvconf package, if installed 

dns-nameservers 202.96.209.133

auto eth1 

iface eth1 inet static 

address 112.65.0.2 

netmask 255.255.255.0

儲存配置資訊並重新啟動網絡卡

# /etc/init.d/networking restart

2.增加2個路由表分別是電信:tel 聯通:cnc 

# vi /etc/iproute2/rt_tables 

252 tel 

251 cnc

儲存並推出

3.增加路由規則 

# ip route flush table tel 

# ip route add default via 114.80.0.3 dev eth0 src 114.80.0.4 table tel 

# ip ruleadd from 114.80.0.4 table tel

此處是設定電信的閘道器,並可實現讓電信的資源訪問只從eth0網絡卡出去

# ip route flush table cnc 

# ip route add default via 112.65.0.1 dev eth1 src 112.65.0.2 table cnc 

# ip rule add from 112.65.0.2 table cnc

此處是設定聯通的閘道器,並可實現讓聯通的資源訪問只從eth1網絡卡出去

4.配置networking啟動指令碼檔案 在結尾exit 0之前增加如下內容

# vi /etc/init.d/networking

ip route flush table tel 

ip route add default via 114.80.0.3 dev eth0 src 114.80.0.4 table tel 

ip rule add from 114.80.0.4 table tel

ip route flush table cnc 

ip route add default via 112.65.0.1 dev eth1 src 112.65.0.2 table cnc 

ip rule add from 112.65.0.2 table cnc

exit 0

5,退出並重啟網路

# /etc/init.d/networking restart

此時再測試機器網路情況,就會發現電信和聯通的位址都可以正常訪問了。此方法還可以實現讓從電信ip過來的請求按照電信路由返回,從網通ip過來的請求從網通路由返回。

補充:網上有些大神說如果伺服器重啟,或者網路服務重啟,上述的路由規則就失效了,所以你需要把上面這段命令寫入系統啟動指令碼和網路啟動指令碼

如果是ubuntu/debian,系統啟動指令碼是/etc/rc.local 

如果是redhat/centos,系統啟動指令碼是/etc/rc.d/rc.local

如果是ubuntu/debian,網路啟動指令碼是/etc/init.d/networking 

如果是redhat/centos,網路啟動指令碼是/etc/rc.d/init.d/network

對於系統啟動指令碼本次並沒有做更改只是更改了網路啟動指令碼,有興趣的同學可以測試下。

ps:有的時候/etc/init.d/networking restart 沒有用,則先stop然後再啟動

雙網絡卡雙閘道器

由於電信和網通之間互聯互通的問題,很多人選擇雙線路機房,所謂雙線路機房就是擁有兩條出口,一條電信一條網通。最近在乙個雙線路機房測試一台伺服器,打算作為論壇的資料庫伺服器使用,伺服器作業系統為 linux。計畫配置為雙ip,雙網域名稱,使得瀏覽者通過電信和網通兩條線路都能正常訪問伺服器,而且各走各的,...

Linux雙線雙網絡卡雙IP雙閘道器設定方法

機房上架了一台測試機,系統是ubuntu 9.04 x64的系統,母機ibm x336機器。使用者需求是雙線,故採用乙個網絡卡配置電信位址,另乙個網絡卡配置聯通位址,安裝好系統後配置好ip發現聯通位址和電信位址只能有乙個可以ping通,若電信位址配置閘道器,聯通位址不配閘道器,則只能ping通電信位...

linux雙網絡卡雙ip配置

在 etc rc.local裡面加上 ip route replace default via 221.6.67.33 dev eth1 ip route replace default via 180.97.81.1 dev eth0 ip route flush table ctc ip rou...