您好,登錄后才能下訂單哦!
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。