Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a VM (on ESXi 5.1.0) running Debian Wheezy (7.0).

eth0 has a statically assigned address. eth1 was DHCP-assigned, and now I want to make it static.

Here is my old /etc/network/interfaces:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo eth0 eth1
iface lo inet loopback

# The primary network interface
allow-hotplug eth0 eth1
iface eth0 inet static
 address 10.2.1.77
 broadcast 10.2.1.255
 netmask 255.255.255.0
 pointopoint 10.2.1.1

iface eth1 inet dhcp

And here is my new /etc/network/interfaces:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo eth0 eth1
iface lo inet loopback

# The primary network interface
allow-hotplug eth0 eth1
iface eth0 inet static
 address 10.2.1.77
 broadcast 10.2.1.255
 netmask 255.255.255.0
 pointopoint 10.2.1.1

iface eth1 inet static
        address 10.1.0.254
        netmask 255.255.255.0
        gateway 10.1.0.1
        dns-nameservers 8.8.8.8

When I reboot, I can see dhcpcd try to renew my lease for my old DHCP-assigned address, and succeed. And then it overwrites /etc/resolv.conf, which should contain 8.8.8.8 but does not. eth1 does have the correct (static) address, however.

What am I doing wrong here? I don't want to disable dhcpcd outright. In the near future I might switch eth1 back to DHCP, or add a third DHCP-assigned interface.

share|improve this question

Run (as root):

update-rc.d -f dhcpd remove

If you want to re-enable it in the future,

update-rc.d dhcpd defaults

NOTE: Removing it from rc.d will disable it on all interfaces. Restoring it will enable on all interfaces.

share|improve this answer
    
So it's all interfaces or no interfaces? Is there a way to use an alternative dhcp client? – craig65535 Feb 5 '13 at 22:20
    
As far as I am aware, yes. I don't know much about Linux, sadly. – Kruug Feb 5 '13 at 22:24
    
So I was using the dhcpcd5 package. Looks like there are lots of alternatives: dhcpcd, udhcpc, isc-dhcp-client and pump are some of them. – craig65535 Feb 6 '13 at 0:20
    
Switched to isc-dhcp-client and it seems to be working now. – craig65535 Feb 6 '13 at 1:10

If you are using dhcpcd (the client daemon, most people here are confusing it with DHCP and DHCPd which is different), then add the following text on the bottom of /etc/dhcpcd.conf

static
interface eth0
static ip_address=172.16.0.5/24
static routers=172.16.0.1
static domain_name_servers=8.8.8.8

Of course remember to replace the IP info with your network details.

share|improve this answer
    
This was helpful reminding me that I needed to do the same thing on wlan0 on my Raspberry Pi when I wanted to switch to manual/static IP on Raspbian Jessie, which runs DHCPd by default. No need to uninstall it completely as long as you configure /etc/dhcpcd.conf correctly. – geerlingguy Apr 4 at 16:12

You could disable the service. http://serverfault.com/questions/32438/disable-a-service-from-starting-at-all-runlevels

The preferred method would be to update the /etc/sysconfig/network-scripts/ifcfg-* file for the device removing the dhcp line (or altering it to false)

Unfortunately I'm not in front of my linux machine right now so I can't pull the exact configuration for you.

share|improve this answer
1  
Unfortunately /etc/sysconfig does not exist on Debian. Or at least on my install. – craig65535 Feb 5 '13 at 22:13
    
I should also mention that doing both wont hurt anything unless you plan on adding a NIC that will use DHCP. – codeReign Feb 5 '13 at 22:13
    
My appologies. I've only ever encountered this problem when using network manager on the command line. After a quick google it appears those files are part of NetworkManager configuration opposed to what you are using. – codeReign Feb 5 '13 at 22:17
up vote 0 down vote accepted

This is caused by a limitation in dhcpcd5 - it enables DHCP on all interfaces (all or nothing). I fixed this by switching to isc-dhcp-client which is more flexible.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .