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:~$