替换树莓派官方源为阿里源
#/etc/apt/sources.list
deb http://mirrors.aliyun.com/raspbian/raspbian stretch main contrib non-free rpi
##****# Uncomment line below then 'apt-get update' to enable 'apt-get source'
deb-src http://mirrors.aliyun.com/raspbian/raspbian stretch main contrib non-free rpi
安装所需要的软件
#Install program
sudo apt-get install dnsmasq hostapd pppoeconf iptables-persistent
配置树莓派wlan0的ip地址(注意树莓派的ip已经由/etc/dhcpcd.conf管理,需要在此文件中修改相应信息)
sudo vi /etc/dhcpcd.conf
#add following information at end
interface wlan0
static ip_address=10.1.0.1/24
nohook wpa_supplicant
#configure dhcp server
sudo vi /etc/dnsmasq.conf
interface=wlan0
listen-address=10.1.0.1
server=114.114.114.114
dhcp-range=10.1.0.10,10.1.0.100,24h
#config hostapd
sudo vi /etc/hostapd/hostapd.conf
interface=wlan0
channel=7
hw_mode=g
wmm_enabled=1
#ieee80211n=1
#ht_capab=[HT40+][SHORT-GI-40][TX-STBC][RX-STBC2][DSSS_CK-40][LDPC]
macaddr_acl=0
ssid=Art
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=Xmas200907
wpa_pairwise=TKIP
rsn_pairwise=CCMP
sudo vi /etc/defaut/hostapd #default configure location
DAEMON_CONF="/etc/hostapd/hostapd.conf"
通过
hostapd -d /etc/hostapd/hostapd.conf来调试hostapd
#PPOE
sudo ppoeconf
#ip forward
sudo vi /etc/sysctl.conf
net.ipv4.ip_forward=1
sysctl -p
#enable NAT
sudo iptables -t nat -I POSTROUTING -o ppp0 -s 10.1.0.0/24 -j MASQUERADE
sudo iptables-save > /etc/iptables/rules.v4
sudo /etc/init.d/netfilter-persistent restart
如果出现
iptables v1.8.1 (nf_tables): Chain 'MASQUERADE' does not exist
执行
update-alternatives --config iptables
选择 iptables-legacy 即可修正这个错误
转载于:https://blog.51cto.com/26081/2353390