DEV Community

Faizudeen Kajogbola
Faizudeen Kajogbola

Posted on

Using a Raspberry Pi as a Home Router

This article walks you through how to use your Raspberry Pi (RPi) as a home router.

The central problem being solved is:

How to use a RPi’s wireless interface as a Wi‑Fi access point that is connected to the Internet via the RPi’s Ethernet port.

The solution relies heavily on NetworkManager’s shared connection mode.


Assumptions

Your RPi:

  • Is running Raspberry Pi OS based on Debian Bookworm (or later)
  • Has a working Internet connection via its Ethernet port
  • Manages network connections using NetworkManager

Steps

1. Verify that eth0 is correctly configured

Run:

sudo nmcli device
Enter fullscreen mode Exit fullscreen mode

Confirm that device eth0 is in the connected state.


2. Create a Wi‑Fi access point on the RPi’s wireless interface

# Create Wi‑Fi connection
# Of course you need to replace `wlan0`
#   with your interface name
sudo nmcli connection add type wifi \
  ifname wlan0 \
  con-name ap0 \
  ssid "<ACCESS-POINT-NAME>" \
  autoconnect yes

# Set access point mode
sudo nmcli connection modify ap0 \
  802-11-wireless.mode ap

# Use 2.4 GHz band
sudo nmcli connection modify ap0 \
  802-11-wireless.band bg

# Set WPA2/WPA3 pre‑shared key
sudo nmcli connection modify ap0 \
  wifi-sec.key-mgmt wpa-psk \
  wifi-sec.psk "<PASSWORD-GOES-HERE>"
Enter fullscreen mode Exit fullscreen mode

3. Enable NetworkManager’s “shared” mode

NetworkManager’s shared mode:

  • Starts a DHCP server on the interface
  • Enables IP forwarding
  • Enables IP masquerading (NAT)
# Enable shared mode
sudo nmcli connection modify ap0 \
  ipv4.method shared

# Specify IPv4 subnet
sudo nmcli connection modify ap0 \
  ipv4.addresses 172.18.0.1/24

# Disable IPv6 (optional)
sudo nmcli connection modify ap0 \
  ipv6.method ignore
Enter fullscreen mode Exit fullscreen mode

4. Start the access point

sudo nmcli connection up ap0
Enter fullscreen mode Exit fullscreen mode

5. Validate the setup

# Check Wi‑Fi access point gateway IP
ip -4 addr show wlan0

# Check routes
# Expect:
# - 172.18.0.0/24 via wlan0
# - default route via eth0
ip -4 route
Enter fullscreen mode Exit fullscreen mode

6. Connect a client and verify Internet access

# Connected devices at the Wi‑Fi (L2) layer
sudo iw dev wlan0 station dump

# Connected devices at the IP (L3) layer
ip neigh show dev wlan0
Enter fullscreen mode Exit fullscreen mode

References

Top comments (1)

Collapse
 
nagatodev profile image
Faruq Abdulsalam •

Really straightforward and easy to follow. Thanks for sharing!