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
  • 4
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值