Настройка raspberry pi как wifi точки доступа
09.08.2015
Однажды мне захотелось сделать точку доступа из raspberry pi. Купил wifi usb адаптер TP-LINK TL-WN725N, 150Mbps 802.11n, Nano и приступил к настройке.
Для начала обновил систему.
sudo rpi-update uname -a Linux raspberrypi 3.18.9+ #768 PREEMPT Sun Mar 15 18:59:03 GMT 2015 armv6l GNU/Linux
В этой версии уже должны быть драйвера для этого адаптера, но если система не находит устройство, то вы можете скачать их
sudo wget https://github.com/lwfinger/rtl8188eu/raw/c83976d1dfb4793893158461430261562b3a5bf0/rtl8188eufw.bin -O /lib/firmware/rtlwifi/rtl8188eufw.bin
и перезагрузить raspberry.
Если и это не помогло, то попробуйте так (сначала найдите нужную версию тут):
// 3.18.9+ #767, #768 - 8188eu-20150307.tar.gz см. uname -a wget https://dl.dropboxusercontent.com/u/80256631/8188eu-20150307.tar.gz tar -zxvf 8188eu-20140307.tar.gz sudo cp rtl8188eufw.bin /lib/firmware/rtlwifi //not needed anymore if your operating system is above 3.10.33+ sudo install -p -m 644 8188eu.ko /lib/modules/3.10.33+/kernel/drivers/net/wireless sudo insmod /lib/modules/3.10.33+/kernel/drivers/net/wireless/8188eu.ko sudo depmod -a sudo reboot
После корректной настройки драйвера, lsusb должен показать
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 005: ID 0bda:8179 Realtek Semiconductor Corp. // wifi adapter
Далее нужно установить следующие пакеты:
sudo apt-get install bridge-utils udhcpd
sudo apt-get autoremove hostapd // если уже установлен hostapd wget https://github.com/jenssegers/RTL8188-hostapd/archive/v2.0.tar.gz tar -zxvf v2.0.tar.gz cd RTL8188-hostapd-2.0/hostapd sudo make sudo make install
Отредактировать /etc/hostapd/hostapd.conf. Содержимое моего файла стало выглядеть так:
# Basic configuration interface=wlan0 ssid=НАЗВАНИЕСЕТИ channel=6 bridge=br0 # WPA and WPA2 configuration macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=ПАРОЛЬ wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP wmm_enabled=0 # Hardware configuration driver=rtl871xdrv ieee80211n=1 hw_mode=g device_name=RTL8192CU manufacturer=Realtek
/etc/default/hostapd:
# Defaults for hostapd initscript # # See /usr/share/doc/hostapd/README.Debian for information about alternative # methods of managing hostapd. # # Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration # file and hostapd will be started during system boot. An example configuration # file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz # DAEMON_CONF="/etc/hostapd/hostapd.conf" # Additional daemon options to be appended to hostapd command:- # -d show more debug messages (-dd for even more) # -K include key data in debug messages # -t include timestamps in some debug messages # # Note that -B (daemon mode) and -P (pidfile) options are automatically # configured by the init.d script and must not be added to DAEMON_OPTS. # #DAEMON_OPTS=""
После редактируем sudo nano /etc/network/interfaces. Содержимое моего файла стало выглядеть так:
auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp #hwaddress ether 00:e0:4c:42:64:c4 auto wlan0 iface wlan0 inet static address 192.168.42.1 netmask 255.255.255.0 post-up service udhcpd start up iptables-restore < /etc/iptables.ipv4.nat
Вносим еще пару изменений.
/etc/udhcpd.conf:
# The start and end of the IP lease block start 192.168.42.2 #default: 192.168.0.20 end 192.168.42.20 #default: 192.168.0.254 ... #interface eth0 #default: eth0 interface wlan0 ... remaining yes #default: yes ... #Examles opt dns 8.8.8.8 4.4.4.4 option subnet 255.255.255.0 opt router 192.168.42.1 #opt wins 192.168.10.10 #option dns 129.219.13.81 # appened to above DNS servers for a total of 3 #option domain local option lease 864000 # 10 days of seconds ...
/etc/sysctl.conf:
... # Uncomment the next line to enable packet forwarding for IPv4 net.ipv4.ip_forward=1 ...
Настроить маршрутизацию (но я не уверен, что она нужна)
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 sh -c "iptables-save > /etc/iptables.ipv4.nat"
Надеюсь, что я ничего не пропустил.
Теперь, после перезагрузки системы, все должно заработать!
