NMCLI command usage and network configuration

Source: Internet
Author: User

The default network service in Red Hat Enterprise Linux 7 and CentOS 7 is provided by NetworkManager, which is the daemon for dynamic control and configuration of the network, which is used to keep current network devices and connections in working condition while also supporting traditional ifcfg types 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 the command line tool NMCLI to control NetworkManager.

In Centos/rhel 7, the Network Management command-line tool, also known as NMCLI. Users who frequently use ifconfig should avoid using Ifconfig in CentOS 7. The function of NMCLI is much more powerful and complex.


Address Configuration Tool: Nmcli

Nmcli-command-line tool for controlling NetworkManager


Command syntax:

nmcli[OPTIONS] OBJECT {COMMAND | help}

Object and command can be used in full name can also be abbreviated, at least one letter can be used, the proposed first three letters. The most common thing we use in object is connection and device, which requires a simple distinction between connection and device.

Device called a network interface, is a physical device

Device-show and manage network interfaces

NMCLI Device Help

Connection is a connection, which is biased toward logical settings

Connection-start, stop, and manage network connections

NMCLI Connection Help

Multiple connection can be applied to the same device, but only one of the connection is enabled at the same time. The advantage is that for a network interface, we can set up a number of network connections, such as static IP and dynamic IP, and then as needed up the corresponding connection


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/86/F6/wKioL1fP3L-g1fdXAAAvAZncXO0325.png "title=" 6.png " alt= "Wkiol1fp3l-g1fdxaaavazncxo0325.png"/>

Modify properties such as IP address:

# NMCLI Connection Modify IFACE [+|-]setting.propertyvalue

Setting.property:

Ipv4.addresse Ipv4.gateway

Ipv4.dns1 ipv4.methodmanual | Auto


Modify the configuration file to take effect: systemctl Restart network or NMCLI con reload

NMCLI command effective: Nmclicon down eth0; Nmclicon up Eth0



To configure a network using NMCLI:

Neworkmanager is the daemon that manages and monitors network settings

The device is the network interface, and the connection is the configuration of the network interface. A network interface can have multiple connection configurations, but only one connection configuration takes effect.


    • Show all include inactive connections

Nmcli Con Show

    • Show all active connections

Nmcli Con Show--active

    • Show Network Connection Configuration

Nmcli con Show "System eth0"

    • Show Device status

NMCLI Dev Status

    • Display Network Interface Properties

NMCLI Dev Show eno16777736


Examples of Use:

Show all include inactive connections:

[[Email protected] 7 ~]# NMCLI Connection Show

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/86/F5/wKioL1fPxtqSu1_hAAAjahZ1LsY726.png "title=" 1.png " alt= "Wkiol1fpxtqsu1_haaajahz1lsy726.png"/>

Where the name content is the name content defined in the NIC configuration file, modify the profile name entry, you can change the name, you can choose to restart the Network service after the modification: "Command: Systemctl restart"; or reread Profile "command: Nmcli con Reload "to make it effective.

The "Wired Connection 1" is a wired connection, and because the device option is empty, it is not bound to the NIC so that it does not take effect.



    • Create a new connection Default,ip automatically via DHCP

# nmcli con add con-name default type Ethernet Ifnameeth0
    • Delete Connection

# nmcli con del default
    • Create new connection static, specify static IP, do not connect automatically

# Nmcticon Add con-name static ifnameeth0 AutoConnect no type Ethernet ip4 172.25.x.10/24 gw4 172.25.x.254

Con add– Adding a new connection

con-name– Connection Name

type– Device Type

ifname– Interface Name

AutoConnect no-no boot start automatically

Because the command is too long to be good at using tab completion, when the command is completed, a configuration file is generated under/etc/sysconfig/network-scripts/, but it does not take effect. Such as:


Example: Create a name for home, type Ethernet card, bind network card for eth1, boot auto Start, define IPv4 address and gateway

[[Email protected] 7 ~]# nmcli connection Add con-name Home type Ethernet ifname eth1 autoconnect Yes IP4 10.1.252.60/24 g W4 10.1.0.254

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/86/F7/wKiom1fP0KbzGZnSAABPvSEyMws504.png "title=" 2.png " alt= "Wkiom1fp0kbzgznsaabpvseymws504.png"/>

You can see the direct build configuration file, but the NIC is not bound, so it does not take effect.


We need to enable this interface

    • To enable the static connection configuration

Nmcli con up static

    • Enable default connection Configuration

Nmcli con up default

    • View Help

Nmcli con Add Help

[[Email protected] 7 ~]# nmcli connection up Home

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/86/F6/wKioL1fP0XjDROK9AAA-2G0fY_E685.png "title=" 3.png " alt= "Wkiol1fp0xjdrok9aaa-2g0fy_e685.png"/>

In this way, the home interface is in effect and can be used normally. However, the same time can only be tied to one interface. Usually if you need to work, you can set up a few sets of configuration files, the environment needs to be able to temporarily switch.

When you don't need to use: NMCLI Connection Delete Home Delete

[[Email protected] 7 ~]# nmcli Connection Delete Home Connection ' home ' (2443d6ec-f92e-4402-b15c-9eec15405852) successful Ly deleted.


    • Modify Connection Settings

NMCLI con mod "static" Connection.autoconnect No

NMCLI con mod "static" Ipv4.dns 172.25.x.254

NMCLI con mod "static" +ipv4.dns 8.8.8.8

NMCLI con mod "static"-ipv4.dns 8.8.8.8

NMCLI con mod "static" ipv4.addresses "172.25.x.10/24 172.25.x.254"

NMCLI con mod "static" +ipv4.addresses 10.10.10.10/16


Command modification and configuration file comparison:

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/86/F6/wKioL1fP3FXi2jAsAACIm7HpmF0103.png "title=" 5.png " alt= "Wkiol1fp3fxi2jasaacim7hpmf0103.png"/>


Device configuration is saved in a text file

    • /etc/sysconfig/network-scripts/ifcfg-<name>

    • The Help document lists the complete list of options:/usr/share/doc/initcripts-*/sysconfig.txt


Template:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/86/F6/wKioL1fP3UzRk4CCAABKL-c2x-A407.png "title=" 7.png " alt= "Wkiol1fp3uzrk4ccaabkl-c2x-a407.png"/>


After you modify the connection configuration, you need to reload the configuration

Nmcli Con Reload

Nmcli con Down "system eth0" can be activated automatically

Nmcli con up "system eth0"

nmcli Dev dis eth0 disable nic, check-in is automatically activated

Graphical tools

Nm-connection-editor



Cases:

[[Email protected] 7 ~]# nmcli con mod home +ipv4.addresses 10.1.114.114/24[[email protected] 7 ~]# nmcli con up home [[em AIL protected] 7 ~]# IP Addr

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/86/F8/wKiom1fP2ayyNYNEAAAxvjgYCBc384.png "title=" 4.png " alt= "Wkiom1fp2ayynyneaaaxvjgycbc384.png"/>



Networking Group Network Teaming

A network group is a way to logically connect multiple NICs together to allow failover or increase throughput. One way to improve server network availability is to use multiple network cards. The Linux binding driver provides a way to aggregate multiple network adapters into a single logical binding interface. This is a new way to implement bindings and does not affect the old binding drivers in the Linux kernel.

    • Network group: is a method of aggregating multiple network cards together to achieve redundancy and increase throughput

    • Network group differs from legacy bonding technology for better performance and scalability

    • The network group is implemented by the kernel driver and teamd daemon.

    • Multiple ways

Runner

Broadcast

Roundrobin

Activebackup

LoadBalance

LACP (implements the 802.3ad Link Aggregation Control Protocol)



    • Starting the Network group interface does not automatically start the port interface in the network group

    • The port interface in the Start Network group interface does not automatically start the Network group interface

    • Disabling the network group interface automatically disables the port interface in the network group

    • A network group interface without a port interface can initiate a static IP connection

    • When DHCP connection is enabled, network groups that do not have a port interface wait for the port interface to join



Create a network group interface

NMCLI con Add type team con-name CNAME ifname iname [Configjson]

CNAME connection name, INAME interface name

JSON Specifies runner mode

Format: ' {' runner ': {' name ': ' METHOD '} '

The method can be Broadcast,roundrobin,

Activebackup,loadbalance, LACP


Create Port Interface

Nmclicon Add type Team-slave con-name CNAME ifname iname Master Team

CNAME Connection Name

Iname Network Interface Name

Team Network Group Interface name

If the connection name is not specified, the default is Team-slave-iface

Nmcli Dev Dis iname

Nmcli con up CNAME

Iname Device name CNAME Network Group interface name or port interface




Experiment: Create a network group

1, create the network group TEAM0, will generate IFCFG-TEAM0 files in the/etc/sysconfig/network-scripts/directory

# NMCLI Connection Add con-name team0 type team ifname team0 config ' {"runner": {"name": "Activebackup"}} ' Ip4 10.1.252.60/1 6 Gw4 10.1.0.1

2. Add DNS

# NMCLI Connection Modify TEAM0 Ipv4.dns 8.8.8.8

3. Join Group members

# NMCLI Connection Add con-name team0-eth0 type Team-slave ifname eth0 Master TEAM0 # NMCLI connection Add Con-name team0- Eth1 type Team-slave ifname eth1 master Team0

4. Start

NMCLI connection up TEAM0NMCLI connection up TEAM0-ETH0NMCLI connection up team0-eth1

5. View status

# TEAMDCTL TEAM0 Stat

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/86/FB/wKiom1fQEQKyKW7yAAA2ryk-Hqo011.png "title=" 9.png " alt= "Wkiom1fqeqkykw7yaaa2ryk-hqo011.png"/>



Configuring host names with NMCLI


Rhel6 before host name profile:/etc/sysconfig/network

rhel7.0 hostname profile:/etc/hostname, default does not have this file, the DNS reverse resolution gets the hostname, the hostname defaults to: Localhost.localdomain


Display host name information

Hostname

Hostnamectl status

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/86/FC/wKiom1fQG7Oytc8DAABAj56w640106.png "title=" 10.png "alt=" Wkiom1fqg7oytc8daabaj56w640106.png "/>

Create and modify files and take effect

Hostnamectl Set-hostname desktopX.example.com

Delete the file, restore the host name Localhost.localdomain

DNS settings, stored in the/etc/resolv.conf file

Peerdns=no indicates that DNS is still set manually and not automatically acquired when IP is automatically obtained through DHCP. Equivalent to the following command:

Nmclicon mod "system eth0" Ipv4.ignore-auto-dns Yes


Test network

Test network connectivity at the command line

Display host Name

Hostname

Test network connectivity

Ping

mtr

Display the correct routing table

Iproute

Determine the name server to use:

Nslookup

Host

Dig


Trace Route:

Traceroute

Tracepath




Network Client Tools

LFTP, FTP, Lftpget, wget


LFTP:

The LFTP command is an excellent file client program that supports a variety of file transfer protocols, such as FTP, SETP, HTTP, and FTPs. LFTP Support tab Auto-completion, do not remember the command to double-click the TAB key, you can see the possible options.


Syntax: Lftp[-p port] [-u User[,password]] SERVER

Sub-command:

Get, Mget, LS, help


# ftp:

The FTP command is used to set file system related functions. FTP Server is more common on the Internet, the function of the Linux FTP command is to use the command to control the local and remote computer transfer files, here is a detailed description of the Linux FTP command some of the frequently used commands, I believe that the use of Linux for FTP operations will be very easy.


# Lftpget The url:lftpget command downloads the specified file by invoking the LFTP directive



# wget:

The wget command is used to download files from the specified URL. Wget is very stable, it in the bandwidth is very narrow and unstable network has a strong adaptability, if it is because of network download failure, wget will continue to try, until the entire file download is complete. If the server interrupts the download process, it will again be linked to the server to continue downloading from where it stopped. This is useful for downloading large files from servers that have limited link times.


Syntax: wget[option] ... [URL] ...

-Q: Silent mode

-C: Breakpoint continued to pass

-O: Save location

--limit-rates=: Specifying the transfer rate



This article is from the "I ' m Groot" blog, so be sure to keep this source http://groot.blog.51cto.com/11448219/1847482

NMCLI command usage and network configuration

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.