Change Hostname in Linux & Windows

Change Hostname (computer name) in Linux & Windows

You can use the hostname command to see or set the system’s host name. The host name or computer name is usually at system startup in /etc/hostname file. Open the terminal application and type the following command.

To show current hostname simply type the following command:
$ hostname


Ubuntu Linux 16.04 LTS or above:

$ hostnamectl set-hostname 'typehostnamehere'

older Ubuntu versions:
Delete the old name and setup new name.
1. sudo nano /etc/hostname 
Next Edit the /etc/hosts file:
2. sudo nano /etc/hosts
3. sudo reboot (Reboot the system to changes take effect)


~]# hostnamectl set-hostname name

CentOS6 or lower

Delete the old name and setup new name. Change the name after HOSTNAME=
1. # sudo nano /etc/sysconfig/network
2. Next Edit the /etc/hosts file: 
“ hostname
Restart networking on your server to ensure that changes will persist on restart.
3. # /etc/init.d/network restart


1. Update /etc/hostname
2. Update /etc/hosts so local address(es) resolves with the new system name.
3. Reload configuration files
This will temporarily disconnect your system from the network (SSH usually resists short disconnection)
invoke-rc.d start
invoke-rc.d networking force-reload|
invoke-rc.d network-manager force-reload
-> Or the lazy way: Restart the system.

With systemd it is possible to use a single command as follows:
# hostnamectl set-hostname machine-name-here
# hostnamectl set-hostname server2


1. We’re going to go with the easiest way. Hit Start, type “sysdm.cpl,” and then click the “sysdm.cpl” entry.
2. In the “System Properties” window, on the “Computer Name” tab, click the “Change” button.
3. Windows will now need to restart, so save any files you have open, and then click “OK.”

No Comments
Back to top