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.
Display the current Ubuntu hostname
Simply type the following command:
Sample outputs:
$ hostname
Sample outputs:
Ubuntu change hostname command
The procedure to change the computer name on Ubuntu Linux:
- Type the following command to edit /etc/hostname using nano or vi text editor:
sudo nano /etc/hostname
Delete the old name and setup new name. - Next Edit the /etc/hosts file:
sudo nano /etc/hosts
Replace any occurrence of the existing computer name with your new one. - Reboot the system to changes take effect:
sudo reboot
Sample outputs:
How to change the Ubuntu server hostname without a system restart?
Type the following commands:
Next edit the /etc/hostname file and update hostname:
Finally, edit the /etc/hosts file and update the lines that reads your old-host-name:
From:
To:
Save and close the file.
$ sudo hostname new-server-name-here
Next edit the /etc/hostname file and update hostname:
$ sudo nano /etc/hostname
Finally, edit the /etc/hosts file and update the lines that reads your old-host-name:
$ sudo nano /etc/hosts
From:
127.0.1.1 old-host-name
To:
127.0.1.1 new-server-name-here
Save and close the file.
A note about hostnamectl command
Systemd based Linux distor such as Ubuntu Linux 16.04 LTS and above can simply use the hostnamectl command to rename hostname. To see current setting just type:
Sample outputs:
$ hostnamectl
Sample outputs:
To change hostname from nixcraft to viveks-laptop, enter:
$ hostnamectl set-hostname viveks-laptop
$ hostnamectl
Sumber: https://www.cyberciti.biz/faq/ubuntu-change-hostname-command/
Tidak ada komentar:
Posting Komentar