Forums » Education

Changing the Hostname in CentOS 7 for mynumer.com

  • March 27, 2023 6:42 PM +06

    Hello everyone,

    I am in the process of setting up a new website called mynumer.com, which is running on CentOS 7. I realized that the current hostname is not meaningful and doesn't represent the purpose of my website. So, I want to change it to something more appropriate.

    After doing some research, I found that changing the hostname in CentOS 7 is a relatively straightforward process. Here are the steps I followed:

    Step 1: Log in as Root To change the hostname in CentOS 7, you need to log in as the root user. You can do this using the following command:

    sudo su

    Step 2: Edit the Hostname File The hostname file is located in the /etc directory. Use the following command to open the hostname file:

    nano /etc/hostname

    In the file, replace the existing hostname with the new hostname that you want to set.

    Step 3: Edit the Hosts File Next, you need to edit the hosts file using the following command:

    nano /etc/hosts

    In the hosts file, you will see the old hostname followed by the IP address. Replace the old hostname with the new one you just set in the hostname file.

    Step 4: Restart the System To make the changes take effect, you need to restart the system. Use the following command:

    systemctl reboot

    After the system reboots, the new hostname will be applied.

    I hope this helps anyone who needs to change the hostname in CentOS 7 for their website, like I did for mynumer.com. If you have any questions or need further assistance, feel free to ask in the comments.