Difference between revisions of "Linux hostname"
Jump to navigation
Jump to search
Line 3: | Line 3: | ||
In Redhat (RPM) based distros change the hostname permanently by editing: | In Redhat (RPM) based distros change the hostname permanently by editing: | ||
<source lang=bash> | |||
$ vi /etc/sysconfig/network | |||
NETWORKING=yes | |||
HOSTNAME=newHostName | |||
# requires a reboot for eg. Amazon Linux | |||
</source> | |||
In other distros it should be enough to change: | In other distros it should be enough to change: | ||
<source lang=bash> | |||
$ vi /etc/hosts | |||
127.0.0.1 ''newHostName'' | |||
127.0.0.1 localhost localhost.localdomain | |||
::1 localhost localhost.localdomain | |||
</source> | |||
In Ubuntu >14.04 | In Ubuntu >14.04 | ||
<source lang=bash> | |||
$ vi /etc/hosts | |||
127.0.0.1 localhost | |||
127.0.1.1 ''newHostName'' ''newHostName''.home | |||
</source> | |||
Temporarily changing <tt>hostname</tt> can be achieved by the command below then logout and login again to see the effect in bash. | Temporarily changing <tt>hostname</tt> can be achieved by the command below then logout and login again to see the effect in bash. |
Revision as of 12:44, 15 March 2019
In CentOS/Ubuntu and other distros you can control hostname using:
$ hostnamectl set-hostname <new hostname> #in CentOS 7 changes /etc/hostname file that stores centrally the system's hostname
In Redhat (RPM) based distros change the hostname permanently by editing:
$ vi /etc/sysconfig/network NETWORKING=yes HOSTNAME=newHostName # requires a reboot for eg. Amazon Linux
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
In Ubuntu >14.04
$ vi /etc/hosts 127.0.0.1 localhost 127.0.1.1 ''newHostName'' ''newHostName''.home
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