You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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
@@ -2,38 +2,65 @@ Before proceeding, please ensure your Raspberry Pi is [up to date](../../raspbia
2
2
3
3
# Setting up a Raspberry Pi as an access point in a standalone network (NAT)
4
4
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.
6
7
7
8
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.
8
9
9
10
To add a Raspberry Pi-based access point to an existing network, see [this section](#internet-sharing).
10
11
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
+
```
12
27
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:
14
29
15
30
```
16
31
sudo apt install dnsmasq hostapd
17
32
```
18
33
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
+
19
41
## Configuring a static IP
20
42
21
43
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`.
22
44
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
+
24
48
```
25
49
sudo nano /etc/dhcpcd.conf
26
50
```
51
+
27
52
Go to the end of the file and edit it so that it looks like the following:
53
+
28
54
```
29
55
interface wlan0
30
56
static ip_address=192.168.4.1/24
31
57
nohook wpa_supplicant
32
-
33
58
```
34
-
Now restart the `dhcpcd` daemon:
59
+
60
+
Now restart the dhcpcd daemon and set up the new `wlan0` configuration:
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
+
119
154
### Add routing and masquerade
120
155
121
156
Edit /etc/sysctl.conf and uncomment this line:
157
+
122
158
```
123
159
net.ipv4.ip_forward=1
124
160
```
125
161
126
162
Add a masquerade for outbound traffic on eth0:
163
+
127
164
```
128
165
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
129
166
```
167
+
130
168
Save the iptables rule.
169
+
131
170
```
132
171
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
133
172
```
134
173
135
174
Edit /etc/rc.local and add this just above "exit 0" to install these rules on boot.
175
+
136
176
```
137
177
iptables-restore < /etc/iptables.ipv4.nat
138
178
```
179
+
Reboot and ensure it still functions.
180
+
139
181
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.
140
182
141
183
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:
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`.
## Using the Raspberry Pi as an access point to share an internet connection (bridge)
152
192
153
193
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
158
198
sudo apt install hostapd bridge-utils
159
199
```
160
200
201
+
Since the configuration files are not ready yet, turn the new software off as follows:
202
+
203
+
```
204
+
sudo systemctl stop hostapd
205
+
```
161
206
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.
162
207
163
208
```
@@ -166,30 +211,69 @@ sudo nano /etc/dhcpcd.conf
166
211
167
212
Add `denyinterfaces wlan0` and `denyinterfaces eth0` to the end of the file (but above any other added `interface` lines) and save the file.
168
213
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.
170
227
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
172
232
233
+
[NetDev]
234
+
Name=br0
235
+
Kind=bridge
173
236
```
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:
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
181
248
```
182
-
sudo ifup br0
183
-
sudo systemctl restart dhcpcd
249
+
184
250
```
251
+
sudo nano /etc/systemd/network/bridge-br0.network
185
252
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.
187
271
188
272
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:
189
273
- a = IEEE 802.11a (5 GHz)
190
274
- b = IEEE 802.11b (2.4 GHz)
191
275
- 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)
193
277
194
278
```
195
279
interface=wlan0
@@ -209,9 +293,8 @@ wpa_pairwise=TKIP
209
293
rsn_pairwise=CCMP
210
294
```
211
295
212
-
## Start it up
296
+
Now reboot the Raspberry Pi.
213
297
214
-
Now enable and start `hostapd`:
215
298
```
216
299
sudo systemctl unmask hostapd
217
300
sudo systemctl enable hostapd
@@ -220,4 +303,10 @@ sudo systemctl start hostapd
220
303
221
304
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.
222
305
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