In a previous question I asked whether multiple IPs can be assigned via DHCP and reserved by a single Raspberry Pi. The accepted answer demonstrates how to achieve this by setting up virtual network interfaces linked to eth0 and assigning a unique MAC address to the interface.
When I attempt the same steps using wlan0 instead of eth0 I get IPs allocated on the 192.254.x.x subnet, which suggests there is an issue reaching the DHCP server.
Is there a reason this process would work for eth0 but not wlan0?
I start by loading the latest Raspbian image onto my Raspberry Pi (Buster 2021-01-11).
I create a file /etc/network/interfaces.d/eth0 and write the following:
auto eth0 iface eth0 inet manual up ip link add link eth0 name eth0.01 address 02:00:00:00:00:01 type macvlan up ip link add link eth0 name eth0.02 address 02:00:00:00:00:02 type macvlan
I create a file /etc/network/interfaces.d/wlan0 and write the following:
auto wlan0 iface wlan0 inet manual up ip link add link wlan0 name wlan0.01 address 02:00:00:00:00:A1 type macvlan up ip link add link wlan0 name wlan0.02 address 02:00:00:00:00:A2 type macvlan
These settings are applied with the command:
sudo systemctl restart networking
Let's WiFi tether to an Android cell phone. Hopefully this is an easily repeatable setup; it implements a DHCP server at 192.168.43.1/24 using netd to handle the tethering using dnsmasq. To try to keep things comparable between the eth0 and wlan0 interface I use a DLink WiFi extender to wirelessly tether to the Android's WiFi Hotspot and forward a WiFi signal to the Raspberry Pi's wlan0 and an ethernet cable to connect to the Raspberry Pi's eth0 interfaces.
I use the following command to see what my IP addresses are for each interface:
Here is a summary of the lines of code that are of interest:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.43.233 netmask 255.255.255.0 broadcast 192.168.43.255 eth0.01: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.43.41 netmask 255.255.255.0 broadcast 192.168.43.255 eth0.02: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.43.54 netmask 255.255.255.0 broadcast 192.168.43.255 wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.43.76 netmask 255.255.255.0 broadcast 192.168.43.255 wlan0.01: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 169.254.36.195 netmask 255.255.0.0 broadcast 169.254.255.255 wlan0.02: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 169.254.75.246 netmask 255.255.0.0 broadcast 169.254.255.255
It is clear that the wlan0.01 and wlan0.02 interfaces are not communicating with the DHCP server (as seen by the IPs starting with 169.254), whereas the eth0.01 and eth0.02 interfaces are.
Can I reserve two IPs via the wlan0 interface?