15

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?

  • What is the command you are referring to? – Madoc Comadrin Oct 12 '15 at 5:25
  • I tried those commands but was not able to find anything to help me in this. – Madoc Comadrin Oct 12 '15 at 16:06
  • @barlop There is nothing wrong with ifconfig and it is used regularly. It will one day be replaced by ip but honestly, it’s of no consequence to badger someone about which is “better” since this is not a pissing contest. ifconfig provides more than enough details for debugging things like this. – JakeGould Oct 12 '15 at 17:12
11

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.

|improve this answer|||||
  • 2
    My case was almost identical to one described here. Only difference was that my /etc/network/interfaces never got changed to manual like it was in Raspberry Pi forums case. Suggested solutions worked for me as well. – Madoc Comadrin Oct 12 '15 at 18:37
  • 1
    Same, where even with "static" I'm getting dhcp on my eth0. This is still an issue with a jessie-lite install. The workaround isn't helping me yet as I have a situation where I need the wlan0 interface to have a lower metric than the eth0 interface and I can't get dhcpcd5 to let me do that (so far). – Peter Hansen Feb 6 '16 at 16:53
  • 3
    A workaround that did work for me, however, was to tell dhcpcd5 not to look at eth0. This was done by adding "denyinterfaces eth0" in /etc/dhcpcd.conf. – Peter Hansen Feb 6 '16 at 17:33
  • 1
    @PeterHansen Good to know! Added that info to the end of my answer. – JakeGould Feb 6 '16 at 18:31
  • 2
    A followup: in some cases I've found I had both dhcpcd5 and isc-dhcp-client installed, both assigning addresses. Furthermore, there's a systemd-initiated dhcpcd.service which runs on all interfaces (with options -q -b) as well as the dhcpcd5 process started by the "dhcp" option in network/interfaces. Sigh... fairly easy to solve once you know all that, I hope. – Peter Hansen Oct 12 '16 at 15:02
8

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
|improve this answer|||||
  • In a scenario where you don't care about DHCP (or anything else dhcpcd can do) this is the easiest solution. – AVee Nov 19 '16 at 16:30
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.

|improve this answer|||||
1

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.

|improve this answer|||||
0

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

|improve this answer|||||
0

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

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