Nmcli network management command line tool Basics

Source: Internet
Author: User
Tags configuration settings

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
  1. [root@localhost ~]#ip addr show

Sample output:

  1. 1: lo:<LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
  2. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  3. inet 127.0.0.1/8 scope host lo
  4. valid_lft forever preferred_lft forever
  5. inet6 ::1/128 scope host
  6. valid_lft forever preferred_lft forever
  7. 2: eno16777736:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  8. link/ether 00:0c:29:67:2f:4c brd ff:ff:ff:ff:ff:ff
  9. inet 192.168.1.51/24 brd 192.168.1.255 scope global eno16777736
  10. valid_lft forever preferred_lft forever
  11. inet6 fe80::20c:29ff:fe67:2f4c/64 scope link
  12. valid_lft forever preferred_lft forever

 

Retrieve data packet statistics related to connected Interfaces
  1. [root@localhost ~]#ip-s link show eno16777736

Sample output:

 

Obtain route Configuration
  1. [root@localhost ~]#iproute

Sample output:

  1. default via 192.168.1.1 dev eno16777736 proto static metric 100
  2. 192.168.1.0/24 dev eno16777736 proto kernel scope link src 192.168.1.51 metric 100

 

Analyze host/website path
  1. [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
  1. [root@localhost ~]# nmcli connection show

 

Obtain the details of a specific connection.
  1. [root@localhost ~]# nmcli connection show eno1

Sample output:

 

Obtain the network device status
  1. [root@localhost ~]# nmcli device status
  1. DEVICE TYPE STATE CONNECTION
  2. eno16777736 ethernet connected eno1
  3. lo loopback unmanaged --
Use "dhcp" to create a new connection
  1. [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:

  1. Connection'dhcp'(163a6822-cd50-4d23-bb42-8b774aeab9cb) successfully added.
Use static to add an IP address instead of dhcp allocation
  1. [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:

  1. Connection'static'(8e69d847-03d7-47c7-8623-bb112f5cc842) successfully added.

Update Connection:

  1. [root@localhost ~]# nmcli connection up eno1

Check whether the IP address has changed.

  1. [root@localhost ~]#ip addr show

 

Add DNS settings to static connections
  1. [root@localhost ~]# nmcli connection modify "static" ipv4.dns 202.131.124.4

 

Add more DNS
  1. [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
  1. [root@localhost ~]# nmcli connection modify "static"+ipv4.addresses 192.168.200.1/24

Use the command to refresh the settings:

  1. [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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.