SetupHostapd
VMware® Workstation 10.0.1 build-1379776 + Ubuntu 12.04LTS(Linux Kernel 3.8.0-29-generic)
无线网卡tenda 832u ( 在Ubuntu13.04和无线网卡型号:tp-link TL-WN310G下也成功安装过 )
Hostapd 2.0
Install Hostapd 2.0
因为我们之后要进行修改调试,所以这里通过源代码来编译安装
ubuntu@ubuntu:~$ sudo apt-get install libnl-dev libpopt-dev libssl-dev ubuntu@ubuntu:~$ wget http://hostap.epitest.fi/releases/hostapd-2.0.tar.gz ubuntu@ubuntu:~$ cp hostapd-2.0.tar.gz /mnt/hgfs/github #拷贝到windows下的目录,方便在windows下阅读和修改代码 ubuntu@ubuntu:~$ cd /mnt/hgfs/github/ ubuntu@ubuntu:/mnt/hgfs/github$ tar -zxvf hostapd-2.0.tar.gz ubuntu@ubuntu:/mnt/hgfs/github$ cd hostapd-2.0/hostapd/ ubuntu@ubuntu:/mnt/hgfs/github/hostapd-2.0/hostapd$ cp defconfig .config ubuntu@ubuntu:/mnt/hgfs/github/hostapd-2.0/hostapd$ make ubuntu@ubuntu:/mnt/hgfs/github/hostapd-2.0/hostapd$ sudo make install
顺利编译安装成功
安装配置无线网卡
这里使用tenda 832u,插上网卡后虚拟机会跳出提示,VMware左下角会出现USB设备,点击连接设备,最终命令行下ifconfig时能看到wlan0网口
ubuntu@ubuntu:~/hostapd-2.0/hostapd$ sudo gedit /etc/network/interfaces
配置wlan0网口为:
auto wlan0 iface wlan0 inet static address 192.168.0.1 netmask 255.255.255.0
这时eth0有线网口应该是能上网的。
配置hostapd
准备hostapd的配置文件
ubuntu@ubuntu:~/hostapd-2.0/hostapd$ sudo gedit /etc/hostapd.conf
注意理解各参数的含义,配置文件中的具体参数范例如下:
interface=wlan0 driver=nl80211 ssid=mengning hw_mode=g channel=11 dtim_period=1 rts_threshold=2347 fragm_threshold=2346 macaddr_acl=0 auth_algs=3 #ieee80211n=0 wpa=2 wpa_passphrase=12345678 wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
安装dnsmasq
DNSmasq是一个小巧且方便地用于配置DNS和DHCP的工具,适用于小型网络,它提供了DNS功能和可选择的DHCP功能。
当前环境默认已安装运行dnsmasq,这里需要先把它杀掉,然后升级一下
ubuntu@ubuntu:~$ ps -e | grep dnsmasq 1293 ? 00:00:00 dnsmasq ubuntu@ubuntu:~$ sudo killall dnsmasq ubuntu@ubuntu:~$ sudo apt-get install dnsmasq ubuntu@ubuntu:~$ ping www.163.com ubuntu@ubuntu:~$ sudo reboot
这时ping一个网址的话可能不通了,DNS解析有问题,需要重启看再ping一下看网络是否通了。
配置DHCP服务器
ubuntu@ubuntu:~/hostapd-2.0/hostapd$ sudo gedit /etc/dnsmasq.conf
配置参数如下
interface=wlan0 bind-interfaces except-interface=lo dhcp-range=192.168.0.100,192.168.0.200,6h dhcp-option=3,192.168.0.1 dhcp-option=6,219.219.223.10
其中
dhcp-range=192.168.0.100,192.168.0.200,6h #设置dhcp地址范围,即租借时间6小时
dhcp-option=3,192.168.0.1 #为手机配置网关
dhcp-option=6,219.219.223.10 #为手机配置dns,这里是USTCSZ的DNS
启动hostapd,dnsmasq
ubuntu@ubuntu:~$ sudo ifconfig wlan0 192.168.0.1 netmask 255.255.255.0 ubuntu@ubuntu:~$ sudo hostapd -B /etc/hostapd.conf Configuration file: /etc/hostapd.conf Using interface wlan0 with hwaddr c8:3a:35:cc:76:cd and ssid "mengning" ubuntu@ubuntu:~$ sudo /etc/init.d/dnsmasq restart
这时station可以连接我们搭建AP了,但还无法上网,尽管我们的虚拟机中eth0可以上网。
配置路由上网
ubuntu@ubuntu:~$ sudo -s root@ubuntu:~# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf root@ubuntu:~# echo 1 > /proc/sys/net/ipv4/ip_forward root@ubuntu:~# exit exit ubuntu@ubuntu:~$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE ubuntu@ubuntu:~$