accessp3
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.
| Beide Seiten, vorherige ÜberarbeitungVorherige ÜberarbeitungNächste Überarbeitung | Vorherige Überarbeitung | ||
| accessp3 [2017/10/16 23:43] – Externe Bearbeitung 127.0.0.1 | accessp3 [2022/03/24 22:05] (aktuell) – noone | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====Raspberry Pi als WLAN-Router einrichten (WLAN-Access-Point)==== | ||
| - | ====Using your new Raspberry Pi 3 as a WiFi access point with hostapd==== | + | ===Software installieren=== |
| - | There' | + | Es empfiehlt sich gleich am Anfang die notwendige Software zu installieren. Nicht nur die, die jetzt, sondern vielleicht auch später gebraucht wird. Während der Konfiguration kann es vorkommen, dass der Zugriff aus das Internet nicht mehr geht. Wenn dann die notwendige Software noch nicht installiert ist, dann kann man unter Umständen noch einmal von vorne anfangen. |
| + | sudo apt install dnsmasq hostapd iptables | ||
| - | One of my first thoughts was, can I use it as a SoftAP for some ESP8266 sensor nodes? As it turns out, you can, and it's not that difficult, as the BCM43438 chip is supported by the open-source brcmfmac driver! | + | **dnsmasq** ist ein DNS-Server für die Namensauflösung und ein DHCP-Server, der im WLAN die IP-Konfiguration an die WLAN-Clients verteilt.\\ |
| + | **hostapd** erzeugt das WLAN, an dem sich die WLAN-Clients anmelden können.\\ | ||
| + | **iptables** sorgt dafür, dass die WLAN-Clients per NAT eine IP-Verbindung ins nächste Netzwerk bekommen (Routing/ | ||
| - | ===Packages=== | + | ===WLAN-Interface konfigurieren=== |
| + | Seit Raspbian Jessie ist standardmäßig ein DHCP Client Daemon (DHCPCD) aktiviert. Die Netzwerk-Konfiguration wird in der Datei "/ | ||
| + | sudo nano / | ||
| - | The first step is to install the required packages: | + | Hier tragen wir folgende Zeilen ein: |
| - | sudo apt-get install dnsmasq hostapd | + | interface wlan0 |
| + | | ||
| + | | ||
| - | I'll go into a little detail about the two: | + | In dieser IPv4-Konfiguration hat das WLAN-Interface eine statische IPv4-Adresse. Das ist für den Betrieb des DHCP- und DNS-Servers wichtig. |
| - | hostapd | + | |
| - | dnsmasq | + | |
| - | If you want something a little more ' | + | Es wäre auch denkbar, auch der Ethernet-Schnittstelle " |
| - | ===Configure your interfaces=== | + | Wir speichern und schließen die Datei mit Strg + O, Return, Strg + X. |
| - | The first thing you'll need to do is to configure your wlan0 interface with a static IP. | + | |
| - | If you're connected to the Pi via WiFi, connect via ethernet/ | + | Dann starten wir den DHCP Client Daemon neu. |
| + | sudo systemctl restart dhcpcd | ||
| - | In newer Raspian versions, interface configuration is handled by dhcpcd by default. We need to tell it to ignore | + | Dann müssen wir sicherstellen, dass sowohl das Ethernet-Interface (eth0) als auch der WLAN-Adapter (wlan0) funktionieren und vorhanden sind. |
| - | sudo nano / | + | ip l |
| - | and add the following line to the bottom of the file: | + | Beide Netzwerk-Schnittstellen (eth0 und wlan0) müssen vorhanden sein. Die IP-Konfiguration ist dabei unerheblich. |
| - | | + | |
| - | Note: This must be ABOVE any interface lines you may have added! | + | ===DHCP-Server und DNS-Cache einrichten (dnsmasq)=== |
| + | Als nächstes richten wir den DHCP-Server und DNS-Cache ein. Der DHCP-Server sorgt dafür, dass die WLAN-Clients nach der Anmeldung alle nötigen Informationen für die IP-Konfiguration bekommen. Der DNS-Dienst übernimmt die Namensauflösung. Um beides kümmert sich " | ||
| - | Now we need to configure our static IP. To do this open up the interface configuration file with | + | Dazu müssen wir " |
| - | | + | |
| + | sudo nano / | ||
| - | and edit the wlan0 section so that it looks like this: | + | Dort tragen wir folgende Zeilen als Minimal-Konfiguration ein: |
| - | allow-hotplug wlan0 | + | # DHCP-Server aktiv für WLAN-Interface |
| - | iface wlan0 inet static | + | interface=wlan0 |
| - | address 172.24.1.1 | + | |
| - | | + | # DHCP-Server nicht aktiv für bestehendes Netzwerk |
| - | network 172.24.1.0 | + | |
| - | | + | |
| - | # | + | # IPv4-Adressbereich und Lease-Time |
| + | | ||
| + | | ||
| + | # | ||
| + | dhcp-option=option: | ||
| - | Restart dhcpcd with | + | Hier wird der DHCP-Server und das DNS-Forwarding für die Netzwerk-Schnittstelle " |
| - | sudo service dhcpcd restart | + | DHCP-Server und DNS-Cache prüfen und in Betrieb nehmen (dnsmasq) |
| - | and then reload the configuration for wlan0 with | + | Vor der Inbetriebnahme empfiehlt es sich, die Konfiguration zu testen. |
| - | sudo ifdown wlan0 && sudo ifup wlan0 | + | dnsmasq --test -C / |
| - | ===Configure hostapd=== | + | Die Syntaxprüfung sollte mit " |
| - | Next, we need to configure | + | DNSMASQ neu starten: |
| + | sudo systemctl restart dnsmasq | ||
| + | |||
| + | DNSMASQ-Status anzeigen: | ||
| + | sudo systemctl status dnsmasq | ||
| + | |||
| + | DNSMASQ beim Systemstart starten: | ||
| + | sudo systemctl enable dnsmasq | ||
| + | |||
| + | ===WLAN-AP-Host einrichten (hostapd)=== | ||
| + | |||
| + | Dann installieren wir den Host Access Point Daemon, kurz "hostapd". Das ist ein WLAN-Authenticator. Er kümmert sich darum, WLAN-Funktionen verschlüsselt anzubieten und die dazu notwendige Authentifizierung der WLAN-Clients vorzunehmen. | ||
| + | |||
| + | Die Konfiguration des WLAN-AP-Hosts: | ||
| sudo nano / | sudo nano / | ||
| - | with the following contents: | + | Die Datei sollte noch nicht vorhanden und somit leer sein. Wenn die Datei doch vorhanden ist, dann sollte man sie vollständig überschreiben. |
| - | # | + | In die Datei tragen wir folgende Minimal-Konfiguration ein. Selbstverständlich gibt es noch mehr Parameter, die in diesem Fall keine Rolle spielen. |
| + | # WLAN-Router-Betrieb | ||
| + | |||
| + | # | ||
| | | ||
| - | # | + | # |
| - | driver=nl80211 | + | |
| - | # | + | # |
| - | ssid=Pi3-AP | + | ssid=WLANrouter |
| - | # Use the 2.4GHz band | + | channel=1 |
| | | ||
| - | # Use channel 6 | ||
| - | | ||
| - | # Enable 802.11n | ||
| | | ||
| - | # Enable WMM | + | ieee80211d=1 |
| + | | ||
| | | ||
| - | # Enable 40MHz channels with 20ns guard interval | + | |
| - | ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] | + | # WLAN-Verschlüsselung |
| - | # Accept all MAC addresses | + | |
| - | | + | |
| - | # Use WPA authentication | + | |
| | | ||
| - | # Require clients to know the network name | ||
| - | | ||
| - | # Use WPA2 | ||
| wpa=2 | wpa=2 | ||
| - | # Use a pre-shared key | ||
| | | ||
| - | # The network passphrase | ||
| - | | ||
| - | # Use AES, instead of TKIP | ||
| | | ||
| + | | ||
| - | We can check if it's working at this stage by running | + | Drei Einstellungen sind individuell zu tätigen: Das sind der **WLAN-Name (" |
| - | sudo / | + | |
| - | If it's all gone well thus far, you should be able to see to the network Pi3-AP! If you try connecting to it, you will see some output from the Pi, but you won't receive and IP address until we set up dnsmasq in the next step. Use Ctrl+C to stop it. | + | **Hinweis zum WLAN-Treiber**: Es gibt in dieser Konfigurationsdatei den Parameter " |
| - | We aren't quite done yet, because we also need to tell hostapd | + | Anschließend speichern und schließen mit Strg + O, Return, Strg + X. |
| + | |||
| + | Weil diese Datei das WLAN-Passwort im Klartext enthält, sollte nur der Benutzer " | ||
| + | sudo chmod 600 /etc/hostapd/ | ||
| + | |||
| + | Keine Sorge, mit dem Benutzer " | ||
| + | |||
| + | ===WLAN-AP-Host-Konfiguration prüfen und in Betrieb nehmen (hostpad)=== | ||
| + | Bevor wir uns an das weitere Einrichten des WLAN-Routers machen, nehmen wir zuerst den WLAN-Host in Betrieb. Nur wenn das funktioniert, | ||
| + | |||
| + | Zur Inbetriebnahme des WLAN-Hosts starten wir " | ||
| + | sudo hostapd -dd / | ||
| + | |||
| + | **Hinweis**: | ||
| + | |||
| + | " | ||
| + | ... | ||
| + | | ||
| + | ... | ||
| + | | ||
| + | ... | ||
| + | |||
| + | Das ist eine gute Gelegenheit den WLAN-AP zu testen (ohne Internet-Verbindung). Dazu versucht man mit einem WLAN-Client das WLAN zu finden und sich dort anzumelden. | ||
| + | Dabei kann man in der Kommandozeile schön beobachten, wie sich der WLAN-Client anmeldet (AP-STA-CONNECTED) und auch wieder abmeldet (AP-STA-DISCONNECTED), | ||
| + | |||
| + | **Hinweis**: | ||
| + | |||
| + | Wenn " | ||
| + | |||
| + | * Ein beliebter Fehler ist das fehlende " | ||
| + | * Weitere Fehlerquellen kann man ausschließen, | ||
| + | * Eine weitere Fehlerquelle ist die verwendete Distribution. Funktionieren wird es auf alle Fälle mit Raspberry Pi OS. | ||
| + | |||
| + | Damit der " | ||
| + | Wenn " | ||
| sudo nano / | sudo nano / | ||
| - | and find the line # | + | Darin ergänzen wir folgende Parameter: |
| + | | ||
| | | ||
| - | ===Configure dnsmasq=== | + | Anschließend speichern und schließen mit Strg + O, Return, Strg + X. |
| - | The shipped dnsmasq config file contains a wealth of information on how to use it, but the majority of it is largely redundant for our purposes. I'd advise moving it (rather than deleting it), and creating a new one with | + | |
| - | sudo mv / | + | |
| - | sudo nano / | + | |
| - | Paste the following into the new file: | + | Den " |
| - | | + | sudo systemctl unmask hostapd |
| - | | + | sudo systemctl start hostapd |
| - | bind-interfaces | + | sudo systemctl enable hostapd |
| - | server=8.8.8.8 | + | |
| - | domain-needed | + | |
| - | | + | |
| - | | + | |
| - | ===Set up IPv4 forwarding=== | + | Den Status des Daemons kann man mit folgendem Kommando prüfen. |
| - | One of the last things that we need to do before we send traffic anywhere is to enable packet forwarding. | + | sudo systemctl status hostapd |
| - | To do this, open up the sysctl.conf file with | + | Hier sollten folgende Zeilen stehen: Loaded: loaded und Active: active |
| + | |||
| + | ===Routing und NAT für die Internet-Verbindung konfigurieren=== | ||
| + | Bis hierhin hat man im Optimalfall mit de WLAN-Client eine Verbindung zum WLAN und eine IPv4-Konfiguration erhalten. Was noch nicht funktioniert, ist eine Verbindung ins Internet. | ||
| + | |||
| + | Zuerst aktivieren wir das Routing. Dazu öffnen wir eine System-Datei. | ||
| sudo nano / | sudo nano / | ||
| - | and remove the # from the beginning of the line containing net.ipv4.ip_forward=1. This will enable it on the next reboot, but because we are impatient, activate it immediately with: | ||
| - | sudo sh -c "echo 1 > / | ||
| - | We also need to share our Pi's internet connection to our devices connected over WiFi by the configuring a NAT between our wlan0 interface and our eth0 interface. We can do this using the following commands: | + | Hier ergänzen wir die folgende Zeile und schließen die Datei mit Strg + O, Return, Strg + X. |
| + | | ||
| + | |||
| + | Dann aktivieren wir NAT. Wichtig ist hier, dass iptables installiert ist. | ||
| sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | ||
| - | sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED, | ||
| - | sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT | ||
| - | However, we need these rules to be applied every time we reboot the Pi, so run | + | Dann stellen wir sicher, dass diese Routing-Information gespeichert wird. |
| sudo sh -c " | sudo sh -c " | ||
| - | to save the rules to the file / | + | Damit die Routing-Information beim Systemstart geladen wird müssen wir noch ein Systemdatei bearbeiten. |
| sudo nano / | sudo nano / | ||
| - | and just above the line exit 0, add the following line: | + | Hier tragen wir vor der Zeilte mit "exit 0" folgende Zeile ein. |
| - | | + | |
| - | We're almost there! | + | Anschließend muss man die Datei speichern und schließen: Strg + O, Return, Strg + X. |
| - | Now we just need to start our services: | + | Ein Neustart des Raspberry Pi ist abschließend erforderlich. |
| + | sudo reboot | ||
| - | sudo service hostapd start | + | ===WLAN-, Router- und DHCP/ |
| - | sudo service dnsmasq start | + | |
| - | And that's it! You should now be able to connect to the internet through your Pi, via the on-board WiFi! | + | Wenn der Raspberry |
| - | + | sudo systemctl status hostapd | |
| - | To double check we have got everything configured correctly, reboot with | + | ps ax | grep hostapd |
| - | | + | |
| + | ps ax | grep dnsmasq | ||
| + | Wenn die Dienste laufen und die Prozesse für die beiden Dienste angezeigt werden, dann kann man versuchen sich mit einem WLAN-Client am WLAN-Router anzumelden und eine Internet-Verbindung aufzubauen. | ||
accessp3.1508190217.txt.gz · Zuletzt geändert: 2017/10/16 23:43 von 127.0.0.1
