0

I am new to configuring networks so please excuse my ignorance if I have made some obvious and simple mistakes. For educational purposes, I am trying to set up a small wired network where a Raspberry Pi 4 is being used as a router and dhcp server, and where it will share its internet connection on wlan0 (connected to my home wifi router) with any devices connected to the wired private local network.

I have been following an online tutorial that covers setting a static IP address for eth0, installing and configuring dhcp server software on the RPi, and configuring iptables for routing between eth0 and wlan0, but have not yet completed the full setup. I have only got as far as setting the static ip address, and installing and configuring the dhcp server software package (isc-dhcp-server) and am trying to test the dhcp server configuration. The current network topology looks like this:

 +----------+
 | Internet | (provided by wifi connection to home router)
 +-----+----+
       | (wlan0)
 +-----+----------+
 | Raspberry Pi 4 | (router + DHCP server)
 +-----+----------+
       | (eth0)
 +-----+-------+
 |   Laptop    |
 +-------------+

As mentioned above, internet traffic is not yet routed from eth0 to wlan0 to provide internet to my laptop via the ethernet connection. Currently wlan0 is connected to my home wifi to provide internet to the RPi. My laptop is also connected to my home wifi in order to access the internet. This is just for convenience at this stage.

Raspberry Pi Network Configuration

dhcpcd.conf

I am configuring the network settings for eth0 on the RPi using /etc/dhcpcd.conf, which contains the following:

# /etc/dhcpcd.conf on Raspberry Pi (router + DHCP server).

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes

# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# Most distributions have NTP support.
option ntp_servers

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
slaac private

# Assign static IP address to eth0:
interface eth0
static ip_address=10.0.0.1/24
static routers=10.0.0.1
static domain_name_servers=10.0.0.1 8.8.8.8

isc-dhcp-server Configuration

dhcpd.conf

I installed isc-dhcp-server and applied the following configuration:

# /etc/dhcp/dhcpd.conf on Raspberry Pi (router + DHCP server).
# Configuration file for ISC dhcpd

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;

# Configure DHCP server for LAN connected to eth0 (on subnet 10.0.0.0):
subnet 10.0.0.0 netmask 255.255.255.0 {
    range 10.0.0.10 10.0.0.250;
    option domain-name-servers 10.0.0.1, 8.8.8.8;
    option routers 10.0.0.1;
    option broadcast-address 10.0.0.255;
    default-lease-time 600;
    max-lease-time 7200;
}

Constrain these settings to eth0

# /etc/default/isc-dhcp-server on Raspberry Pi (router + DHCP server)

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
INTERFACESv4="eth0"
INTERFACESv6=""

I have verified that eth0 has been correctly assigned its static IP address, etc., and that isc-dhcp-server appears to be running OK.

Laptop Details

I have attempted to test the dhcp server configuration using a 2016 MacBook running MacOS Mojave (10.14.6). This laptop only has a single USB-C port so I am using a Belkin USB-C to ethernet adapter (F2CU040) to connect it to the RPi.

In the network settings I have added a new connection to use the "Belkin USB-C LAN" interface and have selected "Using DHCP" in the drop down menu for the "Configure IPv4" parameter.

Problem

If I have my laptop connected to my home wifi when I plug in the ethernet cable, the RPi cannot assign it an IP address. Running tail -f /var/log/syslog on the RPi seemingly shows an endless stream of DHCPDISCOVER requests from the laptop and subsequent DHCPOFFER replies from the RPi.

So it seems that the issue is that the laptop is unable to accept the DHCPOFFER, for some reason. After a short amount of time the laptop gives itself a self-assigned IP address of 169.254.27.98, but is seemingly still sending DHCPDISCOVER requests to the RPi, but then is not able to accept the IP address that the RPi offers. I am not sure if there is a log file that displays the equivalent information MacOS so I can see what is happening on that end of the connection. The system.log file does not appear (at least as far as I can tell) to show dhcp related activity.

Alternatively, if I have wifi turned off on my laptop, when I attach the ethernet cable it receives an IP address correctly and I can successfully ping the RPi from my laptop and vice versa.

Additionally, if the laptop's wifi is turned on when I connect the ethernet cable I am still able to access the internet. However, if I start with the laptop's wifi turned off, connect the ethernet cable to the RPi and successfully get an IP address, if I then turn the wifi back on, I can no longer communicate with the RPi (pinging the RPi from the laptop says there is "no route to host", pinging the laptop from the RPi says "destination host unreachable") and can't access the internet on my laptop either (website loading freezes, but I don't get a message in my browser to say I am not connected to the internet), despite it seemingly successfully connecting to my home wifi network.

If instead, I manually set the IP address, subnet mask and router IP address in the network settings on my laptop, I can successfully connect to the RPi, even when the laptops's wifi is turned on, and I can still access the internet on my laptop.

At all times, the RPi is connected to my home wifi and this works fine regardless.

Obvious Answer

Of course, eventually I will not need to have the wifi turned on, on my laptop, because it will be able to access the internet via the RPi. So the obvious answer is to just disable wifi and continue with the setup, and indeed this is what I will do, for now. But, I just really want to know what is going on here, and I can't seem to find anything from searching this issue.

Questions

  1. Have I done something wrong in the configuration?
  2. Will this problem resolve itself if I complete the full setup I intend on doing?
  3. Is there something on my laptop that I need to configure?
  4. Is the problem on my laptop and not on the RPi?
  5. If so, am I posting this in the wrong place?
2
  • Using DHCP for the eth link seems totally pointless and hence is an unnecessary source of potential confusion. You've said it works if you manually assign an IP on the laptop, and "it seems that the issue is that the laptop is unable to accept the DHCPOFFER" seems to confirm the issue is with the laptop, not the Pi. There are mac users around here but it seems to me you should be pursing it that way. apple.stackexchange.com
    – goldilocks
    Commented Mar 19, 2021 at 13:51
  • @goldilocks You are right that it would be totally pointless to use DHCP in the setup that I have described above. I was forced to edit some things out of my question to try and get past the spam filter. One of those things that I removed was that I would eventually have an ethernet switch attached to the RPi between it and the laptop and have some other things plugged in too - one of which would be a wireless access point and so I would like the RPi to supply an IP address dynamically to any devices that connect to the AP. Commented Mar 19, 2021 at 14:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.