12

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?

migrated from serverfault.com Aug 9 '15 at 19:00

This question came from our site for system and network administrators.

15

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.

  • What if the cable is already connected before boot? Will a udev event trigger the connection at boot time in that case? In other words, does udev check what devices are already connected to the machine's ports? – Joseph R. Aug 9 '15 at 21:48
0

There are always more than one solution to the problem.

If you are with this machine always in one place, like home, then the easiest way would be getting rid of dhcp-client package, and set static IP address, mask, gateway. Supposing you don't need it, you would do something like

apt-get remove isc-dhcp-client

This will tell you first, if there are any dependepcies. Once you have uninstalled the package, you will no longer have to wait during boot.

This is example of what you would set in your /etc/network/interfaces

iface eth0 inet static
    address 192.168.0.2
    netmask 255.255.255.0
    gateway 192.168.0.254

Source: https://wiki.debian.org/DHCP_Client

  • As mentioned in the question, I do want to use DHCP if the ethernet cable is connected. So removing the DHCP client will not help me. – Maxim V. Pavlov Aug 9 '15 at 20:43
0

Have a look at ifplugd:

ifplugd is a Linux daemon which will automatically configure your ethernet device when a cable is plugged in and automatically unconfigure it if the cable is pulled. This is useful on laptops with onboard network adapters, since it will only configure the interface when a cable is really connected.

ifplugd ifplugd interfaces with your distribution's native network configuration utilities.

Some features:

  • Uses your distribution's native ifup/ifdown programs.
  • May beep when the cable is unplugged, plugged, the interface configuration succeeded or failed.
  • Supports the Linux SIOCETHTOOL (newer, aka ethtool API), SIOCGMIIREG (older, aka mii-diag/mii-tool API) and SIOCDEVPRIVATE (oldest, aka mii-tool API) ioctl()s for getting link status. Release 0.24 introduces support for link detection with the IFF_RUNNING interface flag.
  • Syslog support
  • Small program - the binary is just 25 KB (plus 16 KB for libdaemon).
  • Multiple ethernet interface support
  • Can be configured to ignore short "unplugged" periods (-d option) or short "plugged" periods(-u option)
  • Support for wireless networking. Whenever an association to an AP is detected the network is configured. Have a look on waproamd if you need a facility to configure WEP keys before AP associations succeed.
  • Compatibility mode for network devices which do not support cable detection (-F option)

Package Debian Package Search Page: ifplugd.
Official ifplugd Site

An apt-get update && apt-get-install ifplud should do the trick. On a side note, the creator of systemd maintains this package.

  • 1
    I'd qualify that as "... used to maintain this package" since the last release was ten years ago ;-). Nowadays Lennart would probably recommend systemd-networkd... With ifplugd, after installation, you also need to configure your device (specify allow-ifplugd in /etc/network/interfaces). – Stephen Kitt Aug 10 '15 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.