您的位置:首页 > 其它

树莓派折腾日志1 无线路由器

2015-08-27 21:50 441 查看
树莓派到手第一天,先折腾成一个无线路由器。
中间遇到了hostapd死活起不来的问题。折腾了好久才弄好,主要是因为树莓派官方的hostapd不支持我的无线网卡。这里分享下折腾过程中解决的一些关键问题。
首先要确定自己的无线网卡型号。
pi@raspberrypi ~ $ lsusb

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.

Bus 001 Device 006: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
这里最后面一个就是我的无线网卡,型号为RTL8188CUS。官网提供的hostapd不支持该型号网卡的ap模式,所有要自己找个支持的驱动。

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


感谢http://ju.outofmemory.cn/entry/56020这篇文章,我才找到了原因。

配置hostapd
然后编辑hostapd的默认配置文件,如下:
sudo vim /etc/default/hostapd
找到#DAEMON_CONF ="",修改为:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
然后编辑sudo vim /etc/hostapd/hostapd.conf
# Basic configuration



interface=wlan0

ssid=raspberrywifi

channel=1

#bridge=br0



# WPA and WPA2 configuration



macaddr_acl=0

auth_algs=1

ignore_broadcast_ssid=0

wpa=3

wpa_passphrase=12345678

wpa_key_mgmt=WPA-PSK

wpa_pairwise=TKIP

rsn_pairwise=CCMP



# Hardware configuration



driver=rtl871xdrv

ieee80211n=1

hw_mode=g

device_name=RTL8192CU

manufacturer=Realtek
然后保存退出,重启服务
sudo hostapd /etc/hostapd/hostapd.conf

这里注意driver的值。一般的网卡写nl80211,但我这个网卡要写rtl871xdrv。置于这两个东东是代表什么,还希望明白这方面的兄弟不灵赐教。

dhcp服务器用dnsmasq

修改/etc/dnsmasq.conf文件。

使其有这样一行:

dhcp-range=192.168.20.50,192.168.1.20,48h

下面一行表示使用的端口

interface=wlan0

表示dhcp地址池的范围和租期。

假设dhcp服务器使用eth0,则配置eth0

# ifconfig wlan0 192.168.20.1

重启dnsmasq服务:

# /etc/init.d/dnsmasq restart

OK

用iptables配置路由转发
这里iptables的nat规则配置暂且照抄,回头有空细研究一下。

sudo iptables -F 
sudo iptables -X 
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE 
sudo bash 
iptables-save > /etc/iptables.up.rules 
exit


sudo vim /etc/network/if-pre-up.d/iptables

添加下面两行代码:


#!/bin/bash 
/sbin/iptables-restore < /etc/iptables.up.rules

保存退出,然后修改iptables权限:

sudochmod755 /etc/network/if-pre-up.d/iptables

开户内核转发:

sudo vim /etc/sysctl.conf

找到下面两行:


# Uncomment the next line to enable packet forwarding for IPv4 
#net.ipv4.ip_forward=1

把net.ipv4.ip_forward 前面的#去掉,保存退出。

然后


sudo sysctl -p

ok了,可以连接wifi上网了。

参考博文如下:
http://ju.outofmemory.cn/entry/56020

http://blog.csdn.net/xdw1985829/article/details/38845533
http://www.cnblogs.com/craftor/p/3811627.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: