使用环境:
* Raspberry Pi2 板子
* EP-N8508GS 无线网卡
使用软件
* hostapd
* udhcpd
1. 软件安装
sudo apt-get install hostapd udhcpd
官方hostapd无法兼容EP-N8508GS 无线网卡
wget http://www.daveconroy.com/wp3/wp-content/uploads/2013/07/hostapd.zip
unzip hostapd.zip
sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.bak
sudo mv hostapd /usr/sbin/hostapd.edimax
sudo ln -sf /usr/sbin/hostapd.edimax /usr/sbin/hostapd
sudo chown root.root /usr/sbin/hostapd
sudo chmod 755 /usr/sbin/hostapd
2. 修改配置文件
2.1 修改hostapd
- hostapd配置文件
/etc/hostapd/hostapd.conf
interface=wlan0
ssid=MyNAT
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
- 配置hostapd启动设置
/etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"
2.2 启动ip转发
- 修改
/etc/sysctl.conf
net.ipv4.ip_forward=1
- 启用设置
sysctl -p
2.3 修改网络配置,对无线网卡wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 10.10.10.1
netmask 255.255.255.0
2.4 修改udhcpd配置
- 修改
/etc/udhcpd.conf
start 10.10.10.2
end 10.10.10.20
interface wlan0
remaining yes
opt dns 8.8.8.8
opt subnet 255.255.255.0
opt router 10.10.10.1
opt lease 864000
- 修改服务配置
/etc/default/udhcpd
#DHCPD_ENABLED="no"
2.5 修改防火墙
iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
3 启动服务
systemctl restart networking
systemctl restart hostapd
systemctl restart udhcpd
4 桥接配置
如果只是让有线网络转换为无线网络,那么修改配置为桥接方式建立热点
4.1 修改网络配置/etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto br0
iface br0 inet dhcp
bridge_ports eth0 wlan0
4.2 配置hostapd
- 配置
/etc/hostapd/hostapd.conf
interface=wlan0
bridge=br0
ssid=MyNAT2
channel=1
wmm_enabled=0
wpa=1
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
auth_algs=1
macaddr_acl=0
- 配置
/etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"
引用资料
http://wangye.org/blog/archives/845/
http://blog.csdn.net/xukai871105/article/details/42497097
http://blog.itpub.net/29901741/viewspace-1294741/