Linux Network Configuration---NMTUI&NMCLI

Source: Internet
Author: User
Tags aliases readable uuid

Network Configuration methods
To configure an interface using the NetworkManager Text user interface tool Nmtui
To configure an interface using the NetworkManager command-line tool NMCLI
To manually configure a network interface
To configure a network using the graphical user interface tool

Nmtui
The Text user interface tool Nmtui can be used to configure interfaces in a terminal window. Issue the following command to start the tool:
?] $ nmtui

Install package
Yum Install Networkmanager-tui

Nmcli
Users and scripts can use the NMCLI utility to control NetworkManager:

 对于服务器,headless machines和终端,nmcli可用于直接控制NetworkManager,无需GUI,包括创建,编辑,启动和停止网络连接以及查看网络状态。 对于脚本,nmcli支持简洁的输出格式,更适合脚本处理。 这是一种集成网络配置而非手动管理网络连接的方法。

The basic format of the NMCLI command is as follows:

Nmcli OPTIONS OBJECT {COMMAND | help}

Where object can be one of the following options: General, networking, radio, connection, device, agent, and monitor. You can use any prefix of these options in the command. For example: Nmcli con help.
-T
This pattern is designed for computer (script) processing.
-P
This causes NMCLI to produce human-readable output. For example, align the values and print the caption.
-H, Help
Print help information.
The NMCLI tool has some built-in context-sensitive Help:
NMCLI Help
This command lists the available options and object names to use in subsequent commands.
Nmcli Object Help
This command displays a list of available actions related to the specified object. For example
NMCLI C Help

The overall state of the NetworkManager:
NMCLI General Status
Current NetworkManager log record status:
NMCLI General Logging
All connections:
NMCLI Connection Show
Only the currently active connection, add the--active (or-a) option as follows:
NMCLI Connection Show--active
NetworkManager identified devices and their status:
NMCLI Device status

Start and stop interfaces using NMCLI
The NMCLI tool can be used to start and stop any network interface
NMCLI con up ID bond0
NMCLI con up ID port0
NMCLI Dev Disconnect Bond0
NMCLI Dev Disconnect Ens3

The NMCLI connection down command is used to deactivate the connection of the device without preventing further automatic activation of the device.
The NMCLI Device Disconnect command is used to disconnect the device and prevent the device from automatically activating other connections without human intervention.

NMCLI Interactive Connection Editor
The NMCLI tool has an interactive connection editor. To use it, enter the following command:

?] $ nmcli con Edit

You will be prompted to enter a valid connection type from the list that appears. After entering the connection type, you will be placed at the NMCLI prompt. If you are familiar with the connection type, you can add a valid connection type option to the nmcli con Edit command and go directly to the NMCLI prompt. Edit the existing connection configuration file in the following format:

Nmcli con edit [ID | uuid |path] ID

To edit a new connection profile, the following format applies:

Nmcli con edit [Type new-connection-type] [con-name New-connection-name]

At the NMCLI prompt, type help to see a list of valid commands. Use the describe command to get a description of the settings and their properties. The format is as follows:

Describe Setting.property

For example:

Nmcli> describe Team.config

Create and modify a connection configuration file
The connection profile contains the Connection property information that is required to connect to the data source. To create a new configuration file for NetworkManager, use the following command:

Nmcli c Add {ARGUMENTS}

NMCLI C Add accepts two different types of parameters:

 NetworkManager用于在内部描述连接的名称。 最重要的是:

Connection.type
NMCLI C Add Connection.type Bond

    connection.interface-name    nmcli c add connection.interface-name eth0    connection.id    nmcli c add connection.id "My Connection"     有关属性及其设置的更多信息,请参见man nm-settings

Alias
A human-readable name translated internally into a property. The most common are:
Type (the Connection.type property)

    nmcli c add type bond    ifname (the connection.interface-name property)    nmcli c add ifname eth0    con-name (the connection.id property)    nmcli c add con-name "My Connection"

In previous versions of NMCLI, the required connections were created using aliases. For example, ifname eth0 and Con-name My Connection. You can use commands in the following format:
NMCLI c Add type Ethernet ifname eth0 con-name "My Connection"

In newer versions, property names and aliases can be used interchangeably. The following examples are valid and equivalent:
NMCLI c Add type Ethernet ifname eth0 con-name "My Connection" ETHERNET.MTU 1600

NMCLI C Add connection.type Ethernet ifname eth0 con-name "My connection" ETHERNET.MTU 1600

NMCLI C Add connection.type Ethernet connection.interface-name eth0 connection.id "My connection" ETHERNET.MTU 1600

Parameters vary depending on the type of connection. For all connection types, only the type parameter is required, and ifname is required for all types except Bond,team,bridge and VLANs.

Type type_name
The connection type. For example:

NMCLI C Add Type Bond

IfName interface_name
The interface used to bind the connection. For example:
Nmcli C ADD ifname interface_name type Ethernet

To modify one or more properties of a connection configuration file, use the following command:
NMCLI C Modify

For example, to change connection.id from my connection to my favorite connection and connection.interface-name to eth1, issue the command as follows:

Nmcli C Modify "My Connection" connection.id "My favorite Connection" Connection.interface-name eth1

Attention
It is best to use property names. Aliases are used only for compatibility reasons.

Also, to set the Ethernet MTU to 1600, modify the size as follows:
Nmcli C Modify "My Favorite Connection" ETHERNET.MTU 1600

Connection.type
The connection type. The allowed values are: Adsl,bond,bond-slave,bridge,bridge-slave,bluetooth,cdma,ethernet,gsm,infiniband,olpc-mesh,team, Team-slave,vlan,wifi,wimax. Each connection type has a type-specific command option. You can see the list of type_specific_options in the NMCLI (1) manual page. For example:

    gsm连接需要apn中指定的访问点名称。    nmcli c add connection.type gsm apn access_point_name wifi设备需要ssid中指定的服务集标识符。

NMCLI c add connection.type wifi SSID My identifier

Connection.interface-name
The name of the device associated with the connection.
Nmcli con add connection.interface-name eth0 type Ethernet

Connection.id
The name to use for the connection configuration file. If you do not specify a connection name, the following connection name is generated:
Connection.type-connection.interface-name
Connection.id is the name of the connection configuration file and should not be confused with the interface name (WLAN0,ENS3,EM1) that represents the device. However, users can name connections after an interface, but they are not the same thing. You can provide multiple connection profiles for your device. This is especially useful for mobile devices or for switching network cables back and forth between different devices. Instead of editing the configuration, create different configuration files and apply them to the interface as needed. The ID option also references the connection configuration file name.

The most important options for NMCLI commands, such as Show,up,down, are:
Id
The identity string that the user assigns to the connection profile. You can use the ID in the NMCLI Connection command to identify the connection. The Name field in the command output always represents the connection ID. It refers to the same connection profile name that Con-name has.
Uuid
The unique identification string that the system assigns to the connection configuration file. You can use the UUID in the NMCLI Connection command to identify the connection.

~]$ nmcli Con Show
NAME UUID TYPE DEVICE
Auto Ethernet 9b7f2511-5432-40ae-b091-af2457dfd988 802-3-ethernet--
ENS3 FB157A65-AD32-47ED-858C-102A48E064A2 802-3-ethernet ENS3
Mywifi 91451385-4EB8-4080-8B82-720AAB8328DD 802-11-wireless Wlan0
Note that the Name field in the output always represents the connection ID (name). It is not an interface name, even though it may look the same. In the second connection shown above, the ENS3 in the Name field is the connection ID of the user to the profile that is applied to the interface ens3. In the last connection shown, the user has the connection ID?? The Mywifi is assigned to the interface Wlan0.

Adding an Ethernet connection means creating a configuration profile and assigning it to a device. Before you create a new profile, view the available devices as follows:
~]$ NMCLI Device status
DEVICE TYPE State CONNECTION
ENS3 Ethernet Disconnected--
ENS9 Ethernet Disconnected--
Lo Loopback unmanaged--
To set the device to be not managed by NetworkManager:
$ NMCLI Device SET ifname managed No

For example, to set eth2 unmanaged:
$ NMCLI Device status
DEVICE TYPE State CONNECTION
Bond0 Bond connected Bond0
Virbr0 Bridge Connected Virbr0
Eth1 Ethernet Connected Bond-slave-eth1
Eth2 Ethernet Connected Bond-slave-eth2
Eth0 Ethernet Unmanaged--

$ NMCLI Device Set eth2 managed no---->set eth2 unmanaged:
$ NMCLI Device status
DEVICE TYPE State CONNECTION
Bond0 Bond connected Bond0
Virbr0 Bridge Connected Virbr0
Eth1 Ethernet Connected Bond-slave-eth1
Eth2 Ethernet Unmanaged--
Eth0 Ethernet Unmanaged--
When you set the device to unmanaged, NetworkManager does not control it. However, the device is still connected.

Add a dynamic Ethernet connection
To add an Ethernet configuration file with dynamic IP configuration, allowing DHCP to assign network configuration, you can use commands in the following format:
NMCLI Connection Add type Ethernet con-name CONNECTION-NAME ifname interface-name

For example, to create a dynamic connection profile named My-office, issue the command as follows:
?] $ nmcli con Add type Ethernet con-name MY-OFFICE ifname ENS3

NetworkManager set its internal parameter connection.autoconnect to Yes. NetworkManager also writes the settings to/Etc/sysconfig/network-scripts/ifcfg-my-office, where the onboot instruction is set to Yes.

Note that NetworkManager will not notice manual changes to the Ifcfg file until the next time the interface is started.
To open an Ethernet connection, issue the following command:
~]$ nmcli con up my-office

To change the host name sent by the host to a DHCP server, modify the Dhcp-hostname property as follows:
?] $ nmcli con Modify my-office my-office ipv4.dhcp-hostname host-name ipv6.dhcp-hostname host-name

To change the IPV4 client ID sent by the host to a DHCP server, modify the Dhcp-client-id property as follows:
?] $ nmcli con Modify my-office my-office ipv4.dhcp-client-id client-id-string

IPV6 has no Dhcp-client-id property, Dhclient creates an identifier for IPV6. For more information, see the Dhclient (8) man page.
to ignore the DNS server that the DHCP server sends to the host, modify the Ignore-auto-dns property as follows:
?] $ nmcli con Modify my-office my-office ipv4.ignore-auto-dns Yes Ipv6.ignore-auto-dns Yes

For more information about properties and their settings, see the Nm-settings (5) man page.

Add a static Ethernet connection
To add an Ethernet connection using a static IPV4 configuration, you can use a command in the following format:
You can add IPV6 address and gateway information using the IP6 and GW6 options.
Note that this replaces any previously provisioned DNS servers. Or, to add additional DNS servers to any previous settings, use the + prefix as follows:

?] $ nmcli Con mod test-lab + ipv4.dns "8.8.8.8 8.8.4.4"

To view more information about a newly configured connection, issue the command as follows:
~]$ nmcli-p con Show Test-lab
                 Connection profile details (test-lab)

===============================================================================
Connection.id:test-lab
connection.uuid:05abfd5e-324e-4461-844e-8501ba704773
Connection.interface-name:ens9
Connection.type:802-3-ethernet
Connection.autoconnect:yes
connection.timestamp:1410428968
Connection.read-only:no
Connection.permissions:
Connection.zone:--
Connection.master:--
Connection.slave-type:--
Connection.secondaries:
connection.gateway-ping-timeout:0
[Output TRUNCATED]
With-P, the-pretty option adds heading banners and section breaks to the output.

To lock a profile to a specific device
To lock the configuration file to a specific interface device, the command used in the example above includes the interface name. For example:
NMCLI Connection Add type Ethernet con-name CONNECTION-NAME ifname interface-name

To make the configuration file available to all compatible Ethernet interfaces, issue the following command:
NMCLI Connection Add type Ethernet con-name CONNECTION-NAME ifname "*"

Note that you must use the ifname parameter even if you do not want to set a specific interface. Use wildcards to specify that a configuration file can be used with any compatible device.
To lock a profile to a specific MAC address, use a command in the following format:
NMCLI Connection Add type Ethernet con-name "Connection-name" ifname
"" Mac 00:00:5e:00:53:00

Add a WiFi connection
To create a Wi-Fi connection profile with a static IP configuration, but allow DNS addresses to be automatically assigned, issue the command as follows:
?] $ nmcli con add con-name mycafe ifname wlan0 type WiFi SSID mycafe \
IP4 192.168.100.101/24 gw4 192.168.100.1

To set the WPA2 password, such as "caffeine", issue the following command:
~]$ nmcli con Modify Mycafe wifi-sec.key-mgmt WPA-PSK
~]$ nmcli con Modify mycafe wifi-sec.psk caffeine
To change your Wi-Fi status, issue the command in the following format:
~]$ NMCLI Radio WiFi [on | off]

Change specific properties
To check for specific properties, such as MTU, issue the command as follows:
~]$ NMCLI connection Show id ' Mycafe ' | grep MTU
802-11-wireless.mtu:auto
To change the properties of a setting, issue a command as follows:
~]$ NMCLI Connection Modify ID ' mycafe ' 802-11-wireless.mtu 1350
To verify your changes, issue the command as follows:
~]$ NMCLI connection Show id ' Mycafe ' | grep MTU
802-11-wireless.mtu:1350
Note that NetworkManager sets parameters (such as 802-3-ethernet and 802-11-wireless) as settings, and the MTU as the set property. For more information about properties and their settings, see the Nm-settings (5) man page.

Configuring static routes with NMCLI
To configure a static route for an existing Ethernet connection using the command behavior, enter the following command:
?] #nmcli Connection Modify eth0 + ipv4.routes "192.168.122.0/24 10.10.10.1"
This directs traffic to the 192.168.122.0/24 subnet to the 10.10.10.1 gateway

Linux Network Configuration---NMTUI&NMCLI

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.