ubuntu中创建开机自启动wifi热点
第一步安装依赖库
sudo apt-get install util-linux procps hostapd iproute2 iw haveged dnsmasq
第二步下载源码
git clone https://github.com/oblique/create_ap
第三步进入文件并编译源码
cd create_ap
sudo make install
第四步测试AP模式
sudo create_ap wlan0(无线网卡名) eth0(有线网卡名) wifi热点名称 wifi热点密码
查看网卡名称:
iwconfig
$ iwconfig
enp9s0 no wireless extensions.
wlp12s0 IEEE 802.11 ESSID:off/any
Mode:Managed Access Point: Not-Associated Tx-Power=14 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:off
enp11s0 no wireless extensions.
lo no wireless extensions.
ap0 IEEE 802.11 Mode:Master Tx-Power=14 dBm
Retry short limit:7 RTS thr:off Fragment thr:off
Power Management:off
我们可以看到enp所以enp9s0,enp11s0为有线网卡名称;wlp12s0为无线网卡名称。
测试代码
sudo create_ap wlp12s0 enp11s0 tsinghua 12345678
见出现下面AP-ENABLED 表示创建成功,可以打开手机wifi搜索一定看得见一个wifi名称为tsinghua
Config dir: /tmp/create_ap.wlp12s0.conf.IpfYaNhV
PID: 9468
Network Manager found, set ap1 as unmanaged device... DONE
Creating a virtual WiFi interface... ap1 created.
Sharing Internet using method: nat
hostapd command-line interface: hostapd_cli -p /tmp/create_ap.wlp12s0.conf.IpfYaNhV/hostapd_ctrl
Configuration file: /tmp/create_ap.wlp12s0.conf.IpfYaNhV/hostapd.conf
Using interface ap1 with hwaddr e0:b9:a5:04:cf:87 and ssid "tsinghua"
ap1: interface state UNINITIALIZED->ENABLED
ap1: AP-ENABLED
因为关机后热点又会不见,所以设置一个开机自启脚本。
第五步创建开机自启脚本
在/etc中创建rc.local文件
编辑
sudo gedit /etc/rc.local
输入以下代码
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sudo create_ap wlp12s0 enp11s0 tsinghua 12345678 &
sudo /etc/init.d/ssh restart
exit 0
预防开机无法自启动,给定权限
sudo chmod +x /etc/rc.local