Author Photo

Being a Linux Enthusiast and a Fan of Open Source Software, I created Ahmer’s SysAdmin Recipes blog to share my experiences with other System Administrators. The curiosity doesn’t let me stop; therefore, I am constantly trying to learn new software tools and techniques. Whereas I also have the passion and the patience to teach the others.

I am always ready to accept new challenges and wish to explore the areas, that I haven’t worked on. Please give me your feedback and help me improve this blog.

Saturday, 15 December 2018

Configure Network in RHEL/CentOS 7 using nmcli

Configure Network in RHEL CentOS 7 using nmcliIn 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 network on a RHEL/CentOS 7 machine using nmcli.

 

Check Status of Network Devices and Connections:

To check status of current devices.

[root@server1 ~]# nmcli device status
DEVICE       TYPE      STATE         CONNECTION
eno16777728  ethernet  connected     eno16777728
eno33554968  ethernet  disconnected  --
lo           loopback  unmanaged     --

To check status of current connections.

[root@server1 ~]# nmcli connection show
NAME         UUID                                  TYPE            DEVICE
eno16777728  a5c248f9-1118-443e-a2bc-7b2de73afe72  802-3-ethernet  eno16777728

To check complete details about a connection.

[root@server1 ~]# 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

 

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

[root@server1 ~]# nmcli connection modify eno16777728 ipv4.method auto ipv4.addresses "" ipv4.dns ""

Restart connection to apply settings.

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

Check the settings now.

[root@server1 ~]# 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
[root@server1 ~]#

 

2) Static Network Configurations:

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

[root@server1 ~]# 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.

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

Check the settings now.

[root@server1 ~]# 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
[root@server1 ~]#

Configure Network in RHEL/CentOS 7 using nmcli


YOU MIGHT ALSO LIKE:

No comments:

Post a Comment