Linux hostname

From Ever changing code
Revision as of 21:51, 17 February 2015 by Pio2pio (talk | contribs) (Created page with "In CentOS you can control <tt>hostanem</tt> using $ '''hostnamectl set-hostname''' ''<new hostname>'' In Redhat (RPM) based distros change the hostname permanently by editi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In CentOS you can control hostanem using

$ hostnamectl set-hostname <new hostname>

In Redhat (RPM) based distros change the hostname permanently by editing:

$ vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=newHostName

In other distros it should be enough to change:

$ vi /etc/hosts
127.0.0.1 newHostName
127.0.0.1   localhost localhost.localdomain
::1         localhost localhost.localdomain

Temporarily changing hostname can be achieved by the command below then logout and login again to see the effect in bash.

$ hostname newHostName
Restart networking

If you changed /etc/hosts or /etc/sysconfig/network file you want to restart networking to ensure that changes will be persistent on reboot:

$ /etc/init.d/network restart        # Redhat based
$ sudo service networking restart    # Debian/Ubuntu distros