Nmcli network management command line tool Basics
Introduction
In this tutorial, we will discuss the network management command line tool (NetworkManager command line tool) in CentOS/RHEL 7, also known as nmcli. Users who use ifconfig should avoid using ifconfig in CentOS 7.
Let's use the nmcli tool to configure some network settings.
To obtain the address information of all interfaces in the system
[root@localhost ~]#ip addr show
Sample output:
1: lo:<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno16777736:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:67:2f:4c brd ff:ff:ff:ff:ff:ff
inet 192.168.1.51/24 brd 192.168.1.255 scope global eno16777736
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fe67:2f4c/64 scope link
valid_lft forever preferred_lft forever
Retrieve data packet statistics related to connected Interfaces
[root@localhost ~]#ip-s link show eno16777736
Sample output:
Obtain route Configuration
[root@localhost ~]#iproute
Sample output:
default via 192.168.1.1 dev eno16777736 proto static metric 100
192.168.1.0/24 dev eno16777736 proto kernel scope link src 192.168.1.51 metric 100
Analyze host/website path
[root@localhost ~]# tracepath unixmen.com
The output is like traceroute, but more complete.
Nmcli Tool
Nmcli is a rich and flexible command line tool. Nmcli usage:
- Device-Network Interface in use
- Connection-a group of configuration settings. A single device can have multiple connections and can be switched between connections.
Find out how many connected devices are used
[root@localhost ~]# nmcli connection show
Obtain the details of a specific connection.
[root@localhost ~]# nmcli connection show eno1
Sample output:
Obtain the network device status
[root@localhost ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
eno16777736 ethernet connected eno1
lo loopback unmanaged --
Use "dhcp" to create a new connection
[root@localhost ~]# nmcli connection add con-name "dhcp" type ethernet ifname eno16777736
Here,
- Connection add-add new connection
- Con-name-connection name
- Type-device type
- Ifname-Interface Name
This command will use the dhcp protocol to add connections
Sample output:
Connection'dhcp'(163a6822-cd50-4d23-bb42-8b774aeab9cb) successfully added.
Use static to add an IP address instead of dhcp allocation
[root@localhost ~]# nmcli connection add con-name "static" ifname eno16777736 autoconnect no type ethernet ip4 192.168.1.240 gw4 192.168.1.1
Sample output:
Connection'static'(8e69d847-03d7-47c7-8623-bb112f5cc842) successfully added.
Update Connection:
[root@localhost ~]# nmcli connection up eno1
Check whether the IP address has changed.
[root@localhost ~]#ip addr show
Add DNS settings to static connections
[root@localhost ~]# nmcli connection modify "static" ipv4.dns 202.131.124.4
Add more DNS
[root@localhost ~]# nmcli connection modify "static"+ipv4.dns 8.8.8.8
Note: use an extra + symbol, and use + ipv4.dns instead of ip4.dns.
Add an additional IP Address
[root@localhost ~]# nmcli connection modify "static"+ipv4.addresses 192.168.200.1/24
Use the command to refresh the settings:
[root@localhost ~]# nmcli connection up eno1
As you can see, the settings take effect.
End.
Via: http://www.unixmen.com/basics-networkmanager-command-line-tool-nmcli/
Author: Rajneesh Upadhyay Translator: geekpi Proofreader: wxy
This article was originally translated by LCTT and launched with the Linux honor in China
This article permanently updates the link address: