Is there a way to disable the DHCP client in Raspbian Linux on a Rasperry Pi?

I have a Linux server (Rasperry Pi using Raspbian as OS) that should be using only static IP.

However I noticed that it also has got IP from DHCP server (The IP given out by DHCP is 192.168.111.2). According to network settings the server should be only using static IP (192.168.111.100).

The contents of /etc/network/interfaces:

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.111.100
netmask 255.255.255.0
gateway 192.168.111.1
dns-nameservers ip1 ip2

Despite using static configuration I can SSH to the device also using the IP given by DHCP. Also it appears that ntpd is using the wrong IP as well as the correct one.

Output of Netstat:

udp 0 0 192.168.111.2:123 0.0.0.0:* 2774/ntpd
udp 0 0 192.168.111.100:123 0.0.0.0:* 2774/ntpd

According to ifconfig the IP 192.168.111.2 is not used:

eth0 Link encap:Ethernet HWaddr b8:27:eb:be:18:1c inet addr:192.168.111.100 Bcast:192.168.111.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:138099 errors:0 dropped:0 overruns:0 frame:0 TX packets:81146 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:95954711 (91.5 MiB) TX bytes:27076870 (25.8 MiB)

ps -ef | grep dhcp shows that I have a DHCP daemon running:

root 2000 1 0 Oct07 ? 00:00:06 /sbin/dhcpcd

How do I disable the DHCP daemon from starting and make sure that my server uses only the static?

3

6 Answers

This scenario sounds really weird because your setup should be working as you describe—and hope for it to work—if there is a static IP set in /etc/network/interfaces. That said, this discussion on the official Raspberry Pi site focuses on the issue with the user “rpdom” stating this on the post dated “Thu May 28, 2015 6:21 am”:

This happens in the latest updates. It is caused by the new dhcp client ignoring what the interfaces files does and doing its own thing in addition... seems crazy to me. I'd look at how to reconfigure the dhcp client (can't rememeber which it is or how to do it, I'm still on the old one which works for me), disabling it, or removing it (if possible).

Deeper in the thread user “KLL” suggests the following other post in their response dated “Mon Aug 10, 2015 12:59 pm.” According to “knute”:

Somewhere along the way an upgrade modified my /etc/network/interfaces file with the 'manual' word instead of dhcp or static and I ended up with two IP addresses, my static one and a dhcp address. I finally had time to play with it and found out that dhcpcd5 works differently than whatever was in it before. To get just your static address, do not modify /etc/network/interfaces. Put back the 'manual' word if you changed it and instead modify /etc/dhcpcd.conf as shown in the example from the docs.

So the idea is that dhcpcd5’s behavior has changed in one of the upgrades. And suggestion to solve the issue is to remove any changes from /etc/network/interfaces and instead adjust the settings in /etc/dhcpcd.conf to get a static IP address; example config below:

static <value> Configures a static <value>. If you set ip_address then dhcpcd will not attempt to obtain a lease and just use the value for the address with an infinite lease time. Here is an example which configures a static address, routes and dns. interface eth0 static ip_address=192.168.0.10/24 static routers=192.168.0.1 static domain_name_servers=192.168.0.1

More info on the contents of dhcpcd.conf can be found on the official man page for it.

That said, another idea is to retain the settings you have in /etc/network/interfaces but then edit /etc/dhcpcd.conf to add the line denyinterfaces eth0 to tell the DHCP daemon to completely ignore eth0. Either solution should work, but one solution might be a more preferable solution depending on your overall networking needs/requirements.

7

what worked for me is using a /etc/network/interfaces as in the original question and simply removing the dhcp client:

apt-get remove dhcpcd5 isc-dhcp-client isc-dhcp-common
1

I must say that unfortunately none of the solutions proposed here worked for me. But after a long battle with DHCP, I was finally able to solve the problem:

vi /etc/systemd/network/eth0.network

change:

[Match]
Name=eth0
[Network]
DHCP=yes

to:

[Network]
DHCP=no

hope this helps.

0

The preferable way to disable any service such as dhcpcd is use the system management functions. You'll need to reboot for it take effect - unless you stop the service as well.

For Jessie (which uses systemd management):

sudo systemctl disable dhcpcd.service

And for the older Wheezy (System-V management):

sudo update-rc.d dhcpcd disable

But if you do disable it then you need to make sure you've got a static ip configuration in /etc/network/interfaces otherwise your interfaces won't get an IP address.

Here's a summary of what I needed to do for Raspbian Jessie 2017-01-11:

Edit /etc/network/interfaces and add the static address stanza, remove other references to the static interface (eth0 in this case). The auto line is important otherwise the interface will not start at boot:

 auto eth0 iface eth0 inet static address 192.168.44.17 netmask 255.255.255.0 gateway 192.168.44.27

Next disable dhcpcd and enable standard networking:

  • Disable dhcpcd: systemctl disable dhcpcd.service
  • Enable networking: systemctl enable networking
  • reboot

Raspbian Jessie as of the 2017-01-11 release does not seem to use systemd's networking

1

Tried a few things and found that

 apt list --installed | grep dhcp

found:

dhcpcd5
isc-dhcp-client
isc-dhcp-common

I just disabled dhcpcd5 and that fixed it using:

 sudo apt-get remove dhcpcd5

did a reboot and all was dandy

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like