1

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.

2

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.

| 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
2

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.

| 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 '16 at 16:12
2

The man page for dhcpcd tells us:

denyinterfaces pattern

         When discovering interfaces, the interface name must not match
         pattern which is a space or comma separated list of patterns
         passed to fnmatch(3).

To stop dhcpcd from operating on an interface(s), you can ask it to leave the interface alone by adding the a line to /etc/dhcpcd.conf.

in the OPs case this would be:

denyinterfaces eth0

This should stop dhcpcd messing with you on that specific interface while leaving dhcpcd enabled. This also lets you keep your interface configuration in /etc/network/interfaces. The other option is using what Ariffer suggested (Using /etc/dhcpcd.conf to do your config instead of /etc/network/interfaces.)

| improve this answer | |
0

You could disable the service. https://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.

| 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. – Colton 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. – Colton Feb 5 '13 at 22:17
0

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.

| improve this answer | |

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.