To set the hostname and domain name of your Linux server, you can follow these steps:
hostnamectl
command. For example, to set the hostname to myhost
, you can use the following command:sudo hostnamectl set-hostname myhost
/etc/hosts
file to set the domain name. Open the file in a text editor:sudo nano /etc/hosts
Find the line that begins with 127.0.1.1
and replace the hostname with the desired hostname and domain name. For example:
127.0.1.1 myhost.example.com myhost
/etc/hostname
file to set the hostname. Open the file in a text editor:sudo nano /etc/hostname
Replace the existing hostname with the desired hostname. For example:
myhost
sudo systemctl restart networking
hostname
command to display the current hostname:hostname
Keep in mind that the hostname and domain name are used to identify your server on the network. It is important to set them correctly to avoid confusion and ensure that the server can be accessed using the correct name.