ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Ubuntu 命令行连接wifi

2020-12-08 18:03:33  阅读:272  来源: 互联网

标签:nmcli wifi hotspot 命令行 Ubuntu device ifname con


注:nmcli命令支持使用缩写(别名),譬如说 device——dev、connection——con、……

1、建立和删除一个wifi连接

创建wifi连接(SSID:Samsung-printer,密码:12345678,默认使用设备wlan0)的示例:

$ nmcli device wifi connect Samsung-printer password 12345678

每次命令执行后,会在/etc/NetworkManager/system-connections/目录下创建一个新文件来保存配置,重复执行则创建多个这样的文件。

删除wifi连接的示例:

$ nmcli con del Samsung-printer

在/etc/NetworkManager/system-connections/目录下的Samsung-printer文件将被删除。

2、启动连接和关闭连接

启用wifi连接的示例:

 
  1. $ nmcli connection up Samsung-printer

  2. 或者

  3. $ nmcli device con wlan0

关闭wifi连接的示例:

 
  1. $ nmcli connection down Samsung-printer

  2. 或者

  3. $ nmcli device dis wlan0

4、设置以太网

eth0使用HDCP分配IP:

nmcli con add type ethernet autoconnect no ifname eth0

eth0手动设置IP:

$ nmcli con add type ethernet autoconnect yes ifname eth0 ipv4.addr "192.168.0.0/24" ipv4.method manual

autoconnect后跟yes/no表示自动/不自动连接,ifname后面是设备名称,该命令可以包含有其他设置参数,例如ipv4.addr、ipv4.method等。

4、创建热点

命令格式及参数解释如下:

wifi hotspot [ifname ifname] [con-name name] [ssid SSID] [ band { a | bg } ] [channel channel] [password password]

Create a Wi-Fi hotspot. The command creates a hotspot connection profile according to Wi-Fi device capabilities and activates it on the device. The hotspot is secured with WPA if device/driver supports that, otherwise WEP is used. Use connection down or device disconnect to stop the hotspot.

Parameters of the hotspot can be influenced by the optional parameters:

ifname

使用的网络设备名称

con-name

热点的名称

ssid

热点的ssid

band

wifi的协议标准

channel

信道

password

热点的密码。如果不设置,nmcli会生成一个WPA或者WEP的密码。加入全局选项--show-secrets将会输出热点的密码,这在nmcli生成密码时十分有用。

示例:

$ nmcli device wifi hotspot ifname wlan0 con-name MyHostspot ssid MyHostspotSSID password 12345678

命令执行后,将会创建一个名为MyHotspot的连接。使用上述的命令启动连接,将会开启热点。

5、设置自动连接

示例:

$ nmcli connnection modify MyHotspot connection.autoconnect yes

标签:nmcli,wifi,hotspot,命令行,Ubuntu,device,ifname,con
来源: https://blog.csdn.net/campper/article/details/110878513

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有