公司的wifi信号很弱,也不保险。省事起见,还是自己建立一个好
usb无线网卡设备必须是一个 nl80211 兼容的无线设备,所以驱动就是这个:nl80211
我的操作系统是Ubuntu,如果是CentOS命令基本一样
插上wifi usb卡后 ip a 看一下网卡的名称,我这里是:wlx00a1b0817651,够长
一、安装hostapd软件
sudo apt install -y hostapd
二、建立hostapd.conf文件
vi /etc/hostapd/hostapd.conf
driver=nl80211
ssid=Fast_8188
channel=10
interface=wlx00a1b0817651
wpa=2
wpa_passphrase=GreatWall2021!
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
三、建立启动脚本/usr/local/bin/initAP.sh
cat /usr/local/bin/initAP.sh
#!/bin/bash
start() {
rfkill unblock all
ifconfig wlx00a1b0817651 up 192.168.222.1 netmask 255.255.255.0
sleep 2
dnsmasq -i wlx00a1b0817651 --dhcp-range=192.168.222.10,192.168.222.20,2h
#Enable NAT
sysctl -w net.ipv4.ip_forward=1
iptables -F
iptables -X
iptables -t nat -A POSTROUTING -s 192.168.222.0/24 -j SNAT --to 192.168.41.15
hostapd -B /etc/hostapd/hostapd.conf
}
stop() {
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
systemctl stop dnsmasq
pkill hostapd
/sbin/ip link set down dev wlx00a1b0817651
}
case $1 in
start)
start
;;
stop)
stop
;;
*)
echo "Usage: $0 {start|stop}"
exit 2
esac
四、用root身份执行即可
sudo chmod 755 /usr/local/bin/initAP.sh
sudo /usr/local/bin/initAP.sh start
这样就可以用自己的手机连上这个wifi热点,尽情冲浪啦。