五.设置IPV4转发 打开系统配置文件sysctl.conf,将IPV4转发那一行的#去掉 sudo nano /etc/sysctl.conf # Uncomment the next two lines toenable Spoof protection (reverse-path filter) # Turn on Source AddressVerification in all interfaces to # prevent some spoofing attacks #net.ipv4.conf.default.rp_filter=1 #net.ipv4.conf.all.rp_filter=1 # Uncomment the next line toenable TCP/IP SYN cookies # Note: This may impact IPv6 TCPsessions too #net.ipv4.tcp_syncookies=1 # Uncomment the next line toenable packet forwarding for IPv4 net.ipv4.ip_forward=1 下一次重启后会生效,如果不想现在重启,可以直接输入如下指令直接生效。 sudo sh -c "echo 1 >/proc/sys/net/ipv4/ip_forward" 为了实现PI3以太网接口共享给wlan0上网,需要配置NAT,需先执行如下防火墙命令 sudo iptables -t nat -APOSTROUTING -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 当然,为了不每次都手动配置,需要将以上规则设为自启动。 sudo sh -c "iptables-save> /etc/iptables.ipv4.nat" 通过获取DHCPCD来运行NAT需要创建一个新文件 sudo nano/lib/dhcpcd/dhcpcd-hooks/70-ipv4-nat iptables-restore </etc/iptables.ipv4.nat 最后需要重启服务: sudo service hostapdstart sudo service dnsmasq start sudo reboot 可以通过无线网卡客户端或手机WIFI关联pi3ap,以下是用WI-PIdongle在WIN7系统上连接pi3ap后的成功例子,上网速度也超快。另外在多个用户的手机上也都连接成功。
|