Latest

Saturday, 15 December 2018

Configure RHEL/CentOS 7 Network with nmcli Command

Configure Network in RHEL CentOS 7 using nmcli

In RHEL/CentOS 7, by default network has been managed by the Network Manager. And we know that graphical mode is not available on the server, therefore, configuring network on a newly installed Linux machine can be a difficult task, if we are not familiar with the Network Manager command-line utilities i.e. nmtui and nmcli.

We prefer to work from CLI, therefore we will use nmcli. However, you may use nmtui as well.

In this article, we will configure dymanic and static RHEL/CentOS 7 network with nmcli command.

 

Table of Contents:

Configure Network in RHEL CentOS 7 using nmcli

Check Status of Network Devices and Connections:

To check status of current devices.

# nmcli device status
DEVICE       TYPE      STATE         CONNECTION
eno16777728  ethernet  connected     eno16777728
eno33554968  ethernet  disconnected  --
lo           loopback  unmanaged     --

To check status of current connections.

# nmcli connection show
NAME         UUID                                  TYPE            DEVICE
eno16777728  a5c248f9-1118-443e-a2bc-7b2de73afe72  802-3-ethernet  eno16777728

To check complete details about a connection.

# nmcli connection show eno16777728 | grep ipv4
ipv4.method:                            manual
ipv4.dns:                               192.168.116.2
ipv4.dns-search:
ipv4.addresses:                         { ip = 192.168.116.11/24, gw = 192.168.116.2 }
ipv4.routes:
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes

 

Dynamic Network Configurations:

Currently, the IPv4 address of the above system is set statically. To change it to dynamically obtain an IP address from available DHCP Server.

# nmcli connection modify eno16777728 ipv4.method auto ipv4.addresses "" ipv4.dns ""

Restart connection to apply settings.

# nmcli connection down eno16777728 ; nmcli connection up eno16777728
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)

Check the settings now.

# nmcli connection show eno16777728 | grep ipv4
ipv4.method:                            auto
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:
ipv4.routes:
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes

 

Static Network Configurations:

To configure a network connection statically, we can use the same nmcli command with different parameters.

# nmcli connection modify eno16777728 ipv4.method manual ipv4.addresses "192.168.116.11/24 192.168.116.2" ipv4.dns 192.168.116.2

Restart connection to apply settings.

# nmcli connection down eno16777728 ; nmcli connection up eno16777728
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)

Check the settings now.

# nmcli connection show eno16777728 | grep ipv4
ipv4.method:                            manual
ipv4.dns:                               192.168.116.2
ipv4.dns-search:
ipv4.addresses:                         { ip = 192.168.116.11/24, gw = 192.168.116.2 }
ipv4.routes:
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes

We have configured network in RHEL/CentOS 7 using nmcli command.

If you find this article useful? Don't you mind support us by Buy Me A Coffee


No comments:

Post a Comment

© 2022 CentLinux. All Rights Reserved.