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