将树莓派打造成超级无线路由器[自动翻墙+过滤广告](一)
2016-08-10 00:00
603 查看
本文通过 OscPress 同步至oschina,获取最新版本和更好的阅读体验请查看原文: https://www.cellmean.com/?p=1145 |
无线路由(AP)
1.安装dnsmasq hostapdsudo apt-get install dnsmasq hostapd
其中 hostapd 是用于将树莓派3板载无线网卡变成无线接入点(AP),dnsmasq 作为DHCP服务器和DNS服务器。其中DHCP服务器也可以使用 udhcpd ,不过我没有尝试这种方式。
2.禁用无线接口wlan0
编辑文件 /etc/dhcpcd.conf ,最后一行加入:
denyinterfaces wlan0
树莓派3的无线网卡默认使用dhcp获取IP的,需要先禁用,后来做无线网卡跟AP模式切换时发现这一步似乎可以省去。
3.修改网卡配置文件 /etc/network/interfaces ,把wlan0区域改成下面的配置:
allow-hotplug wlan0
iface wlan0 inet static
address 172.24.1.1
netmask 255.255.255.0
network 172.24.1.0
broadcast 172.24.1.255
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
4. 配置hostapd, 修改文件 /etc/hostapd/hostapd.conf
# This is the name of the WiFi interface we configured above interface=wlan0 # Use the nl80211 driver with the brcmfmac driver driver=nl80211 # This is the name of the network ssid=Pi3-AP # Use the 2.4GHz band hw_mode=g # Use channel 6 channel=6 # Enable 802.11n ieee80211n=1 # Enable WMM wmm_enabled=1 # Enable 40MHz channels with 20ns guard interval ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] # Accept all MAC addresses macaddr_acl=0 # Use WPA authentication auth_algs=1 # Require clients to know the network name ignore_broadcast_ssid=0 # Use WPA2 wpa=2 # Use a pre-shared key wpa_key_mgmt=WPA-PSK # The network passphrase wpa_passphrase=raspberry # Use AES, instead of TKIP rsn_pairwise=CCMP
这样配置了一个名称是 Pi3-AP 密码是 raspberry 的无线热点,执行:
/usr/sbin/hostapd /etc/hostapd/hostapd.conf
就能在无线网络里搜到这个热点了。但是连接之后并不能上网,我们还需要配置 DNS 和 DHCP 服务。所以按ctrl+C退出服务。
5. 配置 dnsmasq
修改 /etc/dnsmasq.conf 文件,请先执行备份
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.`date +%F`
内容修改成:
interface=wlan0 # Use interface wlan0 listen-address=172.24.1.1 # Explicitly specify the address to listen on bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere server=114.114.114.114 # Forward DNS requests to Google DNS domain-needed # Don't forward short names bogus-priv # Never forward addresses in the non-routed address spaces. dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time
其中 server 表示使用DNS服务器IP,dhcp-range 表示IP分配的范围和时间
6. 设置ip转发,修改/etc/sysctl.conf ,将这行代码反注释掉:
net.ipv4.ip_forward=1
或者执行:
sudo echo 1 > /proc/sys/net/ipv4/ip_forward
接着修改 IPTABLES的规则:
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
iptables 的规则在关机后会消失,我们需要把规则保存下来并且在开机后还原这些规则
sudo iptables-save > /etc/iptables.ipv4.nat
修改 /etc/rc.local, 在最后加入一行
iptables-restore < /etc/iptables.ipv4.nat
7. 开机启动 hostapd 和 dnsmasq :
sudo update-rc.d hostapd defaults
sudo update-rc.d dnsmasq defaults
然后执行
sudo reboot
重启树莓派,就能搜索到无线热点 Pi3-AP ,输入密码就能顺利连接上网了。
突然觉得篇幅有点长了,决定分成几节,下一节介绍树莓派无线网卡模式和 AP 模式切换。
感谢阅读本文,欢迎访问 微言 获取更多内容或 查看原文
相关文章推荐
- 树莓派3安装openwrt打造无线路由器
- 树莓派(Raspberry Pi 3) - 树莓派打造无线路由器
- privoxy——广告过滤和自动代理切换
- 技巧百问(5):打造超级浮动广告(不受屏幕限制)
- Chrome插件Tampermonkey--自定义过滤百度网页搜索结果并去除广告栏和自动推荐
- 将树莓派打造成无线路由器
- py + opencv 打造树莓派监控,场景有变化自动拍照上传到百度云
- WebBrowser自动点击链接 广告自动点击 Ads Auto Click
- 微信公众平台新增图片上传接口 将自动过滤外链图片
- 使用Python爬虫+SMTP打造‘自动告白邮件脚本'
- 可以自动轮播的banner条,首页广告条,自定义指示点
- 暴雪分享:打造超级大作的9个步骤
- 禁止Chrome加载电脑管家广告过滤脚本代码
- android——打造超级方便的一键式添加型Title
- android广告自动设置时间跳界面
- 打造DIY版Echo:树莓派+ Alexa 语音服务
- 自动过滤显示用combox--Extjs
- QQ编程思想群 努力打造500人超级会员群
- 利用五大维度打造真正的「原生广告」