0

I've had my Pi for over a year now. It's configured as a sound server, so it's always on and always connected via wireless. During holidays, I turned my AP off but forgot to turn the Pi off. It has a script running as a service that will restart the wireless adapter via ifdown/ifup, then reboot if it is unsuccessful in getting a wireless connection. So the Pi went through a series of many reboots.

Now the Pi can't get its usual fixed address anymore. The Wifi dongle is recognised, it manages to scan for APs. I can connect to an open network or to the same network using DHCP, but the usual fixed address configuration fails. My Pi is headless, so I have to diagnose everything via ssh over Ethernet.

I managed to get it sort of working by removing the gateway address from /etc/network/interfaces, but then I have to add a route like route add -net default gw 192.168.0.1 dev wlan0 to gain access to the internet. When that route is created, the gateway address is ok, but the mask is set to 0.0.0.0 instead of 255.255.255.0. Any idea why my Pi is reacting like this, and how to fix it for good?

Content of various config files, and commands I have tried, are here.

2 Answers 2

1

So, I think I have it now. I just needed to delete all references to eth0 in /etc/network/interfaces. I had put them in so that I could connect to my headless machine to debug the wifi issue. so my interfaces file is:

auto lo wlan0 iface lo inet loopback allow-hotplug wlan0 iface wlan0 inet static address 192.168.0.5 netmask 255.255.255.0 gateway 192.168.0.1 wireless-essid Fomalhaut_closed_u pre-up wpa_supplicant -B w -D wext -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf post-down killall -q wpa_supplicant iface default inet dhcp 

When I do that, and reboot, I get that output for route:

default 192.168.0.1 0.0.0.0 UG 0 0 0 wlan0 link-local * 255.255.0.0 U 0 0 0 eth0 192.168.0.0 * 255.255.255.0 U 0 0 0 wlan0 

I think what is happening there is that the last route with the correct mask (255.255.255.0) acts on the local network, whereas the first one directs the whole internet traffic to 192.168.0.1 with no mask. It's not needed there, because it has already been routed to 192.168.0.1 using the correct mask as per the first rule.

0

When you use route add you should specify gateway. And when you are logging of, and on to a network in short period of time, it is possible that your router haven't released your IP yet, and will give you some other IP. Remember that what you set is only PREFERRED IP.

9
  • Even if it is in the router's reservation pool? That address (192.168.0.4) is reserved to the Wifi Adapter's MAC address. And when I specify route add -net default gw 192.168.0.1 netmask 255.255.255.0 dev wlan0, all requests to the outside internet fail. It only works when the route has the default gateway 0.0.0.0, which is the wrong one. Commented Jul 24, 2015 at 8:46
  • well it would be easy to tell if once every second reconnect it does assign you proper IP, and the other times some other IP. And I suppose that 255.255.255.0 is netmask for local network only. I'm no expert, but it rings a bell to me, that you should add another route to some external stuff, that would translate global addresses for your LAN network. Like if you want to access google, you should add it's IP, but there was a trick to avoid manually mapping whole internet. Somebody else should comment on this. Commented Jul 24, 2015 at 8:58
  • yes, the trick is to use "default" or "0.0.0.0" as a fake address that maps the whole internet. I did that, and it works with the wrong gateway. But the problem is that I never had to do this "route" thing manually before. I do manage to get the proper IP (192.168.0.4), so I don't think it's a router problem. Seems more like a configuration problem on the Pi, involving routing tables and/or wpa_supplicant. Commented Jul 24, 2015 at 9:01
  • Add <code> sleep(60) --make sure it is in seconds </code>[why it no work >.<] in your code and see what it does. If router haven't had time to notice you disconnected, it won't give you your previous IP because it is taken (by you - nice paradox). Sleep 60s would probably make router notice you've disconnected and free your IP for you to take it again.right? Commented Jul 24, 2015 at 9:04
  • Ah yes, I see what you mean now. I will add a longer delay. By the way, do you know what is the best way to restart wlan0 or the whole networking without rebooting? I have tried a script that contains ifdown --force wlan0; sleep 5; wpa_cli -i wlan0 terminate; sleep 5; ifup --force wlan0 but it doesn't work. Idem for /etc/init.d/networking restart. The wireless usb key does not turn on again. Commented Jul 24, 2015 at 9:12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.