Info
Content

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:

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)

CentOS: 

CentOS7:
~]# 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: 
“123.45.67.89 hostname.domain.com hostname
Restart networking on your server to ensure that changes will persist on restart.
3. # /etc/init.d/network restart

Debian


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 hostname.sh 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


Windows


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