Use the nmcli command in RedHat/CentOS 7.x to manage the network

Source: Internet
Author: User

Use the nmcli command in RedHat/CentOS 7.x to manage the network

The default network service in Red Hat Enterprise Linux 7 and CentOS 7 is provided by NetworkManager, which dynamically controls and configures the network daemon. It is used to keep the current network device and connection in the working state, it also supports configuration files of the traditional ifcfg type.

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.

Nmcli usage
  1. # 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:

  1. # nmcli general status

This command prints out all the statuses of NetworkManager.

  1. # nmcli connection show

Show all connections.

  1. # nmcli connection show -a

Only active connections are displayed.

  1. # nmcli device status

Lists devices identified by NetworkManager and their statuses.

Start/stop a 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:

  1. # nmcli device disconnect eno16777736

Run the following command to start the interface:

  1. # nmcli device connect eno16777736
Add static IP Ethernet connection

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

  1. # 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 ).

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

  1. # nmcli connection modify NEW ipv4.dns "8.8.8.8 8.8.4.4"

Run the following command to start a new Ethernet connection:

  1. # nmcli connection up NEW ifname eno16777736

View the configuration of the new connection:

  1. # nmcli -p connection show NEW

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.

  1. # nmcli connection add type ethernet con-name NEW_DHCP ifname eno16777736

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.