Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Assign a Static IP for a CentOS 9 or RHEL 9

October 28, 2022
in Blog, Linux
1
ADVERTISEMENT

Table of Contents

In this post, we will cover how to set static IP address on CentOS 9/RHEL 9 systems.

It’s strongly recommended to set static IP address on your Linux system specially on servers. The main benefit of static IP address is that it will be persistent across the reboots.

There are different ways to set static ip address. We can use any one of it.

  • nmcli
  • nmtui
  • nmstatectl

Configure static IP address using nmcli command

1. First, get the interfaces name attached to your system:

nmcli device

In our case, interface and connection name is ens160. So, we will assign following static IP address on this interface ens160.

# nmcli device
DEVICE  TYPE      STATE      CONNECTION
ens160  ethernet  connected  ens160
lo      loopback  unmanaged  --

2. We have two options either modify the existing connection or create a new connection. In this post, we will be modifying the existing connection.

sudo nmcli con modify 'ens160' ipv4.addresses 192.168.1.10/24
sudo nmcli con modify 'ens160' ipv4.gateway 192.168.1.1
sudo nmcli con modify 'ens160' ipv4.dns "1.1.1.1,8.8.8.8"
sudo nmcli con modify 'ens160' ipv4.method manual

3. Restart the network service using the following commands.

Note But if you're connected to the server remotely (SSH), you should restart the server instead of executing the below commands to avoid lost connection to the server.
sudo nmcli con down 'ens160'
sudo nmcli con up 'ens160'

4. Once the server restarted, let’s check to confirms that static ip address along with route and DNS ip are configured successfully.

# nmcli
ens160: connected to ens160
        ethernet (vmxnet3), 00:0C:29:8C:67:D8, hw, mtu 1500
        ip4 default
        inet4 192.168.1.10/24
        route4 192.168.0.0/24 metric 100
        route4 default via 192.168.0.1 metric 0
        inet6 fe80::20c:29ff:fe8c:67d8/64
        route6 fe80::/64 metric 1024

lo: unmanaged
        "lo"
        loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

DNS configuration:
        servers: 1.1.1.1 8.8.8.8
        interface: ens160
# ping google.com -c 3
PING google.com (142.251.220.46) 56(84) bytes of data.
64 bytes from hkg07s50-in-f14.1e100.net (142.251.220.46): icmp_seq=1 ttl=116 time=30.6 ms
64 bytes from hkg07s50-in-f14.1e100.net (142.251.220.46): icmp_seq=2 ttl=116 time=24.5 ms
64 bytes from hkg07s50-in-f14.1e100.net (142.251.220.46): icmp_seq=3 ttl=116 time=25.1 ms

Static IP Address using nmtui utility

Nmtui is a text-based user interface for managing the networking on modern Linux systems.

1. First, run the following command to install NetworkManager Text User Interface nmtui if it is not installed.

sudo dnf -y install NetworkManager-tui

2. Run nmtui tool.

sudo nmtui

3. Select Edit a connection and press Enter.

Bg2203

4. Select the network interface and then Edit.

Bg2205

5. In the following screen, change IPv4 Configuration from Automatic to Manual.

Bg2209

6. Set the IP Address, Gateway and DNS servers then enter OK.

Bg2206

7. To make above changes into the effect, deactivate and activate the connection. 

Note But, if you're connect to the server remotely, you should restart your server instead of deactivate/activate the connection.
ADVERTISEMENT

Assign static IP address using nmstatectl utility

It is also a command line utility to configure networking on CentOS 9/RHEL 9 systems. It’s not installed as a part of default installation. So, first install nmstate package using the following dnf command.

sudo dnf install -y nmstate

1. To view the exiting settings of the interface, run the following command.

sudo nmstatectl show ens160

The output is divided into 4 distinct sections:

  • dns-resolver: This section contains the nameserver configuration for the particular interface.
  • route-rules: This stipulates the routing rules.
  • routes: This includes both dynamic and static routes.
  • interfaces: This section specifies both the ipv4 and ipv6 settings.

You can use the NMState configuration tool to configure your hosts to the desired state using either interactive or file-based modes.

Note But, we recommended you use the file-based mode if you're a newbie.
sudo nmstatectl show ens160
# sudo nmstatectl show ens160
dns-resolver: {}
route-rules: {}
routes:
  running:
  - destination: 0.0.0.0/0
    next-hop-interface: ens160
    next-hop-address: 10.10.0.1
    metric: 100
    table-id: 254
interfaces:
- name: ens160
  type: ethernet
  state: up
  mac-address: 00:0C:29:8C:67:D8
  mtu: 1500
  min-mtu: 60
  max-mtu: 9000
  wait-ip: any
  ipv4:
    enabled: true
    dhcp: true
    address:
    - ip: 10.10.230.16
      prefix-length: 16
    auto-dns: true
    auto-gateway: true
    auto-routes: true
    auto-route-table-id: 0
  ipv6:
    enabled: true
    dhcp: true
  ...

2. Now, create a YAML file that will specify the desired state of your network interface. Then edit it using a text editor.

sudo nmstatectl show ens160 > ens160.yml
vi ens160.yml

3. Copy the below lines and replace with your requirements then paste into the opening yaml file.

interfaces:
- name: ens160				###The interface name
  type: ethernet
  state: up
  ipv4:
    enabled: true
    address:
    - ip: 192.168.1.10			###Assign a static ip
      prefix-length: 24			###Subnet mask 24 = 255.255.255.0
    dhcp: false				###Disable dhcp mode.
dns-resolver:
  config:
    search:
    server:
    - 1.1.1.1				###A DNS server
    - 8.8.8.8				###A DNS server
routes:
  config:
  - destination: 0.0.0.0/0
    next-hop-address: 192.168.1.1	###The default gateway		
    next-hop-interface: ens160

4. Save the file then apply the configuration using the following command:

sudo nmstatectl apply ens160.yml
Note WARNING – You will be disconnected from the remote session if you're ssh to the server.

5. Finally, SSH to the CentOS 9 server using the new IP address then verify everything are working normally.

# ip add show ens160
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:8c:67:d8 brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    inet 192.168.1.10/24 brd 192.168.255.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe8c:67d8/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
# ping bonguides.com -c 3
PING bonguides.com (172.67.143.164) 56(84) bytes of data.
64 bytes from 172.67.143.164 (172.67.143.164): icmp_seq=1 ttl=57 time=46.0 ms
64 bytes from 172.67.143.164 (172.67.143.164): icmp_seq=2 ttl=57 time=43.6 ms
64 bytes from 172.67.143.164 (172.67.143.164): icmp_seq=3 ttl=57 time=34.0 ms
# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 1.1.1.1
nameserver 8.8.8.8

That’s all from this post. We hope it helps you to configure static ip address on your RHEL 9 systems from the command line.

ADVERTISEMENT
5/5 - (2 votes)
Previous Post

How to Make a Variable is Unexpanded in the Heredoc

Next Post

How to Use NMState Networking Config Tool in Linux

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Comments 1

  1. Saleem Ali says:
    5 months ago

    great Tutorial Brother it Worked

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory