标签:com http blog style class div img code java javascript log
所需硬件:树莓派、无线网卡
1.查看无线网卡是否被识别
pi@raspberrypi ~ $ sudo lsusb Bus 001 Device 002: ID 0424:9512 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 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter pi@raspberrypi ~ $
WLAN Adapter代表的就是无线网卡被系统识别,芯片是RTL8188CUS
2.无线网卡配置静态IP地址
sudo vim /etc/network/interfaces #配置静态地址
pi@raspberrypi ~ $ sudo vim /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
address
192.168.8.1
netmask 255.255.255.0
保存后重启wlan0网卡
sudo ifdown wlan0 sudo ifup wlan0
3.安装DHCP服务软件
sudo apt-get install isc-dhcp-server
配置DHCP服务
sudo vim /etc/dhcp/dhcpd.conf #编辑配置文件 #option domain-name "example.org"; #注释 #option domain-name-servers ns1.example.org, ns2.example.org; #注释 authoritative; #去除注释 #在配置文件底部添加发下配置 subnet 192.168.8.0 netmask 255.255.255.0 { range 192.168.8.100 192.168.8.200; option broadcast-address 192.168.8.255; option routers 192.168.8.1; default-lease-time 600; max-lease-time 7200; option domain-name "local"; option domain-name-servers 8.8.8.8, 8.8.4.4; }
sudo vim /etc/default/isc-dhcp-server #编辑配置文件 INTERFACES="wlan0"
4.安装AP软件与配置
sudo apt-get install hostapd 配置Access Point sudo vim /etc/hostapd/hostapd.conf interface=wlan0 driver=rtl871xdrv#这个是树莓派无线网卡驱动,不要改 ssid=pi#无线信号名字,随意设 hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=raspberry#密码,随意设 wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
设置读取加载配置文件
sudo vim /etc/default/hostapd #找到#DAEMON_CONF=""修改成 DAEMON_CONF="/etc/hostapd/hostapd.conf"
默认安装的版本比较新,该驱动需要用V0.8的版本,否则运行hostapd会报错
wget http://www.adafruit.com/downloads/adafruit_hostapd.zip unzip adafruit_hostapd.zip sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG sudo mv hostapd /usr/sbin sudo chmod 755 /usr/sbin/hostapd
sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf
5.启动dhcp、hostapd服务
sudo service isc-dhcp-server start #启用DHPCServere服务 sudo service hostapd start #启用AP服务
设置开启自启动
sudo update-rc.d hostapd enable sudo update-rc.d isc-dhcp-server enable
6.开启转发
sudo vim /etc/sysctl.conf #开机启动设置ip转发 #底部加上一行 net.ipv4.ip_forward=1 或者直接: sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
7.添加防火墙规则
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
8.保存规则并开机自动生效
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat" sudo vim /etc/network/interfaces #开机生效 up iptables-restore < /etc/iptables.ipv4.nat #底部增加一行
标签:com http blog style class div img code java javascript log
原文地址:http://www.cnblogs.com/buptmuye/p/3695790.html