A tutorial on using the NMCLI command to manage networks in the Linux Redhat system

Source: Internet
Author: User

The default network services in Red Hat Enterprise Linux 7 and CentOS 7 are provided by the NetworkManager, a daemon that dynamically controls and configures the network to keep the current network devices and connections working, while also supporting the traditional ifcfg type of Configuration file.

NetworkManager can be used for the following types of connections: Ethernet,vlans,bridges,bonds,teams,wi-fi,mobile Boradband (such as mobile 3G) and Ip-over-infiniband. For these network types, NetworkManager can configure their network aliases, IP addresses, static routes, DNS,VPN connections, and many other special parameters.

You can use command-line tools nmcli to control NetworkManager.

NMCLI usage

The code is as follows:

# NMCLI [OPTIONS] OBJECT {COMMAND | help}

We can use the TAB key to complete the command, and when you forget the syntax of this command, you can just press TAB to see the list of options.

Some examples of using nmcli:

The code is as follows:

# NMCLI General Status

This command prints all the states of the NetworkManager.

The code is as follows:

# NMCLI Connection Show

Show all connections.

The code is as follows:

# NMCLI Connection Show-a

Displays only the currently active connections.

The code is as follows:

# NMCLI Device status

Lists the list of devices identified by NetworkManager and their status.

Start/Stop Network interface

Use the Nmcli tool to start or stop the network interface, which is the same as Ifconfig's up/down.

Stop an interface by using the following command:

The code is as follows:

# NMCLI Device Disconnect eno16777736

The following commands are used to start the interface:

The code is as follows:

# NMCLI Device Connect eno16777736

To add a static IP Ethernet connection

The following command can add an Ethernet connection with a static IP address:

The code is as follows:

# NMCLI Connection Add type Ethernet con-name name_of_connection ifname interface-name ip4 ip_address gw4 gw_address

Change the name_of_connection,ip_address according to the configuration you want, gw_address parameters (you can omit the last part if you don't need a gateway).

The code is as follows:

# NMCLI Connection Add type Ethernet con-name NEW ifname eno16777736 ip4 192.168.1.141 gw4 192.168.1.1

Use the following command to set up a DNS server:

The code is as follows:

# NMCLI Connection Modify NEW ipv4.dns "8.8.8.8 8.8.4.4"

The following command launches a new Ethernet connection:

The code is as follows:

# NMCLI Connection up NEW ifname eno16777736

To view the configuration information for a new connection:

The code is as follows:

# Nmcli-p Connection Show NEW

Add a new connection that uses DHCP

Add new connections, use DHCP to automatically assign IP addresses, gateways, DNS, and so on, all you have to do is remove the IP/GW address section from the command line, and DHCP automatically assigns these parameters.

For example, configure a DHCP connection named New_dhcp on the ENO 16777736 device

The code is as follows:

# NMCLI Connection Add type Ethernet con-name NEW_DHCP ifname eno16777736

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.