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 8 or RHEL 8

October 28, 2022
in Blog, Linux
0
ADVERTISEMENT

Table of Contents

Typically, in most network configurations, the IP address is assigned dynamically by the router DHCP server. Setting a static IP address may be required in different situations, such as configuring port forwarding or running a web server behind a NAT.

This post explains how to set up a static IP address on a CentOS 8/RHEL 8 server.

Find the available network interfaces

You can use any one of the below commands to list down the available network interfaces on the system.

ifconfig -a

The command prints a list of all the available network interfaces. In this example, the name of the interface is ens160.

# ifconfig -a
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.10.230.5  netmask 255.255.0.0  broadcast 10.10.255.255
        inet6 fe80::7dc9:cd54:9e9b:6366  prefixlen 64  scopeid 0x20<link>
        ...
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        ...

Configuring the Static IP Address of CentOS 8/RHEL 8

Method 1

1. In this method, we will edit the network interface file found under directory. For interface ens160, the file name would be .

# cat /etc/sysconfig/network-scripts/ifcfg-ens160
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
...
NAME=ens160
UUID=a50387a1-cf51-4ed3-bbd4-a6f253f71e15
DEVICE=ens160
ONBOOT=yes

2. To assign a static IP address to the interface, update the interface file as per the requirement.

vi /etc/sysconfig/network-scripts/ifcfg-ens160
BOOTPROTO=none
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=192.168.1.1
DNS2=8.8.8.8
Note Tip: Press to enter command mode, and then type to write, save and quit the file
  • Set BOOTPROTO: none.
  • Specify the static IP address. Under addresses: you can add one or more IPv4 or IPv6 IP addresses that will be assigned to the network interface.
  • Specify the gateway4.
  • Under nameservers, set the IP addresses of the nameservers.

3. Restart the network service to take the changes go into effect.

systemctl restart NetworkManager.service

4. Use ifconfig -a command to verify the static ip address.

# ifconfig -a
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.255.255
        inet6 fe80::7dc9:cd54:9e9b:6366  prefixlen 64  scopeid 0x20<link>
        ...
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>

Also, verify the DNS server entries in /etc/resolv.conf file.

# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 8.8.8.8
nameserver 1.1.1.1

Finally, verify the internet connectivity using the ping command:

# ping -c 3 google.com
PING google.com (216.58.200.238) 56(84) bytes of data.
64 bytes from tsa03s01-in-f238.1e100.net (216.58.200.238): icmp_seq=1 ttl=58 time=20.2 ms
64 bytes from tsa03s01-in-f238.1e100.net (216.58.200.238): icmp_seq=2 ttl=58 time=20.4 ms
64 bytes from tsa03s01-in-f238.1e100.net (216.58.200.238): icmp_seq=3 ttl=58 time=19.5 ms
ADVERTISEMENT

Method 2

You can also use nmtui, a text-based user interface for configuring network interfaces.

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

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

To make above changes into the effect, deactivate and activate the connection or restart your server.

That’s it! You have assigned a static IP to your CentOS 8 or RHEL 8 server.

ADVERTISEMENT
5/5 - (1 vote)
Previous Post

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

Next Post

How to Restart the Network Service on CentOS 8 or RHEL 8

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

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