用树莓派打造无线路由器

树莓派可以折腾的方法很多,我将会吧自己的折腾经验与大家分享。
作为无线路由器,需要提供dhcp的功能和无线ap的能力,我们分别通过isc-dhcp-server和hostapd这两个软件来实现,网卡间转发直接通过iptables定义nat规则来实现。
安装dhcp服务和ap热点服务
apt-get install isc-dhcp-server
apt-get install hostapd
修改/etc/network/interfaces
u510
在/etc/dhcp/dhcpd.conf添加
u511
修改/etc/hostapd/hostapd.conf
u512
打开内核的网卡转发能力,将/etc/sysctl.conf的
net.ipv4.ip_forward=1
的注释去掉。
修改iptables的nat规则
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
将规则添加成为自动启动方式
iptables-save > /root/nat.rule
新建/etc/network/if-pre-up.d/iptables
#!/bin/bash
/sbin/iptables-restore < /root/nat.rule
或者直接在文件里写入规则语句
如果你的hostapd没有办法正常工作,应该是hostapd不支持你的网卡芯片,下载:https://github.com/cnsworder/RTL8188-hostapd/archive/master.zip
在raspberrypi上直接编译就可以了(编译速度确实很慢的)
cd hostapd
make;make install
重新修改hostapd的配置文件就可以了。
看到了树梅派的热点
u513

标签: 树莓派教程