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.

share|improve this question
2  
Possible duplicate of Is there a safe way to disable DHCP from command line? – Videonauth Nov 15 '17 at 16:07
up vote 16 down vote accepted
  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,

share|improve this answer
    
Nice trick, amazingly works. Thanks. – user276851 May 1 '14 at 20:32
    
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
    
Is it about modifying ('touch') the file so the date changes? Am I supposed to only edit the file AFTER I've brought down the interface? If so, how can I 'undo' the fact that I've edited it before? – fostandy Aug 16 '14 at 10:43
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
4  
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

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.

share|improve this answer

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/interface.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 adress, 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 is some conflicts, but still a functional network.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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