Linux

linux如何配置路由等/網路/介面?

  • January 20, 2016

如何在 etc/network/interfaces 中配置路由?我想在 eth0 和 eth1 中添加 3 條路由

我嘗試像這樣配置:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
       address 192.168.82.168
       network 192.168.82.0
       netmask 255.255.255.0
       broadcast 192.168.82.255
       gateway 192.168.82.251
       mtu 1500

auto eth1
iface eth1 inet static
       address 192.168.32.164
       network 192.168.32.0
       netmask 255.255.255.0
       broadcast 192.168.32.255
       mtu 1500
post-up route add -net 192.168.32.0 netmask 255.255.255.0 gw 192.168.32.251 dev eth1
pre-down route add -net 192.168.32.0 netmask 255.255.255.0 gw 192.168.32.251 dev eth1
post-up route add -net 192.168.33.0 netmask 255.255.255.0 gw 192.168.33.251 dev eth1
pre-down route add -net 192.168.33.0 netmask 255.255.255.0 gw 192.168.33.251 dev eth1

但它不起作用,我插入命令:

#route

結果列印出來:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.82.251  0.0.0.0         UG    0      0        0 eth0
192.168.32.0    192.168.32.251  255.255.255.0   UG    0      0        0 eth1
192.168.32.0    *               255.255.255.0   U     0      0        0 eth1
192.168.82.0    *               255.255.255.0   U     0      0        0 eth0

歡迎來到stackexchange。請在幾個 stackexchange 站點上交叉發布相同的問題時閱讀此內容。

現在,回答你的問題。簡短的回答:它確實有效。詳細說明:

路由列印輸出中預設後的路由:

192.168.32.0 192.168.32.251 255.255.255.0 UG 0 0 0 eth1

是結果

後路由添加 -net 192.168.32.0 網路遮罩 255.255.255.0 gw 1​​92.168.32.251 dev eth1

在你的interfaces腳本中。第二個路由net 192.168.33.0/24 via gateway 192.168.33.251添加失敗,因為介面上沒有host 192.168.33.251已知路由eth1。您的意思是說路由net 192.168.33.0/24via gateway 192.168.32.251,或者您需要192.168.33.251根據您的網路配置添加顯式路由。

引用自:https://unix.stackexchange.com/questions/256448