树莓派做wifi热点



原帖地址:

1,http://elinux.org/RPI-Wireless-Hotspot

2,http://www.jenssegers.be/

首先我的是树莓派B版,网卡是EDUP-N8508GS,其芯片是realtek RTL8188CUS,根据http://elinux.org/RPI-Wireless-Hotspot设置发现最后会hostapd segmentation fault.最后找到http://www.jenssegers.be/.

这篇文章也只是自己大概翻译一下这两个帖子,并且作为自己的一个记录.感谢在ickey上朋友帮抽中的树莓派,感谢我的好朋友.

假设你已经有了充足的配件,有网络连接(暂时没有的,如校园网用户,请看后面连接wifi热点),设置好ip地址,然后以pi身份登陆到上面去了.

系统版本是2013-02-09-wheezy-raspbian

(1) 先安装软件包

sudo apt-get install hostapd udhcpd
sudo apt-get install udhcpd

(同这个网卡芯片型号的先不用安装hostapd)

(使用dnsmasq请看http://sirlagz.net/2012/08/09/how-to-use-the-raspberry-pi-as-a-wireless-access-pointrouter-part-1/)

(2) 编辑配置文件

sudo nano /etc/udhcpd.conf

如:

start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices.
end 192.168.42.20
interface wlan0 # The device uDHCP listens on.
remaining yes
opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use.
opt subnet 255.255.255.0
opt router 192.168.42.1 # The Pi's IP address on wlan0 which we will set up shortly.
opt lease 864000 # 10 day DHCP lease time in seconds

再编辑 /etc/default/udhcpd:

sudo nano   /etc/default/udhcpd



DHCPD_ENABLED="no"



#DHCPD_ENABLED="no"

(3) 分配静态ip

sudo ifconfig wlan0 192.168.42.1

要想开机自动设置

sudo nano /etc/network/interfaces

替换"iface wlan0 inet dhcp" (如果没有就直接写)到:

iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0

注释与wifi连接的行如

allow-hotplug wlan0
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual

到:

#allow-hotplug wlan0
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp

(4) 设置hostapd(本网卡芯片型号的先不设置):

sudo nano /etc/hostapd/hostapd.conf

wpa加密的:

输入:

interface=wlan0
driver=nl80211
ssid=热点名称
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=热点密码
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

不加密的:

interface=wlan0
ssid=My_AP
hw_mode=g
channel=6
auth_algs=1
wmm_enabled=0



sudo nano /etc/default/hostapd

把下面这句

#DAEMON_CONF=""

改为

DAEMON_CONF="/etc/hostapd/hostapd.conf"

(5) 设置NAT.

 sudo nano /etc/sysctl.conf

文件末尾加入:

net.ipv4.ip_forward=1

然后运行一下命令:

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

要想开机自动设置,再输入:

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

现在编辑网卡接口设置:

sudo nano /etc/network/interfaces

加入:

up iptables-restore < /etc/iptables.ipv4.nat

启动热点:

sudo service hostapd restart
sudo service udhcpd restart

开机自动启动热点:

sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable

sudo ln -s /etc/init.d/hostapd /etc/rc2.d/S02hostapd

(6) 设置本网卡型号的hostapd:

如果你是我这个型号的,但是找着之前的教程安装会出现:

nl80211: 'nl80211' generic netlink not found
Failed to initialize driver 'nl80211'
rmdir[ctrl_interface]: No such file or directory

因为之前的教程使用nl80211这个驱动,有些网卡,比如我这张就不行。其他网卡型号的待测试,建议先照之前的教程安装.不行在找网卡型号适合的hostapd和驱动装.

<1> 如果之前安装了hostapd包先用以下命令卸载:

sudo apt-get autoremove hostapd

<2> 下载专用的hostapd

wget https://github.com/segersjens/RTL8188-hostapd/archive/v1.1.tar.gz

解压:

tar -zxvf v1.0.tar.gz

(没有网络连接的可以用电脑下载再用u盘弄过去)

<3> 编译hostapd

cd RTL8188-hostapd-1.0/hostapd
sudo make install

<4> 设置hostapd.conf

sudo nano /etc/hostapd/hostapd.conf

像之前改下ssid,密码就好了.其他不知道就不要动.

<5> 重启服务:

sudo service hostapd restart

现在你应该能看到热点了.

连接wifi:

(1) 设置网卡接口:

sudo nano /etc/network/interfaces

设置成如

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet dhcp

auto wlan0

allow-hotplug wlan0

iface wlan0 inet static

address 192.168.137.108

netmask 255.255.255.0

gateway 192.168.137.1

dns-nameserver 202.116.0.1

wpa-ssid "热点名

你可能感兴趣的:(树莓派做wifi热点)