How to Change IP Address and Hostname on a Red Hat 8 Server

In the world of server administration, it’s quite common to need to change the IP address or hostname of a server. Whether it’s for network reconfiguration, setting up a development environment, or deploying a new server, understanding how to make these changes is crucial. In this blog post, we’ll walk you through how to alter the IP address and hostname on a Red Hat 8 server.

Changing the IP Address

The IP address of a Red Hat 8 server can be updated using the NetworkManager’s command-line tool, nmcli, or by directly editing the appropriate network configuration file.

Using nmcli

Here are the steps to alter the IP address using nmcli:

  1. Identify the existing connections with nmcli con show.
  2. Note the NAME of the connection you want to modify. For this example, assume the connection name is eth0.
  3. Update the IP address, gateway, and DNS servers using nmcli con mod:
nmcli con mod eth0 ipv4.addresses "192.168.1.100/24"
nmcli con mod eth0 ipv4.gateway "192.168.1.1"
nmcli con mod eth0 ipv4.dns "8.8.8.8,8.8.4.4"
  1. Modify the method to manual with nmcli con mod eth0 ipv4.method manual.
  2. Apply the changes and restart the network connection with nmcli con up eth0.

Directly Modifying the Configuration File

Another way to change the IP address is by modifying the configuration file directly:

  1. Open the configuration file for your network interface, which is typically named ifcfg-<interface_name> and located in /etc/sysconfig/network-scripts/.
  2. Change the BOOTPROTO line to static.
  3. Add the IP address, netmask, gateway, and DNS settings.
  4. Save the changes and restart the network service with sudo systemctl restart NetworkManager.

Changing the Hostname

You can also change the hostname of your Red Hat 8 server, either by using the hostnamectl command or by editing the /etc/hostname file directly.

Using hostnamectl

The hostnamectl command allows you to view and change the system hostname. To change the hostname, use:

sudo hostnamectl set-hostname new_hostname

Then, verify the changes with hostnamectl.

Directly Modifying the /etc/hostname File

Alternatively, you can manually edit the /etc/hostname file and replace the current hostname with your new one. To apply the changes immediately, use the hostnamectl command as described above.

Remember to update the /etc/hosts file so that the system can resolve the new hostname to the localhost IP address. Add your new hostname at the end of the line starting with 127.0.0.1.

With these steps, you can efficiently manage your Red Hat 8 server’s IP address and hostname settings. This knowledge will help you navigate various scenarios in your server administration tasks.

Leave a comment

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