Setting up a Wifi testnetwork on Pi - HendrikVE/swp-telematik-ws-20-21 GitHub Wiki
You need to be familiar with the usage of the editor nano. If you arent, replace nano in the commands with your preferred editor.
Setup
Run the command sudo apt install dnsmasq hostapd
to install the needed packages. Edit dhcp config with sudo nano /etc/dhcpcd.conf
and insert
interface wlan0
static ip_address=192.168.1.1/24
restart dhcp daemon with sudo systemctl restart dhcpcd
, now check that ethernet interface (eth0) and wlan interface (wlan0) is available with ip l
now we configure the dhcp server. run
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf_alt
sudo nano /etc/dnsmasq.conf
and input
# DHCP-Server aktiv für WLAN-Interface
interface=wlan0
# DHCP-Server nicht aktiv für bestehendes Netzwerk
no-dhcp-interface=eth0
# IPv4-Adressbereich und Lease-Time
dhcp-range=192.168.1.100,192.168.1.200,255.255.255.0,24h
# DNS
dhcp-option=option:dns-server,192.168.1.1
now test the configuration with dnsmasq --test -C /etc/dnsmasq.conf
. it should end with ok. now run
sudo systemctl restart dnsmasq
sudo systemctl enable dnsmasq
to enable startup on system boot. run sudo nano /etc/hostapd/hostapd.conf
and input
# WLAN-Router-Betrieb
# Schnittstelle und Treiber
interface=wlan0
driver=nl80211
# WLAN-Konfiguration
ssid=Openhab_Test_Wlan
channel=1
hw_mode=g
ieee80211n=1
ieee80211d=1
ieee80211w=0
country_code=DE
wmm_enabled=1
# WLAN-Verschlüsselung
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=openhabian
change right of file with sudo chmod 600 /etc/hostapd/hostapd.conf
. start host in debug mode with sudo hostapd -dd /etc/hostapd/hostapd.conf
you can stop the instance with 'Strg + C'. Search the provided messages and check that
...
wlan0: interface state COUNTRY_UPDATE->ENABLED
...
wlan0: AP-ENABLED
...
show up. if they dont show up, restart the pi and check again. if the error persists, check if the message rfkill: WLAN soft blocked
is displayed. if it is unblock wifi with sudo rfkill unblock wlan
and try again. Afterwards close the instance and run sudo nano /etc/default/hostapd
insert here
RUN_DAEMON=yes
DAEMON_CONF="/etc/hostapd/hostapd.conf"
and start hostapd with
sudo systemctl unmask hostapd
sudo systemctl start hostapd
sudo systemctl enable hostapd
to enable the internet connection if desired run sudo nano /etc/sysctl.conf
and insert net.ipv4.ip_forward=1
. Now run
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
sudo nano /etc/rc.local"
here insert bevore the line with exit 0 iptables-restore < /etc/iptables.ipv4.nat
now reboot the pi with sudo reboot