Introduced
In this tutorial, we will discuss the network Management command-line tool in Centos/rhel 7, NetworkManager, also known as NMCLI. Users who use ifconfig should avoid using Ifconfig in CentOS 7.
Let's configure some network settings with the Nmcli tool.
To get address information for all interfaces in the system
[[Email protected] ~]# IP addrshow
Sample Output :
1:lo:<loopback,up,lower_up> MTU 65536 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 brd00: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 qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0c:29:67:2f:4c Brdff:ff:ff:ff:ff:ff
inet 192.168.1.51/24 BRD 192.168.1.255 scopeglobal eno16777736
Valid_lft Forever Preferred_lft Forever
Inet6 FE80::20C:29FF:FE67:2F4C/64 Scope link
Valid_lft Forever Preferred_lft Forever
Retrieving packet statistics related to a connected interface
[Email protected] ~]# Ip-slink show eno16777736
Get the routing configuration
[[Email protected] ~]# IP route
Sample Output :
Default via 192.168.1.1 deveno16777736 proto static metric 100
192.168.1.0/24 deveno16777736 proto kernel scope link src 192.168.1.51 metric 100
Analyze Host/site path
[Email protected] ~]# tracepathunixmen.com
The output is like traceroute, but more complete.
nmcli Tools
nmcli is a very rich and flexible command-line tool. Nmcli are used in the following situations:
Device – The network interface being used
Connect – A set of configuration settings that can have multiple connections for a single device and can be switched between connections.
Find out how many devices are connected to the service
[Email protected] ~]# nmcliconnection Show
Get details of a specific connection
[Email protected] ~]# nmcliconnection show Eno1
Get Network Device status
[Email protected] ~]# nmclidevice status
DEVICE TYPE State CONNECTION
eno16777736 Ethernet Connected Eno1
Lo Loopback unmanaged--
To create a new connection by using DHCP
[[email protected] ~]# nmcliconnection add con-name "DHCP" type Ethernet ifname eno16777736
Over here
Connection Add – Add a new connection
Con-name – Connection Name
type – Device Type
ifname – Interface Name
This command adds a connection using the DHCP protocol
Sample Output :
Connection ' DHCP ' (163A6822-CD50-4D23-BB42-8B774AEAB9CB) successfully added.
Do not assign IP via DHCP, add address using "static"
[Email protected] ~]# nmcliconnection add con-name "static" ifname eno16777736 AutoConnect notype Ethernet IP4 192.168.1. Gw4 192.168.1.1
Sample Output :
Connection ' static ' (8e69d847-03d7-47c7-8623-bb112f5cc842) successfully added.
Update Connection :
[Email protected] ~]# nmcliconnection up Eno1
Check again to see if the IP address has changed
[[Email protected] ~]# IP addrshow
Adding DNS settings to a static connection
[Email protected] ~]# nmcliconnection Modify "static" Ipv4.dns 202.131.124.4
Add more DNS
[Email protected] ~]# nmcliconnection Modify "static" +ipv4.dns 8.8.8.8
Note : To use the extra + symbol, and if +ipv4.dns, not ip4.dns.
Add an additional IP address
[Email protected] ~]# nmcliconnection Modify "static" +ipv4.addresses 192.168.200.1/24
To refresh the settings using the command:
[Email protected] ~]# nmcliconnection up Eno1
You will see that the settings are in effect.
End.
Free pick upBrother LianITEducationOriginalLinuxMaintenance EngineerVideo/elaborateLinuxtutorials, more information on the official website customer service:http://www.lampbrother.net/linux/
or hooking up with Q2430675018.
Welcome to the Linux Communication Group 478068715
NMCLI Network Management command-line tool basics