我正在寻找一种方法来防止 eth0 接口将默认路由添加到我的 Linux 计算机上的主路由表中。我有一个 Debian 发行版(Jessie - 8.0),并且正在查看/etc/network/interfaces
.我当前的配置如下:
如果配置
eth0 Link encap:Ethernet HWaddr b8:27:eb:4b:f4:9e
inet addr:172.16.2.82 Bcast:172.16.3.255 Mask:255.255.252.0
inet6 addr: fe80::ba27:ebff:fe4b:f49e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2311 errors:0 dropped:0 overruns:0 frame:0
TX packets:203 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:187402 (183.0 KiB) TX bytes:22251 (21.7 KiB)
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.178.142.185 P-t-P:192.200.1.21 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:36 errors:0 dropped:0 overruns:0 frame:0
TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:2918 (2.8 KiB) TX bytes:3426 (3.3 KiB)
/etc/网络/接口
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
post-up /sbin/route del default dev eth0
ip 路由显示表主
default dev ppp0 scope link
default via 172.16.0.40 dev eth0 metric 202
10.64.64.65 dev ppp1 proto kernel scope link src 10.181.104.9
169.254.0.0/16 dev wlan0 proto kernel scope link src 169.254.23.201 metric 303
169.254.0.0/16 dev wwan0 proto kernel scope link src 169.254.62.145 metric 305
172.16.0.0/22 dev eth0 proto kernel scope link src 172.16.2.160 metric 202
192.168.42.0/24 dev wlan0 proto kernel scope link src 192.168.42.1
192.200.1.21 dev ppp0 proto kernel scope link src 10.179.96.79
遗憾的是,这种方法仅在使用 ifup eth0 启动接口时才有效,而在物理连接电缆并分配 IP 时则无效。即使如此,这种方法也不会删除默认条目,并且 ifup 会给出以下错误:
Internet Systems Consortium DHCP Client 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/b8:27:eb:4b:f4:9e
Sending on LPF/eth0/b8:27:eb:4b:f4:9e
Sending on Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 6
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 11
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPOFFER from 172.16.0.8
DHCPACK from 172.16.0.8
eminstBootdpxeboot.com option - discarded
eminstBootdpxeboot.com option - discarded
bound to 172.16.2.82 -- renewal in 12663 seconds.
SIOCDELRT: No such process
Failed to bring up eth0.
我想知道一种正确的方法来确保默认路由不通过 eth0 添加不是必须使用ifup
(以利用 post-up)手动启动 eth0,而是使用启动时已初始化的 eth0。
答案1
编辑/etc/dhcp/dhclient.conf
并routers
从request
语句中删除,以便您的 DHCP 客户端不会在请求地址的同时请求默认路由配置。