Using eth0 and wlan0

This can be problematic with Raspbian.  We have found out the hard way that using DHCP on both adaptors results in eth0 working fine but the gateway IP address assigned by wlan0 DHCP being completely ignored and when using wlan0 to send packets the Linux OS sends ARP requests assuming that any destination IP address is on the local network, instead of passing packets to the gateway as it should.  We haven't found a fix to this other than to not use DHCP or to issue the following command to assign the gateway IP address to wlan0 programatically each time after it connects (its volatile):


sudo route add default gw 192.168.1.1 wlan0

Forcing Fixed Network Adapter Names

Unfortunately wlan0 is not always the onboard WiFi on a RPi. We've found issues using the onboard WiFi to create an access point and an additional plug in USB WiFi dongle to connect to a different WiFi network where wlan0 is randomly allocated on power-up and restart.  In our experiences (with Raspbian Jesse and a RPI3) removing the HDMI monitor could cause allocation to change when next rebooting.  There are well knows ways to allocate WiFi adaptor based on MAC address but this isn't helpful when running on lots of different RPi's.  The following is based on the excellent guide at https://www.raspberrypi.org/forums/viewtopic.php?f=36&t=198946 and allocates the adaptors based on physical USB port.

Switch off systemd-predictable mechanism stuff 


sudo ln -nfs /dev/null /etc/systemd/network/99-default.link

Now setup udev rules that uniquely identify the interfaces based on their USB connector positions.  Create the file:


sudo nano /etc/udev/rules.d/72-wlan-geo-dependent.rules

Paste the following into it:


#
# +-----+---------------+
# |     | wlan4 | wlan3 |
# |RJ45 +-------+-------+
# |     | wlan2 | wlan1 |
# +-----+---------------+ (RPI USB ports with position dependent device names for up to 4 optional wifi dongles)
# 
# | wlan0 | (onboard wifi)
#
ACTION=="add", SUBSYSTEM=="net", SUBSYSTEMS=="sdio", KERNELS=="mmc1:0001:1", NAME="wlan0"
ACTION=="add", SUBSYSTEM=="net", SUBSYSTEMS=="usb",  KERNELS=="1-1.2",       NAME="wlan4"
ACTION=="add", SUBSYSTEM=="net", SUBSYSTEMS=="usb",  KERNELS=="1-1.4",       NAME="wlan3"
ACTION=="add", SUBSYSTEM=="net", SUBSYSTEMS=="usb",  KERNELS=="1-1.3",       NAME="wlan2"
ACTION=="add", SUBSYSTEM=="net", SUBSYSTEMS=="usb",  KERNELS=="1-1.5",       NAME="wlan1"

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

  1. David Stein

    4 years ago

    Fails on Raspbian Stretch 9.8.

    (1) /etc/systemd/network/99-default.link is already redirected to /dev/null.

    (2) Rebooting after adding 72-wlan-geo-dependent.rules just causes the adapters to no longer appear.

Comments

Your email address will not be published. Required fields are marked *