Use the nmcli command to manage the network in CentOS7

Source: Internet
Author: User
Network management is actually the management of NetworkManager. you can use the nmcli command to control the network. The following describes how RedHat/CentOS7 uses the nmcli command to manage the network, do not miss out. the network management of RedHatEnterpriseLinux7 and CentOS7 is actually the management of NetworkManager, which can be controlled by nmcli commands.

Network management is actually the management of NetworkManager. you can use the nmcli command to control the network. The following describes how RedHat/CentOS 7 uses the nmcli command to manage the network, do not miss out.

 

Network management of Red Hat Enterprise Linux 7 and CentOS 7 is actually the management of NetworkManager, which can be controlled by the nmcli command, the following small series will introduce you to RedHat/CentOS 7 using the nmcli command to manage the network. if you do not know how to manage the network, you can learn.

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 the command line tool nmcli to control NetworkManager.

1. usage of nmcli

# Nmcli [OPTIONS] OBJECT {COMMAND | help}

You can use the TAB key to complete the command. when you forget the syntax of this command, you only need to press TAB to view the option list.

Some examples of using nmcli:

# Nmcli general status

This command prints out all the statuses of NetworkManager.

# Nmcli connection show

Show all connections.

# Nmcli connection show-

Only active connections are displayed.

# Nmcli device status

Lists devices identified by NetworkManager and their statuses.

2. Start/Stop the network interface

Use the nmcli tool to start or stop the network interface, which is the same as the up/down of ifconfig.

Run the following command to stop an interface:

# Nmcli device disconnect eno16777736

Run the following command to start the interface:

# Nmcli device connect eno16777736

3. add an Ethernet connection with a static IP address

Run the following command to add an Ethernet connection with a static IP address:

# Nmcli connection add type ethernet con-name NAME_OF_CONNECTION ifname interface-name ip4 IP_ADDRESS gw4 GW_ADDRESS

Modify the NAME_OF_CONNECTION, IP_ADDRESS, and GW_ADDRESS parameters according to the configuration you need (if you do not need a gateway, you can omit the last part ).

# Nmcli connection add type ethernet con-name NEW ifname eno16777736 ip4 192.168.1.141 gw4 192.168.1.1

Run the following command to set the DNS server:

# Nmcli connection modify NEW ipv4.dns "8.8.8.8 8.4.4"

Run the following command to start a new Ethernet connection:

# Nmcli connection up NEW ifname eno16777736

View the configuration of the new connection:

# Nmcli-p connection show NEW

4. add a new connection using DHCP

Add a new connection and use DHCP to automatically allocate ip addresses, gateways, DNS, etc. all you need to do is remove the ip address/gw address after the command line, DHCP automatically assigns these parameters.

For example, configure a DHCP connection named NEW_DHCP on the eno 16777736 device.

# Nmcli connection add type ethernet con-name NEW_DHCP ifname eno16777736

The above section describes how to manage the network using nmcli commands in RedHat/CentOS 7. This article describes in detail some examples of using nmcli commands, so that friends who are not familiar with nmcli commands can master the use of nmcli commands.

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.