ajmas
Posts: 37
Joined: Sat Mar 24, 2012 2:28 pm

Raspbian Stretch as DHCP server

Mon Sep 16, 2019 4:22 pm

I am trying to set up my Raspberry Pi Pi 3 Model B as a DHCP server, with the upstream network being on the wlan0 interface. My end goal is:

Code: Select all

   internet <-----> wlan0 ...... eth0 <----> wifi router <-----> IoT devices
Since I am at home and don't have access to the downstream wifi router my set up is as follows:

Code: Select all

   internet <-----> wlan0 ...... eth0 <----> MacBook Air, via Thunderbolt ethernet adapter
I using dnsmasq as the DHCP server. Based on various documentation, I have done the following:

- Installed dnsmasq
- Modified /etc/sysctl.conf to enable forwarding
- Modified /etc/dhcpcd.confg to use a static address for eth0
- Modified /etc/dnsmasq.conf to include values for interface and dhcp-range
- Rebooted

Things don't seem to be working:

- macOS has a self-assigned IP address for the Ethernet port
- `sudo sysctl | grep forwarding` shows expected value as 1.
- on the Pi eth0 has no assigned IP address
- `service dnsmasq status` gives `unknown interface eth0`

I then proceeded to do a restart of dhcpcd via: `sudo service dhcpcd restart`, which seemed to resolve the issue. I then restart the Pi and all seemed okay, except my wlan0 doesn't have any IP address and the eth0 doesn't have any IPv4 address (though on a subsequent restart it did, before losing it). I am guessing the only reason I am even able to connect to the Pi is via the link-local IPv6 address - well briefly before I lose connectivity?

Guessing on the weird behaviour I am guessing something odd is happening with dhcpcd due to a bad config?

The config for additional lines added for `/etc/dhcpcd.conf` are:

Code: Select all

interface eth0
static ip_address=192.168.8.1/24
and the contents for `/etc/dnsmasq.conf` are:

Code: Select all

interface=eth0
dhcp-range=192.168.8.8,192.168.8.250,255.255.255.0,12h

epoch1970
Posts: 3794
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Raspbian Stretch as DHCP server

Mon Sep 16, 2019 4:59 pm

If you have configured anything in /etc/network/interfaces without deactivating dhcpcd, networking will fail. Do not configure anything in the interfaces file, and prefer configuring via dhcpcd.conf

If you have option "bind-interfaces" in /etc/dnsmasq.conf, systemd will fail to launch the service. Remove that option (or use "dynamic-interfaces" but you don't need it in this case.)

If "ifconfig" doesn't show eth0 but enx<MAC address> you have systemd's "Persistent Network Interface Naming" feature enabled. Disable PNIN in raspi-config or use that interface name in dnsmasq.conf instead of eth0.

HTH
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

ajmas
Posts: 37
Joined: Sat Mar 24, 2012 2:28 pm

Re: Raspbian Stretch as DHCP server

Mon Sep 16, 2019 5:15 pm

Turns out one of my issues was due to installing NetworkManager (based on other instructions), since this was wanting to do its own thing and was causing issues with dnsmasq, which I had installed prior, since it seems to provide its own version. For now I have uninstalled NetworkManager - I'll reevaluate this later.

For the wifi connectivity I am trying to work out how to diagnose why this is not working. Using `wpa_cli list_networks` I do see the networks configured in the wpa_supplicant file, but I would like to see any log output of why its failing to establish a connection. I should note the current network SSID does have an accent in its name and appears as:

Code: Select all

4c:32:75:c5:88:22	2412	-44	[WPA2-PSK-CCMP][ESS]	R\xc3\xa9s X
Though my listed networks does show:

Code: Select all

0	R\\xC3\\xA9s X	any
Note, I don't have influence on the SSID, so I can't change what is being used there.

Return to “Networking and servers”