Benutzer-Werkzeuge

Webseiten-Werkzeuge


accessp3

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen der Seite angezeigt.

Link zu der Vergleichsansicht

Beide Seiten, vorherige ÜberarbeitungVorherige Überarbeitung
Nächste Überarbeitung
Vorherige Überarbeitung
accessp3 [2017/10/16 23:43] – Externe Bearbeitung 127.0.0.1accessp3 [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's a new Raspberry PiThis is excitingIt also has on-board WiFiThis makes it doubly exciting!+Es empfiehlt sich gleich am Anfang die notwendige Software zu installierenNicht nur die, die jetzt, sondern vielleicht auch später gebraucht wirdWährend der Konfiguration kann es vorkommen, dass der Zugriff aus das Internet nicht mehr gehtWenn 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 wascan I use it as a SoftAP for some ESP8266 sensor nodes? As it turns outyou canand 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-Serverder im WLAN die IP-Konfiguration an die WLAN-Clients verteilt.\\  
 +**hostapd** erzeugt das WLANan dem sich die WLAN-Clients anmelden können.\\  
 +**iptables** sorgt dafürdass die WLAN-Clients per NAT eine IP-Verbindung ins nächste Netzwerk bekommen (Routing/Firewalling).
  
-===Packages===+===WLAN-Interface konfigurieren=== 
 +Seit Raspbian Jessie ist standardmäßig ein DHCP Client Daemon (DHCPCD) aktiviert. Die Netzwerk-Konfiguration wird in der Datei "/etc/dhcpcd.conf" vorgenommen. 
 +   sudo nano /etc/dhcpcd.conf
  
-The first step is to install the required packages+Hier tragen wir folgende Zeilen ein
-   sudo apt-get install dnsmasq hostapd+   interface wlan0 
 +   static ip_address=192.168.1.1/24 
 +   nohook wpa_supplicant
  
-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 This is the package that allows you to use the built in WiFi as an access point +
-dnsmasq This is a combined DHCP and DNS server that's very easy to configure+
  
-If you want something a little more 'heavyweight'you can use the isc-dhcp-server and bind9 packages for DHCP and DNS respectivelybut for our purposesdnsmasq works just fine.+Es wäre auch denkbarauch der Ethernet-Schnittstelle "eth0" eine statische IP-Konfiguration zu verpassen. Das muss aber nicht sein. In dieser Form hat der WLAN-Router den Vorteildass er in jedem lokalen Netzwerk funktioniertwenn die IPv4-Konfiguration per DHCP an die Ethernet-Schnittstelle geliefert wird.
  
-===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/serial/keyboard first.+Dann starten wir den DHCP Client Daemon neu. 
 +   sudo systemctl restart dhcpcd
  
-In newer Raspian versionsinterface configuration is handled by dhcpcd by default. We need to tell it to ignore wlan0, as we will be configuring it with a static IP address elsewhereSo open up the dhcpcd configuration file with +Dann müssen wir sicherstellendass sowohl das Ethernet-Interface (eth0) als auch der WLAN-Adapter (wlan0) funktionieren und vorhanden sind
-   sudo nano /etc/dhcpcd.conf+   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.
-   denyinterfaces wlan0  +
  
-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 "dnsmasq".
  
-Now we need to configure our static IPTo do this open up the interface configuration file with +Dazu müssen wir "dnsmasq" konfigurieren. Wir erstellen zuerst ein Backup der alten Konfigurationsdatei und öffnen eine neue Datei "/etc/dnsmasq.conf"
-   sudo nano /etc/network/interfaces+   sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf_alt 
 +   sudo nano /etc/dnsmasq.conf
  
-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 +    
-     netmask 255.255.255.0 +   # DHCP-Server nicht aktiv für bestehendes Netzwerk 
-     network 172.24.1.0 +   no-dhcp-interface=eth0 
-     broadcast 172.24.1.255 +    
-   #    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf+   # 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
  
-Restart dhcpcd with +Hier wird der DHCP-Server und das DNS-Forwarding für die Netzwerk-Schnittstelle "wlan0" aktiviert und für die Schnittstelle "eth0" nur DNS, aber kein DHCP serviert. Außerdem wird festgelegt, dass im WLAN die IPv4-Adressen von 192.168.1.100 bis 192.168.1.200 für die Clients vergeben werden und die Adresse des DNS-Servers festgelegt. 
-   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 /etc/dnsmasq.conf
  
-===Configure hostapd===+Die Syntaxprüfung sollte mit "OK" erfolgreich sein.
  
-Nextwe need to configure hostapd. Create a new configuration file with+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 Daemonkurz "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 /etc/hostapd/hostapd.conf    sudo nano /etc/hostapd/hostapd.conf
  
-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. 
-   # This is the name of the WiFi interface we configured above+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 
 +    
 +   # Schnittstelle und Treiber
    interface=wlan0    interface=wlan0
-   # Use the nl80211 driver with the brcmfmac driver +   #driver=nl80211 
-   driver=nl80211 +    
-   # This is the name of the network +   # WLAN-Konfiguration 
-   ssid=Pi3-AP +   ssid=WLANrouter 
-   # Use the 2.4GHz band+   channel=1
    hw_mode=g    hw_mode=g
-   # Use channel 6 
-   channel=6 
-   # Enable 802.11n 
    ieee80211n=1    ieee80211n=1
-   # Enable WMM+   ieee80211d=1 
 +   country_code=DE
    wmm_enabled=1    wmm_enabled=1
-   # Enable 40MHz channels with 20ns guard interval +    
-   ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] +   # WLAN-Verschlüsselung
-   # Accept all MAC addresses +
-   macaddr_acl=0 +
-   # Use WPA authentication+
    auth_algs=1    auth_algs=1
-   # Require clients to know the network name 
-   ignore_broadcast_ssid=0 
-   # Use WPA2 
    wpa=2    wpa=2
-   # Use a pre-shared key 
    wpa_key_mgmt=WPA-PSK    wpa_key_mgmt=WPA-PSK
-   # The network passphrase 
-   wpa_passphrase=raspberry 
-   # Use AES, instead of TKIP 
    rsn_pairwise=CCMP    rsn_pairwise=CCMP
 +   wpa_passphrase=testtest
  
-We can check if it's working at this stage by running +Drei Einstellungen sind individuell zu tätigen: Das sind der **WLAN-Name ("ssid")**, der **Kanal ("channel")**, der von 1 bis 13 frei konfiguriert werden kann, wobei man hier nichts ändern muss. Eventuell muss man hier den Kanal wechseln, wenn eine WLAN-Analyse ergibt, dass bereits mehrere andere WLANs diesen Kanal belegen. Prinzipiell können mehrere WLANs den selben Kanal belegen. Das ist besser, als wenn sich die Kanäle überschneiden. Der dritte Parameter ist das **WLAN-Passwort ("wpa_passphrase")**. Hier sollte man ein Passwort von mindestens 8 Zeichen Länge im Klartext eintragen.
-   sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf+
  
-If it's all gone well thus far, you should be able to see to the network Pi3-AP! If you try connecting to ityou will see some output from the Pibut you won't receive and IP address until we set up dnsmasq in the next stepUse Ctrl+C to stop it.+**Hinweis zum WLAN-Treiber**: Es gibt in dieser Konfigurationsdatei den Parameter "driver"der auskommentiert (#) ist. Normalerweise wird von "hostapd" automatisch der richtige Treiber geladen. Es kann natürlich seindass das nicht gelingtDann muss man hier den richtigen Treiber explizit angeben.
  
-We aren't quite done yetbecause we also need to tell hostapd where to look for the config file when it starts up on bootOpen up the default configuration file with+Anschließend speichern und schließen mit Strg + OReturn, Strg + X. 
 + 
 +Weil diese Datei das WLAN-Passwort im Klartext enthält, sollte nur der Benutzer "root" Leserechte auf diese Datei haben. 
 +   sudo chmod 600 /etc/hostapd/hostapd.conf 
 + 
 +Keine Sorge, mit dem Benutzer "pi" kann man die Datei jederzeit wieder ändern und speichern. 
 + 
 +===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, lohnen sich die weiteren Schritte. Wenn der WLAN-Host nicht in Betrieb geht, braucht man die Router-Funktionen gar nicht erst einzurichten. 
 + 
 +Zur Inbetriebnahme des WLAN-Hosts starten wir "hostapd" im Debug-Modus. Dabei werden uns alle Fehlermeldungen angezeigt. 
 +   sudo hostapd -dd /etc/hostapd/hostapd.conf 
 + 
 +**Hinweis**: Mit "Strg + C" kann man die laufende hostapd-Instanz bei Bedarf beenden. 
 + 
 +"hostapd" wird in jedem Fall Meldungen produzieren. Sofern die Konfiguration richtig ist und der WLAN-Adapter mitspielt, läuft die Konfiguration durch. Das Programm wird aber nicht beendet. Das heißt, "hostapd" kehrt nicht zur Befehlseingabe zurück. Wenn folgende Meldungen erscheinen, dann ist alles im grünen Bereich: 
 +   ... 
 +   wlan0: interface state COUNTRY_UPDATE->ENABLED 
 +   ... 
 +   wlan0: AP-ENABLED 
 +   ... 
 + 
 +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), wenn er die Verbindung zum WLAN beendet. 
 + 
 +**Hinweis**: Wenn man die Konfiguration per SSH vornimmt, dann sollte man das Prüfen des WLAN-AP mit einem anderen Client vornehmen, weil man sich sonst durch das Wechseln des WLANs die SSH-Verbindung abschießt. 
 + 
 +Wenn "hostapd" mit Fehlermeldungen abbricht und zur Kommandoeingabe zurückkehrt, dann stimmt irgendetwas noch nicht. Die Fehler sind allerdings äußerst vielfältig und die dazugehörigen Fehlermeldungen nicht immer eindeutig. 
 + 
 +   * Ein beliebter Fehler ist das fehlende "sudo" beim Aufrufen von "hostapd"
 +   * Weitere Fehlerquellen kann man ausschließen, wenn man sicherstellt, dass der WLAN-Adapter grundsätzlich funktioniert und den AP-Modus beherrscht. 
 +   * Eine weitere Fehlerquelle ist die verwendete Distribution. Funktionieren wird es auf alle Fälle mit Raspberry Pi OS. 
 + 
 +Damit der "hostapd" als Daemon im Hintergrund startet, muss man dem Daemon noch sagen, wo er seine Konfiguration (Datei) findet. 
 +Wenn "hostapd" noch läuft, dann beenden wir es mit "Strg + C"Dann öffnen wir eine Konfigurationsdatei:
    sudo nano /etc/default/hostapd    sudo nano /etc/default/hostapd
  
-and find the line #DAEMON_CONF="" and replace it with+Darin ergänzen wir folgende Parameter: 
 +   RUN_DAEMON=yes
    DAEMON_CONF="/etc/hostapd/hostapd.conf"    DAEMON_CONF="/etc/hostapd/hostapd.conf"
  
-===Configure dnsmasq=== +Anschließend speichern und schließen mit Strg + OReturnStrg + X.
-The shipped dnsmasq config file contains a wealth of information on how to use itbut 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 /etc/dnsmasq.conf /etc/dnsmasq.conf.orig +
-   sudo nano /etc/dnsmasq.conf  +
  
-Paste the following into the new file: +Den "hostapd" nimmt man dann mit folgenden Kommandos in Betrieb
-   interface=wlan0      # Use interface wlan0   +   sudo systemctl unmask hostapd 
-   listen-address=172.24.1.1 # Explicitly specify the address to listen on   +   sudo systemctl start hostapd 
-   bind-interfaces      # Bind to the interface to make sure we aren't sending things elsewhere   +   sudo systemctl enable hostapd
-   server=8.8.8.8       # Forward DNS requests to Google DNS   +
-   domain-needed        # Don't forward short names   +
-   bogus-priv           # Never forward addresses in the non-routed address spaces.   +
-   dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time+
  
-===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 thisopen 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 funktioniertist eine Verbindung ins Internet. 
 + 
 +Zuerst aktivieren wir das Routing. Dazu öffnen wir eine System-Datei.
    sudo nano /etc/sysctl.conf    sudo nano /etc/sysctl.conf
-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 > /proc/sys/net/ipv4/ip_forward" 
  
-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 interfaceWe 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. 
 +   net.ipv4.ip_forward=1 
 + 
 +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,ESTABLISHED -j ACCEPT 
-   sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT 
  
-Howeverwe need these rules to be applied every time we reboot the Pi, so run+Dann stellen wir sicherdass diese Routing-Information gespeichert wird.
    sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"    sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
  
-to save the rules to the file /etc/iptables.ipv4.nat. Now we need to run this after each reboot, so open the rc.local file with+Damit die Routing-Information beim Systemstart geladen wird müssen wir noch ein Systemdatei bearbeiten.
    sudo nano /etc/rc.local    sudo nano /etc/rc.local
  
-and just above the line exit 0, add the following line: +Hier tragen wir vor der Zeilte mit "exit 0" folgende Zeile ein. 
-   iptables-restore < /etc/iptables.ipv4.nat  +   iptables-restore < /etc/iptables.ipv4.nat
  
-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/DNS-Funktion prüfen===
-   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 Pi neu gestartet istsollte man kontrollieren, ob die Dienste "hostapd" und "dnsmasq" laufen, bevor man sich am neu eingerichteten WLAN-Router anmeldet. 
- +   sudo systemctl status hostapd 
-To double check we have got everything configured correctly, reboot with +   ps ax | grep hostapd 
-   sudo reboot+   sudo systemctl status dnsmasq 
 +   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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki