How to Set Hostname for Linux Machine

Here is a small trick for defining a fix 'hostname' for linux machine. Sometimes we face a problem that 'hostname' keeps on changing for Linux machine. At first level, you can check with /etc/hosts, if settings are proper there. The contents should be like:

127.0.0.1               localhost.localdomain localhost
::1                          localhost6.localdomain6 localhost6

But sometimes, even after having these settings fine, we still face above problem.

Next level of quick fix for this problem is given below:

  • Open /etc/rc.local
  • Add following lines  in this file
  • hostname localhost.localdomain (or any other hostname if you want)
  • Save the file
  • Restart the system
This file runs in the last during network configuration (at the time of login) hence any setting which is written here will take effect finally. So whatever in your system would be affecting the hostname, will be overridden here. And you will get the right 'hostname'.

People who read this post also read :



1 comments:

Mohit Gupta said...

You can also try by

Open /etc/NetworkManager/NetworkManager.conf or /etc/NetworkManager/nm-system-settings.conf
Add following lines, if not there already
[keyfile]
hostname=localhost.localdomain

-------
See if it can help

Post a Comment