0

I had Raspbian (Jessie) configured to obtain IP from DHCP. Now I changed it to static. Pi is now reachable on two IP addresses: restarted Pi, restarted other computer, restarted router. No change. Of course when this Pi is shutdown it does not answer.

Scanning with nmap, I see that the old IP appears some 10-20 seconds after the static one. Then both are reachable with ssh, I can login and confirm it is the same machine.

My /etc/network/interfaces is:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.222
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

ifconfig result is:

eth0      Link encap:Ethernet  HWaddr b8:27:eb:a0:43:d5
          inet addr:192.168.1.222  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1213 errors:0 dropped:1 overruns:0 frame:0
          TX packets:319 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:82350 (80.4 KiB)  TX bytes:39947 (39.0 KiB)

I have removed all from /var/lib/dhcp/, rebooted multiple times, waited >24 hours.

What am I missing?

  • Weird. It would be interesting to know what traffic occurs on the network (if you see a DHCP request) using a packet sniffer like Wireshark. – Brian Oct 20 '15 at 14:51
  • Jessie DOES NOT use dhcp (unless you have made some serious changes to it! Search this Forum for dhcpcd for other discussion. – Milliways Oct 21 '15 at 0:36
  • @Milliways It has dhcpcd5 installed as an alternative (alias) for dhcpd -- and as the OP points out, it is enabled by default. – goldilocks Oct 21 '15 at 1:38
  • @goldilocks my comment about dhcp was related to the reference to /var/lib/dhcp/ which is NOT used, so editing it will have no effect. – Milliways Oct 21 '15 at 2:47
  • @Milliways Okay. Maybe making that clear would be more helpful? I know it means typing 8 more characters, but... ;) – goldilocks Oct 21 '15 at 12:32
3

Raspbian uses dhcpcd by default. Static IP can be set in /etc/dhcpd.conf using this guide. In this case leave /etc/network/interfaces with the default content.


Or edit the /etc/network/interfaces as in the question and disable dhcpcd. There is a thread on Raspberry Pi forums.

Out of proposed solutions this one works:

sudo update-rc.d dhcpcd remove

Removing dhcpcd also worked, but the solution above seems to be the least obtrusive.

  • If the Foundation had setup dhchcd as the author intended /etc/network/interfaces would not be needed. They did not include 10-wpa_supplicant (according to dhcpcd man the default installation includes this). – Milliways Oct 21 '15 at 2:51
  • By default dhchcd configures a link-local address which works on ssh for a Pi directly connected to a PC (in my case a Mac and also allows afp) without needing static addresses. – Milliways Oct 21 '15 at 2:54
  • All the network boot service apparatus is my biggest pet peeve about GNU/Linux. It's responsible for probably a double digit percentage of the questions here (and almost as many at U&L), when you can completely replace it with 2 or 3 simple commands and zero configuration (except possibly WPA stuff). Pretty sure in this case: ip link set wlan0 up; wpa_supplicant -B -i wlan0 /etc/wpa/whatever.conf; ip addr add 192.168.1.222 dev wlan0 and maybe an ip route. But first you'd have to disable all the crap (= the hard part). Crazy and unorthodox, I know. – goldilocks Oct 21 '15 at 12:41
  • @goldilocks Could you define or point to a definition of all the crap? – techraf Oct 21 '15 at 14:29
  • All the default boot service stuff WRT networking. I'm not necessarily recommending this to you, I'm inappropriately using comments as a platform for discussion ;) and expressing an opinion as a long term linux user. This is not about a canonical "best practice":chat.stackexchange.com/rooms/30544/networking-revolt – goldilocks Oct 21 '15 at 14:42
2

There are two solutions to this.

Method One

Comment out all of the wlan1 config in your /etc/network/interfaces file. Like this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 192.168.1.222
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

#auto wlan1
#allow-hotplug wlan1
#iface wlan1 inet manual
#wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Method Two

This is undoubtably easier. First, keep your Pi on the original setting for internet, DHCP (the dynamic IP address setting.) Then, use your router's settings, not your Pi's to set a reserved local IP address. This process is different on ever router, so a quick google search for "how to set a reserved ip on [make and model of your router]" should do the trick.

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.