Set Up a Raspberry Pi as a Wireless Router with Static IP and DHCP
By K Taylor 05\30\2025

Set Up a Raspberry Pi as a Wireless Router with Static IP and DHCP

Turn Your Raspberry Pi into a Personal Router

Using hostapd and dnsmasq to serve your own wireless network

From a helpful YouTube tutorial by SpaceRex, I was able to set up a Raspberry Pi as a wireless router. This gave me the ability to create a local network to accept client connections, without the need for commercial hardware.

This guide helps with the following:

  • Setting a static local IP address
  • Enabling IPv4 forwarding for internet routing
  • Creating an SSID and password for your custom router

1. Update and install necessary packages

>sudo apt update && sudo apt upgrade
>sudo apt install hostapd dnsmasq
>sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent

2. Enable and start the access point service

>sudo systemctl unmask hostapd.service
>sudo systemctl enable hostapd.service

3. Configure the static IP address for wlan0

sudo nano /etc/dhcpcd.conf
Add at the bottom:
interface wlan0
static ip_address=10.20.1.1/24
nohook wpa_supplicant

4. Enable IP forwarding

sudo nano /etc/sysctl.d/routed-ap.conf
Add:
net.ipv4.ip_forward=1

5. Add internet routing rules for eth0

>sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
>sudo netfilter-persistent save

6. Configure DHCP via dnsmasq

>sudo cp /etc/dnsmasq.conf /etc/dnsmasq.bak
>sudo nano /etc/dnsmasq.conf
Insert:
interface=wlan0
dhcp-range=10.20.1.5,10.20.1.100,255.255.255.0,300d
domain=wlan
address=/rt.wlan/10.20.1.1

7. Set up your SSID and WPA2 password

>sudo nano /etc/hostapd/hostapd.conf
Example config:
country_code=US
interface=wlan0
ssid=raspynet
hw_mode=g
channel=7
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=raspynet100
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

8. Check if everything is working

ifconfig

Tip: Use a MiFi Device for Internet Over Ethernet

If you're using a MiFi or cellular dongle over USB Ethernet (e.g., enx0015ff313880), you can re-route internet like so:

sudo iptables -t nat -A POSTROUTING -o enx0015ff313880 -j MASQUERADE

Credit

Much of this tutorial was derived from SpaceRex's guide on YouTube:
https://www.youtube.com/watch?v=laeOmNDE-Ac

No additional pages available.