![linux如何配置路由等/网络/接口?](https://linux22.com/image/81663/linux%E5%A6%82%E4%BD%95%E9%85%8D%E7%BD%AE%E8%B7%AF%E7%94%B1%E7%AD%89%2F%E7%BD%91%E7%BB%9C%2F%E6%8E%A5%E5%8F%A3%EF%BC%9F.png)
如何在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
答案1
欢迎来到堆栈交换。请阅读这在几个 stackexchange 网站上交叉发布相同的问题。
现在,回答你的问题。简短的回答:它确实有效。详细信息:
路线打印输出中默认之后的下一个路线:
192.168.32.0 192.168.32.251 255.255.255.0 UG 0 0 0 eth1
是的结果
post-up 路由添加 -net 192.168.32.0 网络掩码 255.255.255.0 gw 192.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/24
via gateway 192.168.32.251
192.168.33.251