0.确保已经创建过wifi热点
CTrl + Alt +T进入终端,输入命令nm-connection-editor,调出网络连接设置:
其中Wi-Fi下面有Hotspot热点,没有的话,可以点左下角的+ 来添加创建,并在其中设置好相关参数
1. 创建服务文件
sudo gedit /etc/systemd/system/hotspot_init.service
2. 在文件中写入如下内容并保存:
[Unit]
Description=Hotspot Service
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/nmcli dev wifi hotspot con-name test-desktop password qq123123 ifname wlan0
ExecStop=/usr/bin/nmcli con down id Hotspot
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
其中,test-desktop为热点名,qq123123为密码, wlan0为对应wifi网卡名(可用ifconfig查看)。 Hotspot为关闭热点id,( id可在热点打开后,在命令行中键入nmcli con down id 后,不断按tab键来查看)。
此外,若发现热点信号不好,可尝试使用2.4G wifi频率:
CTrl + Alt +T进入终端,输入命令nm-connection-editor,调出网络连接设置 ,在里面找到创建的Hotspot或test-desktop连接,打开后将里面的热点band选成相应的频率后完成设置
3.加载服务开机自启动
sudo systemctl daemon-reload
sudo systemctl enable hotspot_init.service
sudo systemctl start hotspot_init.service
4.查询服务状态
sudo systemctl status hotspot.service # 查询服务的状态
journalctl -u hotspot.service #查看命令执行日志