星期四, 八月 14, 2008

Debian Linux ifconfig / route 網路設定

Debian 正常網路設定是於 /etc/network/interfaces, 可見 /etc/network/interfaces 內容大致如下:

auto lo
iface lo inet loopback

auto eth0
# iface eth0 inet manual
iface eth0 inet static
    address 10.1.1.2
    netmask 255.255.0.0
    network 10.1.0.0
    broadcast 10.1.255.255
    gateway 10.1.1.1
# dns-nameservers 168.95.1.1 168.95.192.1
# dns-search longwin.com.tw
#up "/sbin/route add -net 172.16.120.0 netmask 255.255.255.0 gw 10.1.3.3 metric 1"
#up "/sbin/route add -net 172.16.0.0 netmask 255.255.255.0 gw 10.1.10.20 metric 1"
#up "/sbin/route add -net 10.0.0.0 netmask 255.0.0.0 gw 10.1.10.20 metric 1"
#down "/sbin/route del -net 172.16.120.0 netmask 255.255.255.0 gw 10.1.10.20metric 1"
#down "/sbin/route del -net 172.16.0.0 netmask 255.255.255.0 gw 10.1.10.20 metric 1"
#down "/sbin/route del -net 1.0.0.0 netmask 255.0.0.0 gw10.1.10.20 metric 1"

auto eth1
iface eth1 inet static
    address 10.10.11.2
    netmask 255.255.255.128
    network 10.10.0.0

## for adsl pppoe
#auto dsl-provider
#iface dsl-provider inet ppp
#provider dsl-provider

現在遇到一個的問題, 機器啟動時這兩張網卡很晚才啟動(幾乎是快開完機後才被啟動, 原因不明, 之前不知是否有設到其它東西), 然後啟動後的 IP 等設定, 全都沒有被設定.

而除此之外, 另一個需求是希望透過 eth1 的網路, 連到另外2台 172.x.x.x 的主機, 所以需要另外加兩個 route 的條件.

基於以上的問題, 目前想最快速先能動的解法:

  1. 於開機啟動完成後, 去指定網路卡的 IP 和其它設定.
  2. 上述跑完後, 增加另外 2條路由.

簡易執行步驟

  1. vim /etc/rc.local # 於最後一行 exit 0 前, 加下述幾行
    • ifconfig eth0 10.1.1.2 netmask 255.255.0.0 boradcast 10.1.255.255
    • ifconfig eth1 10.10.11.2 netmask 255.255.255.128
    • route add 172.20.12.12 gw 10.10.11.1 metric 1
    • route add 172.20.15.15 gw 10.10.11.1 metric 1
  2. 然後重新啟動, 看開完機後的結果是否有通就可以了.

測試

ping 及 route 看看, 都能通就可以了.

route 看結果, 應該會看到如下:

$ sudo route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.20.12.12    10.10.11.1      255.255.255.255 UGH   1      0        0 eth1
172.20.15.15    10.10.11.1      255.255.255.255 UGH   1      0        0 eth1
10.10.11.0      *               255.255.255.128 U     0      0        0 eth1
localnet        *               255.255.0.0     U     0      0        0 eth0
default         10.1.1.1        0.0.0.0         UG    0      0        0 eth0

然後再分別 ping 各機器 / Gateway, 看全都通就是正常的囉~

  • ping 172.20.12.12
  • ping 172.20.15.15
  • ping 10.1.1.1
  • ping 10.10.11.1
相關標籤
Add this page to del.icio.us Add this page to Yahoo Taiwan's bookmark Add this page to MyShare

發表迴響

標題

內容 (限制 1000 字)

暱稱

電子郵件

個人網頁


 authimage


PS: 若無法留言, 請先確認是否有打開 JavaScript, 造成您的困擾, 實在萬分對不起 Orz...(如果無法留言, 勞煩可以發信給我好嗎? 謝謝.)
PS2: 若您的留言被誤判, 我都會再自行看過, 不需要一直重覆張貼~