How to change the hostname in Linux

This article describes the how the change the hostname in Linux machine.

Let’s start.

  • Open the network file.
 # sudo vi /etc/sysconfig/network
  • Modify the HOSTNAME= value with your domain name. Example hostname is “myhostname”
HOSTNAME = myhostname
  • To access with in the server add it in /etc/hosts file myhostname
  • Run the “hostname” command. This command lets you change the hostname on the server that the command line remembers, but it does not actively update all programs that are running under the old hostname.
[root ~]# hostname myhostname 
[root]# hostname 
[root ~]#
  • Restart networking on your server to ensure that changes will persist on restart.
# /etc/init.d/network restart

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.