1

I've trawled the forums but not found an up to date answer to this. My apologies if I have missed it.

Basic Setup I have a rPi 2B+ with two wifi adapters connected. wlan0 & wlan1 both show in ifconfig. So far so good.

I've setup dhcpcd, dnsmasq and hostapd the same as I have done on a rPi3B+ I have to make an ad-hoc network. The rPi3 only has the onboard wifi (as the ad-hoc) and ethernet (to home router) and has been working fine for months.

With the rPi2 this also works fine when I put it as a direct replacement for the rPi3, so I am doing something right.

The Problem The difficulty is when I add the second wifi dongle to the rPi2. hostapd seems to be getting duff info as it is trying to setup the network on the wrong dongle...which is already connected to my home wifi. I assume this is a boot sequencing thing.

In the configuration for dhcpcd, dnsmasq and hostapd I have set it to wlan0. When I plugin the second dongle it takes the place of the first as wlan0 and what was that is now wlan1.

Easy fix, change the configs to wlan1 but this doesn't sit right with me and it's going to be a PITA when it is eventually running in the application, headless.

The Question Is there a way I can specify/force the above services to use a particular adapter, rather than interface, or tell Stretch to assign an adapter to a particular interface????

The only reference to this issue I can find is on the old version of Stretch where you modify /etc/network/interfaces, which nowadays breaks dhcpcd5.

tl;dr How can I know for certain which of the two wifi dongles is assigned to wlan0 and wlan1 such that dnsmasq, dhcpcd and hostapd work correctly.

2 Answers2

1

You could activate predictable network-interface names.

To do this, call

sudo raspi-config

and navigate to Network Options and choose the item Network interface names.

On the next reboot your interfaces will have unique names, which won't change anymore. For example they are also independent of the order you plug in your dongles.

Now you can work with those interface names in your configurations of dnsmasq, dhcpcd and hostapd.

oh.dae.su
  • 904
  • 1
  • 5
  • 12
0

This is a long standing problem; the order in which interfaces are enumerated is unpredictable, and this is exacerbated by the asynchronous init in systemd.

The Linux solution to this is predictable network interface names

"The old naming method suffered from enumeration race conditions that made it possible for interface names to change unexpectedly …. The new enumeration method … will have names based upon their ethernet MAC addresses."

All OS use some variant of this (although firmware/BIOS provided index numbers or PCI card slot numbers are used, which are not possible for the Pi).

The onboard WiFi of the Pi3 etc which is connected over sdio will however use the name wlan0. See How to set up networking/WiFi which describes options for enabling Predictable Network Interface Names.

There is one issue for the Pi (which does not affect normal computers) - the SD Cards are no longer portable between systems, although you could write udev persistent-net.rules to implement other naming systems.

Milliways
  • 54,718
  • 26
  • 92
  • 182