nmcli是用于控制NetworkManager和报告网络状态的 命令行工具。nmcli用于创建、显示、编辑、删除、激活和停用网络连接,以及控制和显示网络设备状态。 |
nmcli [OPTIONS...] {help | general | networking | radio | connection | device | agent | monitor} [COMMAND] [ARGUMENTS...]
可以使用TAB键来补全 命令,忘记了语法,可以按TAB键查看可用选项。如果按TAB键没有反应,也许是没有安装 bash-completion
#安装bash-completion [root@localhost ~]# yum -y install bash-completion #退出重新登录 [root@localhost ~]# exit
查看NetworkManager的状态:
[root@localhost ~]# nmcli general status STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN connected full enabled enabled enabled enabled
列出连接配置文件信息:
[root@localhost ~]# nmcli connection show NAME UUID TYPE DEVICE enp0s3 5005942f-a7fd-4e55-b8e7-77928d8da72d ethernet enp0s3
显示网卡的状态:
[root@localhost ~]# nmcli device status DEVICE TYPE STATE CONNECTION enp0s3 ethernet connected enp0s3 lo loopback unmanaged --
可以使用nmcli命令行启动或停止网卡,相当于ifup/ifdown命令。
[root@localhost ~]# nmcli device disconnect enp0s3
[root@localhost ~]# nmcli device connect enp0s3
[root@localhost ~]# nmcli connection modify enp0s3 ipv4.method manual ipv4.addresses 192.168.0.110/24 ipv4.gateway 192.168.0.1 ipv4.dns 202.102.128.68 [root@localhost ~]# nmcli connection up enp0s3
[root@localhost ~]# nmcli connection modify enp0s3 +ipv4.addresses 192.168.0.108/24 # 启用配置文件 [root@localhost ~]# nmcli connection up enp0s3 # 查看ip地址 [root@localhost ~]# ip add show enp0s3 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:7b:d3:32 brd ff:ff:ff:ff:ff:ff inet 192.168.0.107/24 brd 192.168.0.255 scope global noprefixroute enp0s3 valid_lft forever preferred_lft forever inet 192.168.0.108/24 brd 192.168.0.255 scope global secondary noprefixroute enp0s3 valid_lft forever preferred_lft forever inet6 fe80::d4d9:9043:1056:9e1a/64 scope link noprefixroute valid_lft forever preferred_lft forever
[root@localhost ~]# nmcli connection modify enp0s3 -ipv4.addresses 192.168.0.108/24 # 启用配置文件 [root@localhost ~]# nmcli connection up enp0s3 # 查看ip地址 [root@localhost ~]# ip ad show enp0s3 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:7b:d3:32 brd ff:ff:ff:ff:ff:ff inet 192.168.0.107/24 brd 192.168.0.255 scope global noprefixroute enp0s3 valid_lft forever preferred_lft forever inet6 fe80::d4d9:9043:1056:9e1a/64 scope link noprefixroute valid_lft forever preferred_lft forever
在命令行界面,对于直接修改配置文件,用nmcli修改网卡信息还是非常方便的。
原文地址: https://www.linuxprobe.com/centos7-nmcli-tools.html
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。