手把手教你使用 Raspberry - Wireless-Access-Point
RPI Wireless-Access-Point
將Raspberry Pi3 作為無線路由接入點
Install the necessary software.
$ sudo apt-get install hostapd udhcpdConfigure DHCP /etc/udhcpd.conf
$ sudo nano /etc/udhcpd.conf// 將文件修為為如下內容:start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices. end 192.168.42.20 interface wlan0 # The device uDHCP listens on. remaining yes opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use. opt subnet 255.255.255.0 opt router 192.168.42.1 # The Pi's IP address on wlan0 which we will set up shortly. opt lease 864000 # 10 day DHCP lease time in secondsEdit the file /etc/default/udhcpd and change the line:
DHCPD_ENABLED="no"to
#DHCPD_ENABLED="no"Configure Network
allow-hotplug wlan0 iface wlan0 inet static address 192.168.42.1 netmask 255.255.255.0Change the lines (they probably won’t all be next to each other):
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet manualto
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf#iface default inet dhcp
/etc/network/interfaces like this:
# interfaces(5) file used by ifup(8) and ifdown(8)# Please note that this file is written to be used with dhcpcd# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'# Include files from /etc/network/interfaces.d:source-directory /etc/network/interfaces.dauto lo iface lo inet loopbackiface eth0 inet manualallow-hotplug wlan0 iface wlan0 inet staticaddress 192.168.52.1netmask 255.255.255.0gateway 192.168.52.1network 192.168.52.0broadcast 192.168.52.255dns-nameservers 192.168.52.1 8.8.8.8 8.8.4.4#iface wlan0 inet manual# wpa-conf /etc/wpa_supplicantwpa_supplicant.conf#allow-hotplug wlan1#iface wlan1 inet manual# wpa-conf /etc/wpa_supplicant/wpa_supplicant.confup iptables-restore < /etc/iptables.ipv4.natConfigure HostAPD. edit the file /etc/hostapd/hostapd.conf (create it if it doesn’t exist) and add the following lines:
A secure network
interface=wlan0 driver=nl80211 ssid=My_AP hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=My_Password wpa_key_mgmt=WPA-PSK#wpa_pairwise=TKIP # You better do not use this weak encryption (only used by old client devices)rsn_pairwise=CCMPA open network
interface=wlan0 ssid=My_AP hw_mode=g channel=6 auth_algs=1 wmm_enabled=0If Raspberry Pi 3 add this parameters:
ieee80211n=1 # 802.11n support wmm_enabled=1 # QoS support ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]Edit the file /etc/default/hostapd and change the line:
#DAEMON_CONF=""to
DAEMON_CONF="/etc/hostapd/hostapd.conf"Configure NAT (Network Address Translation). NAT is a technique that allows several devices to use a single connection to the internet. Linux supports NAT using Netfilter (also known as iptables) and is fairly easy to set up. First, enable IP forwarding in the kernel:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"To set this up automatically on boot, edit the file /etc/sysctl.conf and add the following line to the bottom of the file:
net.ipv4.ip_forward=1To enable NAT in the kernel, run the following commands:
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 ACCEPTThese instructions don’t give a good solution for rerouting https and for URLs referring to a page inside a domain, like www.nu.nl/38274.htm. The user will see a 404 error. Your Pi is now NAT-ing. To make this permanent so you don’t have to run the commands after each reboot, run the following command:
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"Now edit the file /etc/network/interfaces and add the following line to the bottom of the file:
up iptables-restore < /etc/iptables.ipv4.natFire it Up!
sudo service hostapd start sudo service udhcpd startYour Pi should now be hosting a wireless hotspot. To get the hotspot to start on boot, run these additional commands:
sudo update-rc.d hostapd enable sudo update-rc.d udhcpd enable
本文參考RPI-Wireless-Hotspot,在其基礎之上網絡配置部分稍作調整,在Raspberry Debian 8 上運行沒有問題!
總結
以上是生活随笔為你收集整理的手把手教你使用 Raspberry - Wireless-Access-Point的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机编程怎样打符号,在CAD中如何输入
- 下一篇: MySQL数据库入侵及防御方法