DHCP server bound to hotpluggable interfaces

543 views Asked by At

I have a Raspberry Pi 3 (Pi3) and a Raspberry Pi Zero (Pi0). The Pi0 is pluged into the Pi3 via USB.

I am using Raspberry Pi Zero OTG Mode to make the Pi0 appear as a network interface on the Pi3

I have installed isc-dhcp-server on the Pi3. I want it to assign the Pi0 an IP address.

on the Pi3 /etc/default/isc-dhcp-server is as follows: (All other lines commented)

INTERFACES="ethpi1"

on the Pi3 the /etc/network/interfaces file is as follows:

allow-hotplug ethpi1
iface ethpi1 inet static
    address 192.168.2.1
    network 192.168.2.0
    netmask 255.255.255.0
    broadcast 192.168.2.255
    gateway 192.168.2.1


auto lo
iface lo inet loopback

allow-hotplug wlan0
iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

#allow-hotplug eth0
iface eth0 inet manual

When I start up the Pi3 the usb interface is not present. (This is because I am using a cluster hat and after startup I need to use the command clusterhat on p1 to start it.)

This means the interface that the dhcp server is bound to is missing (ethpi1). IP a won't display it. If I run systemctl I can see that isc-dhcp-server is in red and has failed.

If I start the Pi0 (analogous to plugging in the Pi0) I can see the interface appear in ip a after Pi0 has booted.

I can use "ifconfig ethpi1" to see traffic coming through the interface. However the dhcp server is still in failed state. I can restart it with the command:

sudo service isc-dhcp-server restart

it then starts successfully. Finally after waiting a bit more the Pi0 has got itself an ipaddress and I can use the command

ssh [email protected]

and I can successfully log on to my Pi0.

I want to find a way to configure the dhcp server to bind to the interface ethpi1 when it sees it appear and unbind from it when it dissapears.

I will want to extend this later as I add more interfaces. (ethpi2, ethpi3, etc)

Is this possible?

1

There are 1 answers

0
Robert3452 On

I was able to figure out that the correct approach was to create a bridge and assign the dhcp server to the bridge interface