How to Configure Static IPv4 Address on AlmaLinux, Rocky Linux, and CentOS using nmcli
A static IP address is an IP address that doesn't change over time. IP (internet protocol) addresses are numerical signifiers that allow data packets to be sent and received from our networks and devices.
If you wish to configure IPv6 as well, checkout this guide How to Configure IPv6 Address on AlmaLinux RockyLinux and CentOS
- If you wish to configure Additional IPs, checkout this guide How to Configure Additional IPs on AlmaLinux RockyLinux and CentOS
Identify the Network Interface
Determine the name of your network interface. You can use the ip a
or ifconfig
command to list available interfaces.
Common names for interface include ens3, eth0, enp3s0 and many more,
ip a
Output:
root@vps ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> 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: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 1.2.3.4 brd ff:ff:ff:ff:ff:ff
altname enp0s3
inet 192.168.0.24/24 brd 192.169.6.255 scope global noprefixroute ens3
valid_lft forever preferred_lft forever
inet6 2604:0456:0145::1/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@vps ~]#
from the above output, the network interface is ens3.
Create the Interface Configuration File
Now that we know our Interface Name, we will navigate to /etc/NetworkManager/system-connections/
directory, where all the NetworkManager's configuration files would be placed.
Create a new .nmconnection
file for your network interface. You can use a text editor, For example, nano
or vi
, to create a file for the ens3 interface,
cd /etc/NetworkManager/system-connections/
nano ens3.nmconnection
In the editor, add the following content, replacing the placeholder values with your actual network configuration:
[connection]
id=MyStaticConnection
type=ethernet
interface-name=ens3
permissions=
[ipv4]
address=192.168.0.24/24
dns=8.8.8.8,8.8.4.4;
gateway=192.168.0.1
method=manual
Note: Replace "interface" ens3 with the actual interface name that is on your server. Replace "address" 192.168.0.24/24 with the actual IP address that is assigned to your server. Replace "gateway" 192.168.0.1 with the actual Gateway address assigned to the server.
You can find the IP address information from CrownPanel, Refer our wiki on How to View Network Information in CrownPanel.
For DNS, you can use the standard Google IP address or from CloudFlare,
- Google: 8.8.8.8, 8.8.4.4
- CloudFlare: 1.1.1.1
Save and exit from the file.
Restart Network Service
Once the configuration file has been updated with the required IP information, we will go onto restart the NetworkManager for the changes to take effect.
systemctl restart NetworkManager
Now, your system should use the static IP address specified in the .nmconnection
file for the specified network interface.
This concludes our topic of configuring Static Network Interface on the AlmaLinux, Rocky Linux, and CentOS Stream 9 using NetworkManager.
CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME
for 10% off!
1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month
Available Locations: LAX | MIA | ATL | FRA | AMS