would like to change hostname and domain name for my Linux server. Where can I set the local hostname and domain name of my server?
You can use hostname/hostnamectl command to show or set the system’s host name and dnsdomainname command to show the system’s DNS domain name. But the changes are temporary if you use these commands. Local hostname and the domain name of your server defined in text configuration file located in /etc directory.
If you are using systemd based distro such as RHEL/CentOS 7.x, Fedora latest, Ubuntu Linux 16.04 LTS, Debian 9.x+, Arch Linux and more, use hostnamectl command. To see current hostname, run:
To change hostname to foo, run:
$ hostnamectl set-hostname 'foo'
If you are using Red Hat or Fedora Linux (older version) use redhat-config-network GUI tool. Type following command and click on DNS tab > Setup hostname and domain name:
On other hand you can edit a text file. Find out and set up the value for HOSTNAME in the file /etc/sysconfig/network:
# vi /etc/sysconfig/network
Where, web is hostname and nixcraft.com is your DNS domain name.
You need to edit /etc/hostname file and put hostname.domain.com in this file:
# vi /etc/hostname
Set or replace hostname:
Please note that you must have properly configured DNS server to work FQDN based hostname. See how to configure Linux as a dns client.