25.1.LubanCat无线网卡支持列表¶

25.4.2. nmcli¶

1

2

3

4

5

6

7

8

9

10

11

12# 列出可用的wifi接入点, list可以省略

sudo nmcli dev wifi list

# 连接热点PPP, 连接成功后,就会自动生成配置文件,以后要再连接,可以使用nmcli connectio up mySSID命令了

sudo nmcli dev wifi connect PPP password '00000000' ifname wlan0

#如果连接成功后,下次想再连接,就可以使用

sudo nmcli dev wifi connect PPP

#更多nmcli的命令可以使用来查看

nmcli help

nmcli OBJECT help

nmcli命令组成

nmcli [OPTIONS] OBJECT { COMMAND | help }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29OPTIONS

-o[verview] overview mode (hide default values)

-t[erse] terse output

-p[retty] pretty output

-m[ode] tabular|multiline output mode

-c[olors] auto|yes|no whether to use colors in output

-f[ields] |all|common specify fields to output

-g[et-values] |all|common shortcut for -m tabular -t -f

-e[scape] yes|no escape columns separators in values

-a[sk] ask for missing parameters

-s[how-secrets] allow displaying passwords

-w[ait] set timeout waiting for finishing operations

-v[ersion] show program version

-h[elp] print this help

#OBJECT可以用缩写表示

OBJECT

g[eneral] NetworkManager's general status and operations

n[etworking] overall networking control

r[adio] NetworkManager radio switches

c[onnection] NetworkManager's connections

d[evice] devices managed by NetworkManager

a[gent] NetworkManager secret agent or polkit agent

m[onitor] monitor NetworkManager changes

Command 可以通过 nmcli OBJECT help 来获得

下列列举部分常用的命令

nmcli常用命令¶

命令

作用

nmcli n

显示 NetworkManager 是否接管网络设置

nmcli n on

设定 NetworkManager 接管网络

nmcli n off

取消 NetworkManager 接管网络

nmcli c status

查看连接简略信息

nmcli c show

查看连接详细信息

nmcli c up/down ifname

启动/关闭指定连接(ifname 网卡)

nmcli c show(s) ifname

查看ifname网卡的连接详细信息

nmcli c delete(de) ens33

删除指定连接

nmcli d status

查看设备简略信息

nmcli d show

查看设备详细信息

nmcli d sh ens33

显示某一特定设备的详细信息

nmcli d connect(c) ens33

连接设备

nmcli d disconnect(c) ens33

断开设备

1

2

3

4

5

6

7#先列出连接的配置,eth0现在连接的是Wired connection 1

root@lubancat:~# nmcli c s

NAME UUID TYPE DEVICE

Wired connection 1 35ecb023-3194-3edb-bf90-4198f82329a8 ethernet eth0

Wired connection 2 45f86cca-f8df-376e-8aad-37e10d2a65ce ethernet --

aEBF_Guest fb1d506e-6dc7-4c5b-a4ce-339f3349d26d wifi wlan0

然后对Wired connection 1进行修改

1

2

3

4

5

6

7

8

9

10

11

12

13#静态ip设置

sudo nmcli c modify 'aEBF_Guest' [ + | - ]选项 选项值 # 或

sudo nmcli c m 'aEBF_Guest' ipv4.address 192.168.103.172/24 # 修改 IP 地址和子网掩码

sudo nmcli c m 'aEBF_Guest' ipv4.method manual # 修改为静态配置,默认是 auto

sudo nmcli c m 'aEBF_Guest' ipv4.gateway 192.168.103.254 # 修改默认网关

sudo nmcli c m 'aEBF_Guest' ipv4.dns 8.8.8.8 # 修改 DNS

sudo nmcli c m 'aEBF_Guest' +ipv4.dns 114.114.114.114 # 添加一个 DNS

sudo nmcli c m 'aEBF_Guest' ipv6.method disabled # 将 IPv6 禁用

sudo nmcli c m 'aEBF_Guest' connection.autoconnect yes # 开机启动

注意,必须先修改 ipv4.address,然后才能修改 ipv4.method!

用空引号""代替选项的值,可将选项设回默认值(以 ipv4.method 为例):

详细的文档连接

《nmcli命令用法是什么》

《Linux中nmcli命令详解》