15

I modify dhcp to static in /etc/network/interfaces (like below).

# The primary network interface
auto eth0
iface eth0 inet static
netmask 255.255.0.0
address 10.10.130.128
gateway 10.10.1.1

Then restart the interface.

$ sudo ifdown eth0; sudo ifup eth0
...
$ ifconfig
eth0      Link encap:Ethernet 
          inet addr:10.10.130.128  Bcast:10.10.255.255  Mask:255.255.0.0

So the new address kicks in.

But DHCP is still there?

$ ps aux | grep dhc
root    ... dhclient3 -e IF_METRIC=100 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -1 eth0

Is that normal? If not, how to restart interface in static IP while stop DHCP at the same time?

Thanks a lot.

1
23
  1. You first have to shutdown the interface (in dhcp mode) sudo ifdown eth0
  2. Then edit the config nano /etc/network/interfaces

    # The primary network interface
    auto eth0
    iface eth0 inet static
    netmask 255.255.0.0
    address 10.10.130.128
    gateway 10.10.1.1
    
  3. Bring the interface back up sudo ifup eth0

Otherwise dhclient doesn't correctly shuts down,

8
  • 1
    Sorry, but can someone elaborate on exactly how this differs from what is done in the OP here? I've read this three times and I can't seem to tell the difference.
    – fostandy
    Aug 16 '14 at 10:37
  • 3
    @fostandy "ifupdown doesn't support the modifying of interface definitions in /etc/network/interfaces while the related interfaces are up". Here, the interface is stopped before the file is modified.
    – Bruno
    Nov 15 '14 at 0:14
  • 1
    @Bruno - thanks for clarifying. Out of curiousity what do you do if you've already irrevocably edited the /etc/network/interfaces file? Is there a way to force a reset to defaults and and start again?
    – fostandy
    Dec 1 '14 at 8:22
  • 8
    I was baffled as to why it should make a difference but then a clever friend of mine explained it very nicely. The problem is if the file is edited and then ifdown is run, network manager does not know that it needs to stop dhclient, since all it sees in the interfaces file is a static entry. After, the interface is down, issuing ifup correctly reads and applies the static settings, but it also doesn't know that dhclient had been started.
    – paracycle
    Oct 23 '15 at 18:48
  • 1
    What I mean is I've to manually pkill dhclient and dhclient3 since following the aforementioned steps do NOT kill them automatically
    – HighOnMeat
    Jun 1 '16 at 10:44
4

I had the same issue (Ubuntu 16.04). However, this was a cloud instance and I could not ifdown the interface that easily.

Short answer: I removed the file /etc/network/interfaces.d/50-cloud-init.cfg ifup was triggered by that specific file.

Long answer: I configured the interface using the /etc/network/interfaces with a static IP address, but I still found in the daemon.log that dhclient was still requesting IP's from the DHCP and dhclient was started through systemd. Specifically, systemd called the networking.service unit, which called ifup, which read both the interfaces file and the 50-cloud-init.cfg file. Resulting in some conflicts, but still a functional network.

1
  • I had the exact same issue, and learned the hard way, that a later file (like 99-eth0.cfg) was indeed NOT overriding previous statements! So, thanks for your input ;)
    – Daywalker
    Mar 20 '18 at 18:17
1

I found for me, this was due to gnome's NetworkManager still running and thinking it was in charge of the device. In hindsight this should have been obvious as ps showed dhclient was being launched by NetworkManager.

Once I restarted my system the device went to "unmanaged" in NetworkManager and it stopped trying to configure it. Perhaps I could have achieved the same thing just by stopping/restarting NetworkManager, I'm not sure.

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.