In this article, we will review how to change DNS settings using nmcli. In RHEL7 and CentOS7, modifying the ifcfg scripts or /etc/resolv.conf files directly
Discover the convenient and efficient way to change IPv4 addresses on your Linux machine using the nmcli utility, and take control of your network settings with ease.
Changing IPv4 addresses using the nmcli utility is a useful way to manage network connections on a Linux system. Here’s a step-by-step guide on how to change IPv4 addresses using the nmcli utility, with at least three different ways to accomplish each step.
We’ll be taking a similar approach as our previous article on changing DNS settings, this time delving into the process of changing IPv4 addresses using the NMCLI Utility specifically on RHEL or CentOS operating systems.
Before changing the IPv4 address, it’s important to check the current network configuration to ensure you know what you’re changing. Here are three different ways to do this:
The easiest way to check the current network configuration is to use the nmcli
command:
$ nmcli connection show
This command will display a list of all the network connections on your system. Find the name of the connection you want to modify and note it down.
Another way to check the current network configuration is to use the ip addr
command:
$ ip addr show
This command will display the IP addresses and network interfaces on your system. Find the interface you want to modify and note it down.
A third way to check the current network configuration is to use the ifconfig
command:
NOTE: As of the RHEL 7 release, the ifconfig
command is no longer available by default and requires the net-tools package to be installed using either yum or dnf, depending on your operating system.
$ ifconfig
This command will display the IP addresses and network interfaces on your system. Find the interface you want to modify and note it down.
$ ifconfig
enp1s0: flags=4163 mtu 1500
inet 192.168.1.21 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::ad2:4604:a246:e4e7 prefixlen 64 scopeid 0x20
ether 52:54:00:16:04:9c txqueuelen 1000 (Ethernet)
RX packets 3243495 bytes 2375068065 (2.2 GiB)
RX errors 0 dropped 655879 overruns 0 frame 0
TX packets 150113 bytes 11491248 (10.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73 mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 10 bytes 900 (900.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 900 (900.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
$ ip addr show
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:16:04:9c brd ff:ff:ff:ff:ff:ff
inet 192.168.1.21/24 brd 192.168.1.255 scope global noprefixroute enp1s0
valid_lft forever preferred_lft forever
inet6 fe80::ad2:4604:a246:e4e7/64 scope link noprefixroute
valid_lft forever preferred_lft forever
Now that you know the name of the connection or interface you want to modify, you can change the IPv4 address associated with it. Here are three different ways to do this:
The easiest way to modify the IPv4 address is to use the nmcli
command:
$ sudo nmcli connection modify ipv4.addresses / ipv4.gateway
Replace the following to match your environment or network settings:
<connection_name>
with the name of the connection you want to modify.<new_ip_address>
with the new IP address you want to assign to the connection.<subnet_mask>
with the subnet mask for the new IP address.<new_gateway_ip>
with the new gateway IP address you want to use.Another way to modify the IPv4 address is to use the ifconfig
command:
$ sudo ifconfig netmask
Change the following to match your environment or network or settings:
<interface_name>
with the name of the interface you want to modify.<new_ip_address>
with the new IP address you want to assign to the interface.<subnet_mask>
with the subnet mask for the new IP address.A third way to modify the IPv4 address is to use the ip addr
command:
$ sudo ip addr add / dev
Similarly, the ip addr
command performs the same function as the ifconfig
command and it’s the new standard for RHEL versions 7, 8 and 9.
After modifying the network configuration, you need to apply the changes by restarting the network service. Here are three different ways to do this:
The easiest way to apply the changes is to use the systemctl
command:
$ sudo systemctl restart NetworkManager.service
This command will restart the NetworkManager service, which will apply the changes to the network configuration.
Another way to apply the changes is to use the service
command:
$ sudo service NetworkManager restart
It performs the same function as the systemctl
command and restarts the NetworkManager service, which applies changes to the network configuration.
A third way to apply the changes is to use both systemctl
and nmcli
:
$ sudo systemctl restart NetworkManager.service
$ sudo nmcli connection reload
These commands will ensure that network configuration changes remain persistent even after system reboots.
Finally, it’s important to verify that the changes have been applied correctly. Here are three different ways to do this:
The most common way (in the more recent versions of RHEL and CentOS) to verify the changes is to use the nmcli
command:
$ sudo nmcli connection show
Replace <connection_name>
with the name of the connection you modified. This command will display the details of the connection, including the new IPv4 address.
Another way to verify changes is to use the ip addr
command:
$ sudo ip addr show
Replace <interface_name>
with the name of the interface you modified. This command will display the IP addresses and network interfaces on your system, including the new IPv4 address.
A third way to verify the changes is to ping a remote host:
$ ping
Replace <remote_host>
with the IP address or hostname of a remote host. If the ping is successful, the changes have been applied correctly and the network connection is working. If the ping fails, there may be an issue with the network configuration.
In summary, changing IPv4 addresses using the nmcli utility involves several steps:
nmcli connection show | Identify the connection you want to modify using the |
nmcli connection modify | Modify the IPv4 address using the |
nmcli connection up , sudo service network-manager restart , or sudo systemctl restart NetworkManager.service && sudo nmcli connection reload . | Apply the changes using one of three methods: |
nmcli connection show , ip addr show , or ping . | Verify the changes using one of three methods: |
We also provided three different ways to accomplish each step to give users more flexibility and options depending on their preferences and familiarity with different commands.
Was this article helpful to you? If so, leave us a comment below and share!
Related Posts
In this article, we will review how to change DNS settings using nmcli. In RHEL7 and CentOS7, modifying the ifcfg scripts or /etc/resolv.conf files directly
With our step-by-step guide, you can easily build your own RPM packages in Linux on RHEL and CentOS, and efficiently manage software updates and installations.
Learn about the differences between NMCLI and NMTUI, two powerful tools for managing network connections on Linux systems, and discover which one is best suited