Sometimes happen you want to change the hostname for your machine. Debian based systems (Debian/Ubuntu) have the hostname information saved in this file /etc/hostname . This is the file location from where the system at the boot time is reading and set it up using the init script that is located in /etc/init.d/hostname.sh .
You can edit the file /etc/hostname very easy and apply your desired change for hostname on the system
Steps:
- sudo gedit /etc/hostname
- make the change of hostname and save the file
- sudo /etc/init.d/hostname.sh start
All changes are now applied and you should have now a new hostname on the system. To verify that the changes really have taken place run these commands:
- sudo hostname {shows the current hostname on the system}
- sudo hostname -f {shows you hostname.localdomain information}
- sudo hostname -d {shows you localdomain information }
- sudo hostname -i {shows ip address for the hostname}
If any of the information for localdomain does not match you can edit/correct this information in this file /etc/hosts
To make changes in /etc/hosts:
- cd /etc
- sudo gedit hosts
- make the correct changes {127.0.0.1 hostname and 127.0.0.1 hostname.localdomain}
- save the changes
Additional switches for hostname are:
- -s = short hostname
- -a = alias name
- -i = ip address for the hostname
- -I = all ip addresses for the hostname
- -d = domain name for the hostname
- -f = FQDN, all long hostname
Now you re-run the commands: hostname, hostname -i, hostname -d and hostname -f — you should have now the correct hostname and localdomain on your system
hostname -a // show nothing, one blank line.
hostname -f // show my new hostname seted, its ok
hostname -d // show: com