还是看原文链接吧:https://github.com/eexpress/eexp-bin/blob/master/ap.bash
感觉挺好用的。而且修改挺方便。里面实现了ipv4的转发。基本的参数都可以修改。
记得安装一下sudo apt-get install isc-dhcp-server
使能dhcpd。不然不会自动分配IP哦。
今天重新编辑一下,出现rfkill block的问题。
$ sudo ifconfig wlan0 up
SIOCSIFFLAGS: Operation not possible due to RF-kill
可以参考网页http://askubuntu.com/questions/62166/siocsifflags-operation-not-possible-due-to-rf-kill
重要的解决方法在这儿:
Soft-blocking
The output to sudo rfkill list
shows that your network card is "soft-blocked".
This could happen when the wireless card has been signalled to switch-off via the kernel.
Try the following steps:
-
run in a terminal:
sudo rfkill unblock wifi; sudo rfkill unblock all
-
rerun
sudo rfkill list
to confirm that the card has been unblocked. -
reboot
-
rerun
sudo rfkill list
again to confirm unblocking as been retained. -
rerun
sudo lshw -class network
- you should now see that the kernel has recognised (or not) the wireless card.
If the wireless kernel module has been recognised (it should not say "unclaimed"), Network Manager should now be able to see wireless networks that are available in your vacinity.
以下是脚本的代码
#!/bin/bash
#● ai hostapd dhcp3-server
iw list|grep '* AP'
[ $? -ne 0 ] && echo "No device support AP mode." && exit
sudo ifconfig wlan0 192.168.0.1 netmask 255.255.255.0
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -j MASQUERADE
sudo pkill -9 dhcpd
if [ ! -f /etc/apparmor.d/disable/usr.sbin.dhcpd ]; then
sudo ln -s /etc/apparmor.d/usr.sbin.dhcpd /etc/apparmor.d/disable/
sudo /etc/init.d/apparmor restart
fi
cat > /tmp/dhcpd.conf << EOF
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.0.0 netmask 255.255.255.0
{
range 192.168.0.2 192.168.0.250;
option domain-name-servers 8.8.8.8;
option routers 192.168.0.1;
}
EOF
sudo dhcpd wlan0 -cf /tmp/dhcpd.conf -pf /var/run/dhcp-server/dhcpd.pid
cat > /tmp/hostapd.conf << EOF
interface=wlan0
driver=nl80211
ssid=`hostname`-hostapd
hw_mode=g
channel=11
auth_algs=1
# 如果需要开启密码,wpa=1。
wpa=0
wpa_passphrase=12345678
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
EOF
sudo hostapd -d /tmp/hostapd.conf