How to change the hostname / domainname on a Linux system

If you forget to set your correct hostname / domainname at your linux installation then you can easily fix it if you follow the next steps from this “tutorial”. Changing hostname/domainname is easy but first you will need to know what kind of linux distribution do you run: Debian or RedHat based. I will try to enumerate the most common distributions based on Debian and RedHat to help you find the roots of yours distribution.

Changing permanently the hostname / domainname on linux distributions based on RedHat:

1. You can use redhat-config-network GUI tool. Just go to DNS tab > Setup hostname and domain name. After just save your config and you are done.
2. Or you can edit /etc/sysconfig/network and replace the value of HOSTNAME with your domain name.
Edit /etc/sysconfig/network

nano /etc/sysconfig/network

Replace HOSTANAME with your hostname:

HOSTNAME=home.randombugs.com

Changing permanently the hostname / domainname on linux distributions based on Debian:

On ALL Linux system is recommended to change domainname and hostname in /etc/hosts and /etc/resolv.conf, because all have an influence to your network settings. Just look in above files after your old hostname/domainname and just replace it.

Changing the hostname / domainname on any linux distributions:

You can also change your hostname temporarily on any disitribution with hostname comand:

hostname home.randombugs.com

and this will remain until next reboot.

To change your hostname permanently on any distribution just edit /etc/sysctl.conf and add:

/etc/hostname This file should only contain the hostname and not the full FQDN.

# Most programs work anyways if you put in a FQDN but some barfs. hostname –fqdn get its information from the resolv-subsystem, you have to edit /etc/hosts for it to kick in. EG:
127.0.1.1 hostname.domain.tld hostname