I am looking for a way to prevent eth0 interface from adding a default route to my main routing table on my Linux machine. I have a Debian distribution (Jessie - 8.0) and was looking at the post-up directive in /etc/network/interfaces
. My current configuration looks as follows:
ifconfig
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/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
post-up /sbin/route del default dev eth0
ip route show table main
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
Sadly, this approach only works if the interface is brought up using ifup eth0, and not when the cable is physically connected and ip assigned. Even still, this approach doesn't delete the default entry and ifup gives the following error:
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.
I would like to know a proper way to ensure that the default route is not added through eth0 and not have to bring up eth0 manually using ifup
(to leverage post-up) but rather use the one that is already initialized on boot.