1

My Pi is set to a static IP. But after a few hours or days it is suddenly no longer reachable on this IP. I now figured out that when this happens the wlan0 interface is no longer on this static IP but on a different one...

This is my interfaces file

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

auto wlan0
iface wlan0 inet static
address 192.168.1.100
gateway 192.168.1.2
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255

This morning it was on 192.168.1.100, but now it is on 192.168.1.105. How can this happen?

Jacobm001
  • 11,898
  • 7
  • 46
  • 56
Reto
  • 165
  • 1
  • 1
  • 5
  • I always advise against setting the IP static in the PI, do so in your router if possible. What version of raspbian are you running? I had wifi issues with Wheezy in the past, moving to Jessie has resolved that for me. (Pi2) – Havnar Feb 18 '16 at 14:51
  • Unfortunately my router does not support static IP... I am on wheezy... – Reto Feb 18 '16 at 14:59
  • are you perhaps using the retropie image? – Havnar Feb 18 '16 at 15:35
  • I am using the wheezy image from raspberrypi.org – Reto Feb 18 '16 at 15:43
  • You have both auto wlan0 and allow-hotplug wlan0. Could it be that your usb draw too much power, the usb disconnects (maybe just for a few seconds). Then it falls back to eth0 which gets a new IP via DHCP. Then you're wlan0 card comes back up and your connection changes. In other words: 192.168.1.105 is probably eth0 not wlan0. Try sudo ifconfig to check – kba Feb 18 '16 at 15:45
  • No, I checked that. eth0 is not connected and ifconfig says wlan0 is on 192.168.1.105 – Reto Feb 18 '16 at 15:47
  • What does iface default inet dhcp stand for? Do I need this? – Reto Feb 18 '16 at 19:40
  • Take a look here: https://wiki.debian.org/WPA: "The following line specified in /etc/network/interfaces will activate and configure each 'default' network in wpa_supplicant.conf with DHCP upon a successful connection to an access point". So it look it's your troublemaker. – nsilent22 Feb 18 '16 at 20:12
  • So you think I should remove the line iface default inet dhcp? Or change it to iface default inet static or iface default inet manual? – Reto Feb 18 '16 at 20:51

1 Answers1

2

"My Pi is set to a static IP" - No it isn't! You have 2 different settings for wlan0. It is unpredictable what would happen.

See https://raspberrypi.stackexchange.com/a/37921/8697 for a tutorial on how to setup.

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • Thank you for the link to your tutorial. But I cannot see why I have two different settings. Because of manual and static? Can I correct this without changing everything do dhcpcd? – Reto Feb 19 '16 at 08:15
  • iface wlan0 inet manual and iface wlan0 inet static are attempting to configure wlan0 in different ways. Pick one or the other. If you really want static I recommend the method in the tutorial. If you want to use the older (less robust) method you should disable dhcpcd . This is disabled because you invoke dhcp. – Milliways Feb 19 '16 at 08:41
  • I removed iface wlan0 inet manualbut now I have no more connection. So I will have to try the new method. – Reto Feb 19 '16 at 12:18
  • Where do netmask, broadcast etc. go? Is this not needed here? Compared with the above, is this what I should have in dhcpcd.conf? interface wlan0 static ip_address=192.168.1.100 static routers=192.168.1.2 static domain_name_servers=192.168.1.2 – Reto Feb 19 '16 at 13:02
  • @Reto NOTE You should have removed iface wlan0 inet static and all reference to dhcp (as per the tutotial) NOT iface wlan0 inet manual. You have a choice to use dhcpcd or not. If not you should disable it. – Milliways Feb 19 '16 at 22:56
  • @Reto You don't need netmask if you use a proper CIDR format (as in the tutorial). Note I don't recommend static, don't use it and consider it unnecessary. I use zero-conf. The tutorial contains an extract from `man dhcpcd.conf`` which you should read. – Milliways Feb 19 '16 at 22:59
  • I upgraded to jessie but I do not have dhcpcd. I tried installing it manually but still the service does not exist and the conf file is missing... what can I do? – Reto Feb 21 '16 at 07:53
  • @Reto When you say "I upgraded to jessie" did you do a new install? It is not possible to upgrade from Wheezy. Why do you think you don't have dhcpcd. – Milliways Feb 21 '16 at 10:20
  • No, not a new install. I followed one of the many wheezy to jessie upgrade guides. – Reto Feb 21 '16 at 10:40