Hostname

Hostname

Show your hostname

You can type in hostname command to see the current hostname in this machine.

hostname

Change hostname

1. Change hostname

You can edit /etc/hostname file by using your editor. And change the hostname to whatever you want.

sudo vim /etc/hostname

The new hostname file content will looks like this:

# /etc/hostname
kejyun-host-name

2. Add hostname’s ip address

If you are using the hostname as a service hostname, you can mapping the new hostname to 127.0.0.1 ip address.

sudo vim /etc/hosts
# /etc/hosts
127.0.0.1 kejyun-host-name

3. Force to change your hostname

After finish change the hostname. You can run a command to force your machine to update their hostname. Then you can see your new hostname after you re-login your system.

sudo hostname -F /etc/hostname
kj@kejyun-host-name:~$

Reference