Easily Configure a static IP address on Oracle Linux

Configuring a static IP address is an essential task when setting up a server, as it ensures that the IP address remains constant, even after rebooting. In this blog article, we will discuss how to configure a static IP address in Oracle Linux.

Configure a static IP address

Step 1: Check the current IP Before configuring a static IP, we need to check the current IP address of the server. There are various commands to check the IP address, such as “ip a”, “ifconfig”, or “ip addr”. Here’s an example:

ip addr

Step 2: Configure Static IP After checking the current IP address, we can proceed to configure a static IP address. Navigate to the network-scripts directory using the following command:

cd /etc/sysconfig/network-scripts/

In this directory, we will find the configuration files for network interfaces. We need to edit the appropriate file for the interface we want to configure, such as “ifcfg-eth0”. Here’s an example of how to edit this file using the nano editor:

nano ifcfg-eth0

In the file, update/edit the following parameters:

# static IP address on Oracle Linux
HWADDR=00:08:A2:0A:BA:B8
TYPE=Ethernet
BOOTPROTO=none
# Server IP #
IPADDR=192.168.2.203
# Subnet #
PREFIX=24
# Set default gateway IP #
GATEWAY=192.168.2.254
# Set DNS servers #
DNS1=192.168.2.254
DNS2=8.8.8.8
DNS3=8.8.4.4
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
# Disable IPv6 #
IPV6INIT=no
NAME=eth0
# This is system-specific and can be created using the 'uuidgen eth0' command #
UUID=41171a6f-bce1-44de-8a6e-cf5e782f8bd6
DEVICE=eth0
ONBOOT=yes

Here are the explanations for each parameter:

  • HWADDR: The MAC address of the interface.
  • TYPE: The type of interface, which is Ethernet in this case.
  • BOOTPROTO: The protocol used for booting, which is set to none since we are using a static IP address.
  • IPADDR: The IP address we want to assign to the interface.
  • PREFIX: The subnet mask of the network, which is set to 24 in this example.
  • GATEWAY: The default gateway IP address.
  • DNS1, DNS2, DNS3: The IP addresses of the DNS servers.
  • DEFROUTE: Whether to configure the default route for this interface.
  • IPV4_FAILURE_FATAL: Whether to fail the interface when an IPv4 error occurs.
  • IPV6INIT: Whether to enable IPv6 for this interface.
  • NAME: The name of the interface, which is eth0 in this example.
  • UUID: A unique identifier for the interface, which can be generated using the “uuidgen eth0” command.
  • DEVICE: The name of the device, which is eth0 in this example.
  • ONBOOT: Whether to configure the interface at boot time.

Step 3: Change DNS Server To change the DNS server, edit the “/etc/resolv.conf” file using the following command:

nano /etc/resolv.conf
Check This Also: Easily Disable Weak Algorithms in OpenSSH (Oracle Linux)

Add the following line, replacing <dns-server> with the IP address of the DNS server:

nameserver <dns-server>

Save and close the file.

Step 04: Restart networking service After making the changes, restart the networking service to apply the new network configuration:

systemctl restart network

This will restart the networking service and apply the changes.

Step 05: Verify that the new network configuration is applied by checking the IP address using any of the following commands:

ip a
ifconfig
ip addr

The output of any of the above commands should show the new static IP address that you configured.

Congratulations! You have successfully configured a static IP address on Oracle Linux.

Leave a Reply

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