One of my headless systems is assigned a static IP address through /etc/network/interfaces
on a wired Ethernet. It is connected to a router which is also a DHCP server. After a couple of days, the static address is dropped and replaced by a DHCP address. Why would that be?
- If I do a
sudo ifdown eth0 && sudo ifup eth0
orsudo service networking restart
or a reboot, the system takes on its static address again, but then a couple of days later, the IP address changes to a dynamic one. - There is no other system on the network with (accidentally) the same static address.
- NetworkManager is not running on the system.
- I have set up the system to email me as soon as the address changes, but the times at which that occurs seem completely random. DHCP Lease time is 24h but that doesn't seem to correlate, and anyway that shouldn't matter for a static address.
- My /etc/network/interfaces is this:
auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.124.104 gateway 192.168.124.253 netmask 255.255.255.0
It's a bit of a puzzle.
What would cause a system to give up its static address and request a DHCP address instead? What to look for, in which log file?
Recently I stumbled on this problem and after some investigation it turned out that /etc/dhcp/dhcp.conf needed a block to be added, (or uncommented,) similar to this:
Hope this helps!
Regards, Glendon Gross
Hmmm, strange... I'm not sure it matters, but for neatness sake I would place the
netmask
parameter directly after "address" and not after "gateway". You should also uninstall/deactivate the (isc-
)dhcp-client
package from the host, and beware of ipv6 and theresolveconf
package. Before that: A way to find out what's going on is to put in place a firewall rule that accepts & logs all traffic to and from the DHCP ports (server 67 UDP and client 68 UDP) or create logging for the devices state, thedhcp-client
or sniff your traffic.A workaround (or alternative solution) though is to configure DHCP reservations for some of your hosts or an infinite lease-time for their DHCP addresses. For me that works really well, and the advantage is centralized management. If your DHCP server is your modem/router you can probably configure it in the web-interface (either the lease-time or the reservation) and on some routers you can even check a "fixed address" checkbox. If you configured your own server (Ubuntu?) you need to edit the
dhcpd.conf
file adding some lines like this:I know this is old, but I ran into a similar issue that I was struggling with. I also opened a case with Canonical to ask for help.
I've since resolved my issue and have come back to this post in the hope that this might prove useful to someone else who might stumble upon this. My issue in the end, turned out to be 'wicd-daemon'. I'm not sure how or why the package was installed, but it was the main contributor of dropping my static address and causing other networking issues for me.
A symptom of my problem was dhclient would startup if I unplugged the network cable and plugged it back in. Similar to the issue reported here I would then get a different IP address. If I set my NIC manually it was OK, but then some random time later it would get a different IP (due to dhclient running in the background it seems). Check if dhclient is running. As for why dhclient is even running that is another problem. Below I describe what resolved dhclient for me, which I ended up tracing down several paths (avahi, ntpd, ifup, ...). For my case it was wicd-daemon.
The issue originally came to light in testing as I was switching networks that required me to physically move my network cable. This caused networking issue for me which it shouldn't have. It also took a bit of time to discover the problem as well, as I was not expected my static IP to have dropped or changed.
In the end, purging wicd-daemon and python-wicd took care of the issue. My system now retains the static IP address even when the network cable has been unplugged. I've not seen dhclient start up either, so I'm thinking that issue has also resolved itself. I went down other paths as well, looking at avahi which seemed to play a roll in the issues I was having, I also looked at ntpd as well (weird I know, but it was showing up in the syslogs at the same time other issues did; NTPD probably didn't have anything to do with it but it was producing suspicious logs). I ran down several rabbit holes until by chance I stumbled on a wicd process running while doing other testing.
So long story short check if dhclient is running and if you have a network manager like wicd running on your system. It could be what is causing you problems with your static address.