This page describes how to configure the network interfaces for a Raspbery Pi running as a Wi-Fi Access Point (AP). This is just one step in a larger list of instructions, which can be found on the page Raspberry Pi Wifi Access Point. The instructions here do not include the routing, which is covered later.
We need to configure two networks, the “local” network managed by hostapd to be a Wi-Fi Access Point (AP), and the “upstream” network connection to the Internet. The upstream network can be wired or Wi-Fi, and it could use a fixed IP address, or it could be a DHCP client, so there are lots of possible variations. We will use wlan0 for the Wi-Fi Access Point, since we will always have that on Wi-Fi, and use wlan1 if the upstream network connection is also via Wi-Fi.
Local Area Network (LAN) for the Access Point (AP)
The first Wi-Fi adapter, called wlan0, will be used for the Wi-Fi Access Point (the local network). It’s best to use the IP address range for a Private Network.1 For a small home network you can put the following (or something like it) in the file /etc/network/interface:
allow-hotplug wlan0 iface wlan0 inet static address 192.168.47.1 network 192.168.47.0 netmask 255.255.255.0 broadcast 192.168.47.255 gateway 192.168.47.1
This configuration is for a “Class C” network, which can have up to 254 IP addresses. For a large public event or venue you will probably want to use a class B or even a Class A network.2 In that case you can use the values in Table 1 to fill in the appropriate fields in the interfaces file.
Name | Size | address | network | netmask | broadcast | gateway |
---|---|---|---|---|---|---|
Class C | 254 | 192.168.47.1 | 192.168.147.0 | 255.255.255.0 | 192.168.47.255 | 192.168.47.1 |
Class B | 65,534 | 172.16.0.1 | 172.16.0.0 | 255.240.0.0 | 172.16.255.255 | 172.16.0.0.1 |
Class A | 16,777,214 | 10.0.0.1 | 10.0.0.0 | 255.0.0.0 | 10.255.255.255 | 10.0.0.1 |
Table 1. Private Network settings for Class C, B, and A networks. For more details on private networks see RFC 19183
Upstream Connection
There are several different ways to make the upstream connection. It can be wired or Wi-Fi, and it could have a static IP address or it could get an address and other network settings from a DHCP server.
EDITED TO HERE
We will put the configuration for each interface in a separate file in the directory to make it easier to select which upstream interface to use, and also because it allows you to be a DHCP client on the upstream link.
(If you have a static or dhcp interface in /etc/network/interfaces then the dhcp client won’t start.4) If your access point won’t act as a DHCP client (it will definitely be a server, but that is different) then you can put all the configuration into the one file /etc/network/interfaces.
First, add the following to the top level file, /etc/network/interfaces:
# wlan0 is the Access Point allow-hotplug eth0 allow-hotplug wlan1 # Now read full interface configuration from the subdirectory source-directory /etc/network/interfaces.d
That last line is what reads the other files in that subdirectory. I have found that it is important to use allow-hotplog for wlan0 instead of auto; When I used auto then hostapd could not find wlan0, though it was up later when I checked. Maybe the boot order is different?
- The upstream connection can be either via wired ethernet, on interface eth05 or via Wi-Fi, on interface wlan1. I will describe both and you can pick one or the other to connect to the Internet. It’s even possible to have both upstream links enabled at the same time — in case one fails the other will still work. You have to decide if you use DHCP (as a client) or a static the IP address and netmask and gateway.
First, put the following in the file /etc/network/interface.d/wlan1 for the second wireless interface:
iface wlan1 inet static address 192.168.1.99 network 192.168.1.0 netmask 255.255.255.0 broadcast 192.168.1.255 gateway 192.168.1.1 wpa-ssid "UpstreamSSID" wpa-psk "PassWordGoesHere" wpa-group TKIP CCMP wpa-key-mgmt WPA-PSK
Next, add the following to /etc/network/interface.d/eth0 for the wired upstream connection:
iface eth0 inet dhcp
These are just examples – you could use a static IP address for the wired interface, or use dhcp for the upstream WiFi connection. Having an entry for an interface that does not exist won’t cause problems.
Either way, we will come back to edit these files when we set up the routing tables, which
is describe in “Raspberry Pi Access Point Routing Tables.”
Notes and References
- https://en.wikipedia.org/wiki/Private_network ↩
- Cisco Networking Academy > CCNP 1: Advanced IP Addressing Management > Private Addressing and NAT. ↩
- RFC 1918: Address Allocation for Private Internets https://datatracker.ietf.org/doc/html/rfc1918 ↩
- See the file /usr/lib/dhcpcd5/dhcpcd. ↩
- It may have a different name if you have enabled “predictable” network interface names ↩