Raspberry Pi ως WiFi επαναλήπτη - πώς λειτουργεί
Σε αυτή την πρακτική συμβουλή θα μάθετε πώς μπορείτε να χρησιμοποιήσετε το Raspberry Pi ως αναμεταδότη WiFi. Έτσι έχετε την καλύτερη WiFi υποδοχή στο σπίτι σας.
Το Raspberry Pi ως αναμεταδότης WiFi: τα αξεσουάρ που χρειάζεστε
Για να μπορέσετε να χρησιμοποιήσετε το Raspberry Pi ως αναμεταδότη WiFi, χρειάζεστε - εκτός από το Raspberry Pi με Raspbian - τα παρακάτω εξαρτήματα.
- Δύο ραβδιά WLAN με chipset Ralink RT5370
- Ένα τροφοδοτικό για το Raspberry Pi
Προετοιμασία Raspberry Pi για WLAN: Εγκαταστήστε Hostapd και dnsmasq
Πρώτα εγκαταστήστε το hostapd και το dnsmasq έτσι ώστε να μπορείτε να χρησιμοποιήσετε το Raspberry Pi ως διακομιστή AP και DHCP. Το Hostapd είναι ένας αποκαλούμενος έλεγχος ταυτότητας, ο οποίος τελικά δημιουργεί το σημείο πρόσβασης WLAN, ενώ το dnsmasq είναι ένας απλός διακομιστής DNS και DHCP που μεταδίδει άγνωστα αιτήματα ονόματος και τα αποθηκεύει στην κρυφή μνήμη. Για να το κάνετε αυτό, εκτελέστε την ακόλουθη εντολή:
- sudo apt-get να εγκαταστήσετε το hostapd dnsmasq
Εκχωρήστε ένα στατικό IP στο ραβδί WLAN
Μόλις γίνει αυτό, πρέπει να αντιστοιχίσετε ένα στατικό IP στο ραβδί WLAN. Για να το κάνετε αυτό, επεξεργαστείτε το αρχείο "/ etc / network / interfaces" και πληκτρολογήστε εδώ:
- ## / etc / network / interfaces για τη συσκευή wlan0
- # Ρυθμίστε τη συσκευή με στατική IP
- iface wlan0 inet στατική
- # Στατική διεύθυνση IP
- διεύθυνση 10.0.0.1
- # Μάσκα δικτύου
- μάσκα δικτύου 255.255.255.0
Ρύθμιση του Raspberry Pi: hostapd
Τώρα πρέπει να επεξεργαστείτε το αρχείο ρύθμισης hostapd ("DAEMON_CONF =" / etc / hostapd / hostapd.conf ""). Προσαρμόστε το αρχείο ως εξής:
- # Περιεχόμενο του /etc/hostapd/hostapd.conf
- # 1.Η συσκευή που θα λειτουργεί ως AP
- διεπαφή = wlan0
- οδηγός = nl80211
- # 2.Parameters έτσι ώστε ο δαίμονας τρέχει
- ctrl_interface = / var / run / hostapd
- ctrl_interface_group = 0
- # 3. Η διαμόρφωση Wifi
- SSID = Raspi
- καναλιού = 6
- hw_mode = g
- ieee80211n = 1
- # 4. Ασφάλεια της σύνδεσης Wifi
- wpa = 2
- wpa_passphrase = ΠΟΛΥ SECRET
- wpa_key_mgmt = WPA-PSK
- wpa_pairwise = CCMP
- rsn_pairwise = CCMP
- # 5. Άλλες ρυθμίσεις
- beacon_int = 100
- auth_algs = 3
- wmm_enabled = 1
Το Raspberry Pi ως αναμετάδοση WiFi: Επιτρέπεται η ανάθεση διευθύνσεων IP
Τώρα προσαρμόστε το αρχείο "/etc/dnsmasq.conf" έτσι ώστε το Raspberry Pi να μπορεί επίσης να εκχωρήσει διευθύνσεις IP:
- διεπαφή = wlan0
- dhcp-range = 10.0.0.2, 10.0.0.20, 255.255.255.0, 12h
Συνδέστε Raspberry Pi στο δρομολογητή
Χρησιμοποιήστε την εντολή sudo apt-get install wpa_supplicant για να βεβαιωθείτε ότι είναι εγκατεστημένο το wpa_supplicant, δημιουργήστε το αρχείο ρυθμίσεων "/etc/wpa.conf" και πληκτρολογήστε εδώ εδώ. Μην ξεχάσετε να προσαρμόσετε ανάλογα το "myssid" και τον "κωδικό πρόσβασης".
- δικτύου = {
- SSID = "myssid"
- PSK = "password"
- προτεραιότητα = 0
- }
DIY WiFi επαναλήπτης: Δημιουργία σύνδεσης
Για να μπορέσει το Raspberry Pi να δημιουργήσει σωστά τη σύνδεση, πρέπει να επεξεργαστείτε το αρχείο "/ etc / network / interfaces".
- ## Πρόσθετες γραμμές στο / etc / network / interfaces για τη συσκευή wlan1
- # Ξεκινήστε τη συσκευή κατά την εκκίνηση του συστήματος
- αυτοκίνητο wifi1
- # Διαμορφώστε τη συσκευή μέσω dhcp
- iface wlan1 inet dhcp
- # Χρησιμοποιήστε το δεδομένο αρχείο για σύνδεση στο διαδίκτυο
- wpa-conf /etc/wpa.conf
Επεξεργαστείτε τις ρυθμίσεις δικτύου του Raspberry Pi
Για να μεταβιβάσετε το σήμα Internet στις συσκευές που είναι συνδεδεμένες στο Raspberry Pi, πρέπει να επεξεργαστείτε το αρχείο ρυθμίσεων sysctl.
- Στο αρχείο "/etc/sysctl.conf" αφαιρέστε τον διπλό σταυρό (#) στη γραμμή "# net.ipv4.ip_forward = 1".
- Χρησιμοποιήστε την εντολή "sysctl -p" για να ξαναδιαβάσετε το αρχείο sysctl.conf.
- Εγκαταστήστε το iptables με την εντολή "sudo apt-get install iptables" έτσι ώστε το Raspberry Pi να μπορεί να στέλνει πακέτα μεταξύ των δικτύων WiFi.
Επεξεργαστείτε το τείχος προστασίας στον πυρήνα του Linux
Για να διασφαλίσετε ότι η σύνδεση παρέχεται αυτόματα όταν ξεκινάει η εφαρμογή Raspberry Pi, δημιουργήστε το αρχείο "/etc/network/if-up.d/router.sh" και εισαγάγετε τα ακόλουθα. Μην ξεχάσετε να επισημάνετε το αρχείο σας ως εκτελέσιμο (chmod + x).
$config[ads_text5] not found- iptables --table nat --append POSTROUTING --out-διεπαφή wlan1 -j MASQUERADE
- iptables --append FORWARD - στην διεπαφή wlan0 -j ACCEPT
Ενεργοποιήστε την πύλη στο Διαδίκτυο
Τέλος, πρέπει να βεβαιωθείτε ότι το dnsmasq λέει στις συσκευές ότι είναι μια πύλη στο Διαδίκτυο. Για να το κάνετε αυτό, επεξεργαστείτε το αρχείο "/etc/dnsmasq.conf" και καταχωρίστε τα παρακάτω. Μετά από αυτό, το μόνο που έχετε να κάνετε είναι να επανεκκινήσετε το Raspberry Pi.
- dhcp-option = 3, 10.0.0.1