Network Configuration for a WiFi Access Point

Network Configuration for a WiFi Access Point

This page describes how to configure the network interfaces for a Raspbery Pi running as a WiFi 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. It does not include the routing, which is covered later.

We need to configure two networks, the “local” network managed by hostapd to be a WiFi Access Point (AP), and the “upstream” network connection to the internet. We will put the configuration for each interface in a separate file in the directory /etc/network/interfaces.d/ 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.1) 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.

  1. First, add the following to the top level file, /etc/network/interfaces:

    # wlan0 is the Access Point
    allow-hotplug wlan0
    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?

  2. The first wifi adapter, called wlan0, will be used for the WiFi Access Point (the local network). Put the following (or something like it) in the file /etc/network/interface.d/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

    We will come back to edit this file later.

  3. The upstream connection can be either via wired ethernet, on interface eth02 or via WiFi, 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

  1. See the file /usr/lib/dhcpcd5/dhcpcd.
  2. It may have a different name if you have enabled “predictable” network interface names
Print Friendly, PDF & Email