Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to create an ad-hoc wifi made of 5 computers (one windows pc and 4 raspberry pi loaded with a raspbian) the raspberry pi will talk through mqtt, but tha'ts 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 adress obviously!)

~ % ifconfig                 
eth0      Link encap:Ethernet  HWaddr b8:27:eb:ff:88:99  
          inet addr:192.168.1.41  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          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:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          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
    address 192.168.0.2
    netmask 255.255.255.0
    wireless-channel 1
    wireless-essid mirroir
    wireless-mode ad-hoc
    wireless-key 967136deac

~ % sudo route add -net 192.168.0.0 netmask 255.255.255.0 wlan0

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

Any idea?

UPDATE: it seems to work but not always, like 1 boot out of 10, really weird?!

Regards

share|improve this question
    
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 192.168.1.254 directly under the netmask 255.255.255.0 line in your /etc/network/interfaces file –  mulllhausen Oct 1 '13 at 1:41

2 Answers 2

up vote 3 down vote accepted

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
    
share|improve this answer
    
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 at 4:22

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

So for wlan use network like 10.10.0.1, mask 255.255.255.0 And for eth use network like 192.168.0.1, mask 255.255.255.0

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.