Debian – How to skip DHCP if no cable connected to ethernet in Debian

bootdebiandhcpnetworking

My Bananian Linux is wasting time at logon trying to get a DHCP lease for eth0 interface which is not connected. Well, the extender cable is connected to it, but nothing is on the other end.

I have

auto eth0
iface eth0 inet dhcp 

set in my /etc/network/interfaces since I do want it to pick up ethernet in case it is connected, but I surely don't want to slow down the startup of the system if the cable is not connected to ethernet. I assumed system would know this automatically and would not attempt to get a DHCP lease for the interface.

Here is what I see at load time (see the last three lines):

enter image description here

After if understands that the lease isn't coming, it proceeds with the boot.

Is there a way I could tell it not to DHCP if there isn't a connected cable?

Best Answer

If you specify

allow-hotplug eth0

instead of

auto eth0

in /etc/network/interfaces, then the connection will only be initiated by udev when something triggers it, instead of at every boot.

That might be sufficient to handle your case, but not necessarily; the interfaces manpage mentions that

(Interfaces marked "allow-hotplug" are brought up when udev detects them. This can either be during boot if the interface is already present, or at a later time, for example when plugging in a USB network card. Please note that this does not have anything to do with detecting a network cable being plugged in.)

You might need to use /etc/network/if-up.d/00check-network-cable from the ifupdown-extra package to skip the interface if no cable is connected.

Related Question