Skip to content

Linux home networking part 1: Static IP fall-back

NetworkManager has made it’s way into the top Linux distributions as the standard way to manage network interfaces on desktop/notebook computers. I like NetworkManager. It works well for both wired and wireless interfaces with DHCP, and using wireless security and authentication is a breeze. With more recent versions you can also configure static IP addresses, but it doesn’t support a fall-back static IP configuration if DHCP fails to get a dynamic IP.

I need this capability, because my home network doesn’t have a router-like device to act as a DHCP server, but I would like to be able to take my notebook to work (or elsewhere), and use DHCP with minimal fuss.

It turns out this fall-back capability is supported in dhcp3-client (and perhaps other DHCP clients), by using a pre-defined lease in the config file (/etc/dhcp3/dhclient.conf on my Ubuntu 8.10 install):

request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
netbios-name-servers, netbios-scope, interface-mtu;

timeout 10;

lease {
interface "eth0";
fixed-address 10.0.0.1;
option subnet-mask 255.255.255.0;
renew 2 2030/1/12 00:00:01;
rebind 2 2030/1/12 00:00:01;
expire 2 2030/1/12 00:00:01;
}

dhcp3-client will now try to get a lease from DHCP, and if it fails, it will configure the IP given in the pre-defined lease, effectively making this a static fall-back IP address.

Unfortunately when NetworkManager gets the news from the DHCP client that we could not get a lease from a DHCP server, it nukes the static configuration on the interface and takes us back to square one. I wanted a work-around that would allow me to keep NetworkManager (since I use it for my 3G modem too), so I came up with this:

I added the following stanza to my /etc/network/interfaces file:

allow-hotplug eth0
iface eth0 inet dhcp

This enables the standard Debian ifup/ifdown magic, and it also stops NetworkManager from managing the interface (which I don’t mind, since I never use 802.1x on wired networks).

In order to get back plug-and-play functionality (like NetworkManager provided by configuring the interface when it detected the link going up), I installed ifplugd, and configured it to watch my wired interface by changing INTERFACES="" to INTERFACES="eth0" in /etc/default/ifplugd, and restarting the daemon.

An alternative to this setup would be to use IPv4LL addressing provided by avahi-autoip, but I prefer to manually allocate a static IP to each host.

Post a Comment

Your email is never published nor shared. Required fields are marked *