linux下比较好的配置无线AP的脚本(非adhoc模式)

还是看原文链接吧: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:

  1. run in a terminal:

    sudo rfkill unblock wifi; sudo rfkill unblock all

  2. rerun sudo rfkill list to confirm that the card has been unblocked.

  3. reboot

  4. rerun sudo rfkill list again to confirm unblocking as been retained.

  5. 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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值