Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update WLAN AP documentation #1097

Merged
merged 2 commits into from
Apr 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 34 additions & 51 deletions configuration/wireless/access-point.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,26 @@
Before proceeding, please ensure your Raspberry Pi is [up to date](../../raspbian/updating.md) and rebooted.

# Setting up a Raspberry Pi as an access point in a standalone network (NAT)

The Raspberry Pi can be used as a wireless access point, running a standalone network. This can be done using the inbuilt wireless features of the Raspberry Pi 3 or Raspberry Pi Zero W, or by using a suitable USB wireless dongle that supports access points.
The Raspberry Pi can be used as a wireless access point running a standalone network. To do this, you need either a Raspberry Pi 3 or Raspberry Pi Zero W (which have inbuilt wireless LAN functionality), or another Pi model with a suitable USB wireless dongle that supports access points.

Note that this documentation was tested on a Raspberry Pi 3, and it is possible that some USB dongles may need slight changes to their settings. If you are having trouble with a USB wireless dongle, please check the forums.

To add a Raspberry Pi-based access point to an existing network, see [this section](#internet-sharing).

In order to work as an access point, the Raspberry Pi will need to have access point software installed, along with DHCP server software to provide connecting devices with a network address. Ensure that your Raspberry Pi is using an up-to-date version of Raspbian (dated 2017 or later).

Use the following to update your Raspbian installation:
```
sudo apt-get update
sudo apt-get upgrade
```
Install all the required software in one go with this command:
```
sudo apt-get install dnsmasq hostapd
```
Since the configuration files are not ready yet, turn the new software off as follows:
```
sudo systemctl stop dnsmasq
sudo systemctl stop hostapd
```
Install the required software (dnsmasq and hostapd) with this command:

To ensure that an updated kernel is configured correctly after install, reboot:
```
sudo reboot
sudo apt install dnsmasq hostapd
```

## Configuring a static IP

We are configuring a standalone network to act as a server, so the Raspberry Pi needs to have a static IP address assigned to the wireless port. This documentation assumes that we are using the standard 192.168.x.x IP addresses for our wireless network, so we will assign the server the IP address 192.168.4.1. It is also assumed that the wireless device being used is `wlan0`.

To configure the static IP address, edit the dhcpcd configuration file with:
To configure the static IP address, open the dhcpcd configuration file with the following command:
```
sudo nano /etc/dhcpcd.conf
```
Expand All @@ -43,32 +31,37 @@ interface wlan0
nohook wpa_supplicant
```
Now restart the dhcpcd daemon and set up the new `wlan0` configuration:
Now restart the `dhcpcd` daemon:
```
sudo service dhcpcd restart
sudo systemctl restart dhcpcd
```

## Configuring the DHCP server (dnsmasq)

The DHCP service is provided by dnsmasq. By default, the configuration file contains a lot of information that is not needed, and it is easier to start from scratch. Rename this configuration file, and edit a new one:

```
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf
```

Type or copy the following information into the dnsmasq configuration file and save it:

```
interface=wlan0 # Use the require wireless interface - usually wlan0
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
```

So for `wlan0`, we are going to provide IP addresses between 192.168.4.2 and 192.168.4.20, with a lease time of 24 hours. If you are providing DHCP services for other network devices (e.g. eth0), you could add more sections with the appropriate interface header, with the range of addresses you intend to provide to that interface.

There are many more options for dnsmasq; see the [dnsmasq documentation](http://www.thekelleys.org.uk/dnsmasq/doc.html) for more details.

Reload `dnsmasq` to use the updated configuration:
```
sudo systemctl reload dnsmasq
```

<a name="hostapd-config"></a>
## Configuring the access point host software (hostapd)

You need to edit the hostapd configuration file, located at /etc/hostapd/hostapd.conf, to add the various parameters for your wireless network. After initial install, this will be a new/empty file.
Expand All @@ -83,7 +76,7 @@ To use the 5 GHz band, you can change the operations mode from hw_mode=g to hw_m
- a = IEEE 802.11a (5 GHz)
- b = IEEE 802.11b (2.4 GHz)
- g = IEEE 802.11g (2.4 GHz)
- ad = IEEE 802.11ad (60 GHz).
- ad = IEEE 802.11ad (60 GHz)

```
interface=wlan0
Expand Down Expand Up @@ -116,11 +109,12 @@ DAEMON_CONF="/etc/hostapd/hostapd.conf"

## Start it up

Now start up the remaining services:
Now enable and start `hostapd`:

```
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
sudo systemctl start dnsmasq
```
### Add routing and masquerade

Expand All @@ -142,8 +136,6 @@ Edit /etc/rc.local and add this just above "exit 0" to install these rules on bo
```
iptables-restore < /etc/iptables.ipv4.nat
```
Reboot

Using a wireless device, search for networks. The network SSID you specified in the hostapd configuration should now be present, and it should be accessible with the specified password.

If SSH is enabled on the Raspberry Pi access point, it should be possible to connect to it from another Linux box (or a system with SSH connectivity present) as follows, assuming the `pi` account is present:
Expand All @@ -163,14 +155,9 @@ One common use of the Raspberry Pi as an access point is to provide wireless con
To do this, a 'bridge' needs to put in place between the wireless device and the Ethernet device on the access point Raspberry Pi. This bridge will pass all traffic between the two interfaces. Install the following packages to enable the access point setup and bridging.

```
sudo apt-get install hostapd bridge-utils
sudo apt install hostapd bridge-utils
```

Since the configuration files are not ready yet, turn the new software off as follows:

```
sudo systemctl stop hostapd
```
Bridging creates a higher-level construct over the two ports being bridged. It is the bridge that is the network device, so we need to stop the `eth0` and `wlan0` ports being allocated IP addresses by the DHCP client on the Raspberry Pi.

```
Expand All @@ -179,18 +166,6 @@ sudo nano /etc/dhcpcd.conf

Add `denyinterfaces wlan0` and `denyinterfaces eth0` to the end of the file (but above any other added `interface` lines) and save the file.

Add a new bridge, which in this case is called `br0`.

```
sudo brctl addbr br0
```

Connect the network ports. In this case, connect `eth0` to the bridge `br0`.

```
sudo brctl addif br0 eth0
```

Now the interfaces file needs to be edited to adjust the various devices to work with bridging. `sudo nano /etc/network/interfaces` make the following edits.

Add the bridging information at the end of the file.
Expand All @@ -200,10 +175,15 @@ Add the bridging information at the end of the file.
auto br0
iface br0 inet manual
bridge_ports eth0 wlan0
```

```
Bring up the new `br0` interface and restart `dhcpcd` for the changes to take effect:
```
sudo ifup br0
sudo systemctl restart dhcpcd
```

The access point setup is almost the same as that shown in the previous section. Follow *all* the instructions in the `Configuring the access point host software (hostapd)` section above to set up the `hostapd.conf` file and the system location, but add `bridge=br0` below the `interface=wlan0` line, and remove or comment out the driver line. The passphrase must be between 8 and 64 characters long.
The access point setup is almost the same as that shown in the previous section. Follow **all** the instructions in the [Configuring the access point host software (hostapd)](#hostapd-config) section above to set up the `hostapd.conf` file and the system location, **but** add `bridge=br0` below the `interface=wlan0` line, and remove or comment out the driver line. The passphrase must be between 8 and 64 characters long.

To use the 5 GHz band, you can change the operations mode from 'hw_mode=g' to 'hw_mode=a'. The possible values for hw_mode are:
- a = IEEE 802.11a (5 GHz)
Expand All @@ -229,12 +209,15 @@ wpa_pairwise=TKIP
rsn_pairwise=CCMP
```

Now reboot the Raspberry Pi.
## Start it up

Now enable and start `hostapd`:
```
sudo reboot
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
```

There should now be a functioning bridge between the wireless LAN and the Ethernet connection on the Raspberry Pi, and any device associated with the Raspberry Pi access point will act as if it is connected to the access point's wired Ethernet.

The `ifconfig` command will show the bridge, which will have been allocated an IP address via the wired Ethernet's DHCP server. The `wlan0` and `eth0` no longer have IP addresses, as they are now controlled by the bridge. It is possible to use a static IP address for the bridge if required, but generally, if the Raspberry Pi access point is connected to a ADSL router, the DHCP address will be fine.