Skip to content

Commit c3036cc

Browse files
rbisewskiJamesH65
authored andcommitted
Modernize access-point.md documentation (#1009)
* adjust Access Point md file to use newer commands * explaining new systemd commands for creating a bridge * V minor changes in copy-edit Substituted colon, end of line 228 "an ADSL router" not "a ADSL router", line 300
1 parent 335bdfe commit c3036cc

File tree

1 file changed

+112
-23
lines changed

1 file changed

+112
-23
lines changed

configuration/wireless/access-point.md

Lines changed: 112 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,65 @@ Before proceeding, please ensure your Raspberry Pi is [up to date](../../raspbia
22

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

5-
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.
5+
6+
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.
67

78
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.
89

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

11-
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).
12+
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.
13+
14+
Use the following to update your Raspbian installation:
15+
16+
```
17+
sudo apt update
18+
sudo apt upgrade
19+
sudo dist-upgrade
20+
```
21+
22+
If an updated kernel was installed, consider rebooting:
23+
24+
```
25+
sudo reboot
26+
```
1227

13-
Install the required software (dnsmasq and hostapd) with this command:
28+
To create an access point, we'll need DNSMasq and HostAPD. Install all the required software in one go with this command:
1429

1530
```
1631
sudo apt install dnsmasq hostapd
1732
```
1833

34+
Since the configuration files are not ready yet, turn the new software off as follows:
35+
36+
```
37+
sudo systemctl stop dnsmasq
38+
sudo systemctl stop hostapd
39+
```
40+
1941
## Configuring a static IP
2042

2143
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`.
2244

23-
To configure the static IP address, open the dhcpcd configuration file with the following command:
45+
46+
To configure the static IP address, edit the dhcpcd configuration file with:
47+
2448
```
2549
sudo nano /etc/dhcpcd.conf
2650
```
51+
2752
Go to the end of the file and edit it so that it looks like the following:
53+
2854
```
2955
interface wlan0
3056
static ip_address=192.168.4.1/24
3157
nohook wpa_supplicant
32-
3358
```
34-
Now restart the `dhcpcd` daemon:
59+
60+
Now restart the dhcpcd daemon and set up the new `wlan0` configuration:
61+
3562
```
36-
sudo systemctl restart dhcpcd
63+
sudo service dhcpcd restart
3764
```
3865

3966
## Configuring the DHCP server (dnsmasq)
@@ -116,26 +143,41 @@ sudo systemctl unmask hostapd
116143
sudo systemctl enable hostapd
117144
sudo systemctl start hostapd
118145
```
146+
147+
Do a quick check of their status to ensure they are active and running:
148+
149+
```
150+
sudo systemctl status hostapd
151+
sudo systemctl status dnsmasq
152+
```
153+
119154
### Add routing and masquerade
120155

121156
Edit /etc/sysctl.conf and uncomment this line:
157+
122158
```
123159
net.ipv4.ip_forward=1
124160
```
125161

126162
Add a masquerade for outbound traffic on eth0:
163+
127164
```
128165
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
129166
```
167+
130168
Save the iptables rule.
169+
131170
```
132171
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
133172
```
134173

135174
Edit /etc/rc.local and add this just above "exit 0" to install these rules on boot.
175+
136176
```
137177
iptables-restore < /etc/iptables.ipv4.nat
138178
```
179+
Reboot and ensure it still functions.
180+
139181
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.
140182

141183
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:
@@ -146,8 +188,6 @@ ssh [email protected]
146188

147189
By this point, the Raspberry Pi is acting as an access point, and other devices can associate with it. Associated devices can access the Raspberry Pi access point via its IP address for operations such as `rsync`, `scp`, or `ssh`.
148190

149-
## ----------------------------------------------------------------------------------
150-
<a name="internet-sharing"></a>
151191
## Using the Raspberry Pi as an access point to share an internet connection (bridge)
152192

153193
One common use of the Raspberry Pi as an access point is to provide wireless connections to a wired Ethernet connection, so that anyone logged into the access point can access the internet, providing of course that the wired Ethernet on the Pi can connect to the internet via some sort of router.
@@ -158,6 +198,11 @@ To do this, a 'bridge' needs to put in place between the wireless device and the
158198
sudo apt install hostapd bridge-utils
159199
```
160200

201+
Since the configuration files are not ready yet, turn the new software off as follows:
202+
203+
```
204+
sudo systemctl stop hostapd
205+
```
161206
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.
162207

163208
```
@@ -166,30 +211,69 @@ sudo nano /etc/dhcpcd.conf
166211

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

169-
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.
214+
Add a new bridge, which in this case is called `br0`.
215+
216+
```
217+
sudo brctl addbr br0
218+
```
219+
220+
Connect the network ports. In this case, connect `eth0` to the bridge `br0`.
221+
222+
```
223+
sudo brctl addif br0 eth0
224+
```
225+
226+
Now the interfaces file needs to be edited to adjust the various devices to work with bridging. To make this work with the newer systemd configuration options, you'll need to create a set of network configuration files.
170227

171-
Add the bridging information at the end of the file.
228+
If you want to create a Linux bridge (br0) and add a physical interface (eth0) to the bridge, create the following configuration.
229+
230+
```
231+
sudo nano /etc/systemd/network/bridge-br0.netdev
172232
233+
[NetDev]
234+
Name=br0
235+
Kind=bridge
173236
```
174-
# Bridge setup
175-
auto br0
176-
iface br0 inet manual
177-
bridge_ports eth0 wlan0
237+
238+
Then configure the bridge interface br0 and the slave interface eth0 using .network files as follows:
239+
178240
```
241+
sudo nano /etc/systemd/network/bridge-br0-slave.network
179242
180-
Bring up the new `br0` interface and restart `dhcpcd` for the changes to take effect:
243+
[Match]
244+
Name=eth0
245+
246+
[Network]
247+
Bridge=br0
181248
```
182-
sudo ifup br0
183-
sudo systemctl restart dhcpcd
249+
184250
```
251+
sudo nano /etc/systemd/network/bridge-br0.network
185252
186-
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.
253+
[Match]
254+
Name=br0
255+
256+
[Network]
257+
Address=192.168.10.100/24
258+
Gateway=192.168.10.1
259+
DNS=8.8.8.8
260+
```
261+
262+
Finally, restart systemd-networkd:
263+
264+
```
265+
sudo systemctl restart systemd-networkd
266+
```
267+
268+
You can also use the brctl tool to verify that a bridge br0 has been created.
269+
270+
The access point setup is almost the same as that shown in the previous section. Follow the instructions above to set up the `hostapd.conf` file, 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.
187271

188272
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:
189273
- a = IEEE 802.11a (5 GHz)
190274
- b = IEEE 802.11b (2.4 GHz)
191275
- g = IEEE 802.11g (2.4 GHz)
192-
- ad = IEEE 802.11ad (60 GHz). Not available on Raspberry Pi.
276+
- ad = IEEE 802.11ad (60 GHz)
193277

194278
```
195279
interface=wlan0
@@ -209,9 +293,8 @@ wpa_pairwise=TKIP
209293
rsn_pairwise=CCMP
210294
```
211295

212-
## Start it up
296+
Now reboot the Raspberry Pi.
213297

214-
Now enable and start `hostapd`:
215298
```
216299
sudo systemctl unmask hostapd
217300
sudo systemctl enable hostapd
@@ -220,4 +303,10 @@ sudo systemctl start hostapd
220303

221304
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.
222305

223-
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.
306+
The bridge will have been allocated an IP address via the wired Ethernet's DHCP server. Do a quick check of the network interfaces configuration via:
307+
308+
```
309+
ip addr
310+
```
311+
312+
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 an ADSL router, the DHCP address will be fine.

0 commit comments

Comments
 (0)