Difference between revisions of "RaspberryPi:AdvancedConnectivity"
Line 4: | Line 4: | ||
For issues with connectivity, visit [[RaspberryPi:DebuggingConnectivity]] | For issues with connectivity, visit [[RaspberryPi:DebuggingConnectivity]] | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
= Configuring the Pi to Act as an Access Point = | = Configuring the Pi to Act as an Access Point = |
Latest revision as of 12:20, 18 August 2020
Overview[edit]
This page covers advanced connectivity options that you can use on the Raspberry Pi. While not always required, they can simplify and streamline the way you work with the Raspberry Pi.
For issues with connectivity, visit RaspberryPi:DebuggingConnectivity
Configuring the Pi to Act as an Access Point[edit]
If you are hosting a server on the Raspberry Pi, or perhaps want to create a WiFi network for guests to connect to, the Pi can act as an access point. This guide comes from https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md and https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/ and will work with a Pi that has an Ethernet Port (though it it possible to mimic an Ethernet port on a Pi 0W over USB. A Pi 0 doesn't have WiFi so this wouldn't serve any purpose).
Note that this WiFi connection will not provide internet access by bridging the Ethernet port (that’s something else entirely), but it works well for hosting services on the Pi, such as a Node-Red server.
[Show/hide]
SSH into the Pi, update, and reboot to ensure updates have taken place
$ sudo apt-get update $ sudo apt-get dist-upgrade $ sudo reboot
Wait for the Pi to reboot, and reconnect via SSH. Install hostapd and dnsmasq
$ sudo apt-get install hostapd dnsmasq
Configure a static IP in dhcpcd
$ sudo nano /etc/dhcpcd.conf
Adjust the contents so that the wireless interface is described as follows:
interface wlan0 static ip_address=192.168.4.1/24 nohook wpa_supplicant
Save and close that file, and restart the dhcp service
$ sudo systemctl restart dhcpcd
Run the following commands to create save the original dnsmasq, and create a new file which will be edited:
$ sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig $ sudo nano /etc/dnsmasq.conf
Place the following in the now open file:
interface=wlan0 listen-address=192.168.4.1 dhcp-range=192.168.4.2,192.168.4.180,255.255.255.0,24h server=8.8.8.8 domain-needed bogus-priv
Save and close the file
Restart the dnsmasq service
$ sudo systemctl reload dnsmasq
Configure hostapd. Open up the configuration file:
sudo nano /etc/hostapd/hostapd.conf
Place the following configuration in the file. Some assumptions are made about the technical aspects of it, but these are beyond the scope of this course. Note that network name and password do not have quotes around them.
interface=wlan0 driver=nl80211 ssid=TestNetwork hw_mode=g channel=7 ieee80211n=1 wmm_enabled=1 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=TestNetwork wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
Save and close the file
Next, the system needs to know where to find this configuration file. Open the configuration file:
$ sudo nano /etc/default/hostapd
Find the line with “#DAEMON_CONF” and replace it with:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Save and close this file.
Now enable and start hostapd:
$ sudo systemctl unmask hostapd $ sudo systemctl enable hostapd $ sudo systemctl start hostapd
Add routing and masquerade by opening sysctl:
$ sudo nano /etc/sysctl.conf
And uncomment this line by removing the preceding # symbol:
net.ipv4.ip_forward=1
Save and close the file
Add a masquerade, and save the iptables rule:
$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE $ sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
Edit /etc/rc.local and add this just above “exit 0” to install these rules on boot.
$ sudo nano /etc/rc.local
Place the following just above “exit 0” to install these rules on boot
iptables-restore < /etc/iptables.ipv4.nat