How do you set up a static IP address in CentOS?

Learn how to easily set up a static IP address in CentOS with our step-by-step guide. Ensure stable network connections for your system.

How do you set up a static IP address in CentOS?

Setting up a Static IP Address in CentOS

Configuring a static IP address in CentOS involves modifying network configuration files. Follow the steps below to set up a static IP address on your CentOS system:

Step 1: Locate Network Configuration Files

Network configuration files are located in the /etc/sysconfig/network-scripts directory. The primary configuration file for network interfaces is typically named ifcfg-interface_name, where interface_name is the name of the network interface you want to configure (e.g., ifcfg-eth0).

Step 2: Edit the Configuration File

Open the appropriate configuration file using a text editor. You can use tools like vi or nano to edit the file.

sudo vi /etc/sysconfig/network-scripts/ifcfg-interface_name

Step 3: Configure the Static IP Address

Within the configuration file, you need to specify the following parameters to set up a static IP address:

  • DEVICE: Name of the network interface (e.g., eth0).
  • BOOTPROTO: Set this to static to configure a static IP address.
  • IPADDR: The static IP address you want to assign to the interface.
  • NETMASK: The subnet mask for the IP address.
  • GATEWAY: The default gateway for the network.
  • DNS1: Primary DNS server IP address.
  • DNS2: Secondary DNS server IP address (optional).

For example, a sample configuration file for eth0 with a static IP address might look like this:

DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
ONBOOT=yes

Step 4: Save and Close the File

After making the necessary changes, save the file and exit the text editor.

In vi, you can save and close the file by pressing Esc followed by :wq and then Enter.

Step 5: Restart the Network Service

Once you have configured the static IP address, you need to restart the network service for the changes to take effect.

sudo systemctl restart network

Step 6: Verify the Configuration

You can verify that the static IP address has been successfully configured by checking the network settings using commands like ifconfig or ip addr show.

ifconfig interface_name
ip addr show interface_name

Step 7: Test Connectivity

After setting up the static IP address, test the network connectivity to ensure that your CentOS system can communicate with other devices on the network.

ping destination_ip

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow