RPI Wireless-Access-Point
aspberry-pi3-作为无线路由接入点">将Raspberry Pi3 作为无线路由接入点
Install the necessary software.
$ sudo apt-get install hostapd udhcpd
Configure 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 seconds
Edit 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.0
Change the lines (they probably won’t all be next to each other):
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet manual
to
#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.d auto lo iface lo inet loopback iface eth0 inet manual allow-hotplug wlan0 iface wlan0 inet static address 192.168.52.1 netmask 255.255.255.0 gateway 192.168.52.1 network 192.168.52.0 broadcast 192.168.52.255 dns-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.conf up iptables-restore < /etc/iptables.ipv4.nat
Configure 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=CCMP
A open network
interface=wlan0 ssid=My_AP hw_mode=g channel=6 auth_algs=1 wmm_enabled=0
If 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=1
To 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 ACCEPT
These 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.nat
Fire it Up!
sudo service hostapd start sudo service udhcpd start
Your 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 上运行没有问题!