You can use the hostname command to display or set the Debian Linux system’s host name. In this tutorial, you will learn how to change your hostname on Debian Linux.
Steps to change your hostname on Debian Linux:
- Login to your server: ssh [email protected]
- Become a root user: sudo -s or su -
- Edit the file /etc/hostname: vi /etc/hostname
- Edit the file /etc/hosts: vi /etc/hosts
- Run command: /etc/init.d/hostname.sh start
Let us see steps in details.
Find your current computer name
Type the following command:
Change your computer name on Debian
To change hostname to server2, enter:
$ hostname server2
How Do I Change Hostname Permanently?
Edit the file /etc/hostname, enter:
# vi /etc/hostname
Delete the existing name and replace it with a new name:
Save and close the file. You may also need to edit the /etc/hosts file, enter:
# vi /etc/hosts
Find all references to server1 and replace with server2:
127.0.0.1 localhost 127.0.1.1 server2 # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
Save and close the file. Please note that the host name is usually set once at system startup in /etc/init.d/hostname.sh (normally by reading the contents of a file which contains the host name, e.g. /etc/hostname). Just type the following command to apply new changes without rebooting the server:
# /etc/init.d/hostname.sh start