Last active
May 2, 2020 14:19
-
-
Save BigSully/d68982dce541ac139e39099bfd828ba2 to your computer and use it in GitHub Desktop.
Setting up a Raspberry Pi 3B plus as a routed wireless access point
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## set up the raspberry pi 3B+ as a wifi AP ( a wireless router ) | |
## suppose etho is your wan interface name, and wlan0 is your lan interface name | |
# https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md | |
# https://thepi.io/how-to-use-your-raspberry-pi-as-a-wireless-access-point/ | |
# https://www.shellvoide.com/wifi/setup-wireless-access-point-hostapd-dnsmasq-linux/ | |
## install softwares | |
apt install -y hostapd | |
apt install -y dnsmasq | |
DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent | |
# testing ps -ef | grep hostapd | |
## define wlan0 IP configuration | |
cat >> /etc/dhcpcd.conf <<EOF | |
interface wlan0 | |
static ip_address=192.168.7.1/24 | |
nohook wpa_supplicant | |
EOF | |
## enable routing between interfaces( eth0, wlan0) | |
cat >> /etc/sysctl.d/routed-ap.conf <<EOF | |
# https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md | |
# Enable IPv4 routing | |
net.ipv4.ip_forward=1 | |
EOF | |
## enable IP masquerading and save rules | |
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | |
netfilter-persistent save # Rules will be saved to /etc/iptables/ | |
## configure the DHCP and DNS services for the wireless network | |
mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig | |
cat >> /etc/dnsmasq.conf <<EOF | |
interface=wlan0 # Listening interface | |
dhcp-range=192.168.7.2,192.168.7.200,255.255.255.0,24h | |
# Pool of IP addresses served via DHCP | |
domain=wlan # Local wireless DNS domain | |
address=/gw.wlan/192.168.7.1 | |
# Alias for this router | |
EOF | |
## configure the access point | |
echo 'DAEMON_CONF="/etc/hostapd/hostapd.conf"' >> /etc/default/hostapd | |
cat >> /etc/hostapd/hostapd.conf <<EOF | |
interface=wlan0 | |
ssid=pi-ap | |
hw_mode=g | |
channel=7 | |
macaddr_acl=0 | |
auth_algs=1 | |
ignore_broadcast_ssid=0 | |
wpa=2 | |
wpa_passphrase=11112222 | |
wpa_key_mgmt=WPA-PSK | |
wpa_pairwise=TKIP | |
rsn_pairwise=CCMP | |
EOF | |
## reboot and find the AP created to test, the password of the wifi is 11112222 | |
systemctl reboot | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment