I'm trying to create an ad-hoc wifi made of 5 computers (one Windows PC and 4 raspberry pi's loaded with a raspbian). The raspberry pi will talk through mqtt, but that's not the point. The problem I have is that I always need to do the following in order to have the wlan0 interface after each reboot:

sudo ifdown wlan0
sudo ifup wlan0

Do you know why? Here is my conf (the same on each pi except the IP address obviously!)

~ % ifconfig                 
eth0      Link encap:Ethernet  HWaddr b8:27:eb:ff:88:99  
          inet addr:  Bcast:  Mask:
          RX packets:951 errors:0 dropped:0 overruns:0 frame:0
          TX packets:266 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:66321 (64.7 KiB)  TX bytes:43663 (42.6 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:0f:13:51:05:8c  
          inet addr:  Bcast:  Mask:
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:42 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:2520 (2.4 KiB)

~ % iwconfig
wlan0     IEEE 802.11bgn  ESSID:"mirroir"  
          Mode:Ad-Hoc  Frequency:2.412 GHz  Cell: 42:B1:44:EB:D2:C1   
          Tx-Power=20 dBm   
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Power Management:on

lo        no wireless extensions.

eth0      no wireless extensions.

~ % more /etc/network/interfaces 
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
auto wlan0
iface wlan0 inet static
    wireless-channel 1
    wireless-essid mirroir
    wireless-mode ad-hoc
    wireless-key 967136deac

~ % sudo route add -net netmask wlan0

~ % netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         UG        0 0          0 eth0     *        U         0 0          0 wlan0     *        U         0 0          0 eth0

Any idea?

It seems to work, but not always -- like 1 boot out of 10, really weird?!

  • Is that the setting after the down/up or before? – ott-- Sep 30 '13 at 21:24
  • after, before wlan0 has no ip – xavier.seignard Sep 30 '13 at 21:29
  • i can't see how it is figuring out the gateway ip? maybe try adding gateway directly under the netmask line in your /etc/network/interfaces file – mulllhausen Oct 1 '13 at 1:41

Have you tried one of the solutions below? I have to guess the answer here as the problem is not easy to reproduce, may be an issue with the driver you got.

  1. In the interfaces file try commenting out "auto wlan0" and just keep "allow-hotplug wlan0"

    #auto wlan0
    allow-hotplug wlan0
    iface wlan0 inet dhcp
    ... rest of the config ...
  2. Probably not the ideal solution you are looking for but try creating a new shell script with execute privileges in your favourite scripts directory with the following content.

    ifdown wlan0 
    ifup wlan0 

    Then add the following line to your interfaces file.

    auto wlan0
    iface wlan0 inet dhcp
    ... rest of the config ...
    post-up /path-to-your-script/script.sh
  3. When your computer starts up without the wireless connection active. Try fiddling with iwconfig with different parameters (try man iwconfig to get a complete list) until your interface comes up. I guess may be txpower sort of switch might help you out here. If that works for you, then use pre-up <command-that-worked> in your interfaces file like in the 2nd answer and leave the command there.

    So something like this at the end (remember to pass absolute paths to (pre|post)-up

    pre-up /sbin/iwconfig wlan0 txpower on
  • Hi, thx for that complete answer! I tried the first solution without success. The workaround i use is the solution 2, I added it in /etc/rc.local. I should give a try to the third solution you're giving. Thanks! – xavier.seignard Oct 1 '13 at 7:18
  • did any of the above solutions work for you? if you have managed to solve the problem please share.. thanks – Purinda Gunasekara Oct 25 '13 at 5:51
  • hi, I haven't tried yet the third one, i will give a try next week – xavier.seignard Oct 25 '13 at 14:36
  • Solution 1 worked for me. – dgmdan Aug 9 '14 at 4:22

Exactly same problem here. The problem was a timing issue: wlan0 wasn't ready when the boot process issued the ifup.

I solved this by adding a wait statement pre-up sleep 5 to wlan0 in the interfaces file:

marcelo@breeze:~$ cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
  pre-up sleep 5 
  wpa-ssid mycoolssid
  wpa-psk returnguantanamo

Maybe you want to use different "local" networks for the eth0 interfaces and wlan0.

So for wlan use network like, mask And for eth use network like, mask

I haven't had this problem on RPI (probably because I always keep wlan0 and eth0 network IPs very different). But on my windows PC I have this problem all the time: When I use wireless with 192.168.1.x and then I plug into ethernet port, for example my rasbperry with 192.168.0.x address (mind the 3rd octet), I always loose network connection.


Uncomment auto eth0, auto eth1 or auto wlan for the interface you wish to come up when the unit boots.

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.