Linux servers setting Hostname and -sudo: unable to resolve host- solution

06 November 2015, Friday 0 Comments

When you have not set your server's hostname properly, you will see some of the security and verification processes are not right. To fix this issue, you can set your Hostname easily.

Set Hostname

For linux distributions similar to Ubuntu:

hostnamectl set-hostname server.localhost

For linux distributions similar to CentOS:

hostname server.localhost

We have set hostname server.localhost in the example shown in above. You can change it to anything you want just looks similar shown in below.

Add Hostname to Network Configuration

Lets add newly defined hostname to network configuration. Open hosts file with an editor such like nano and add hostname refers to

Open hosts file with an editor such like nano:

nano /etc/hosts
Add this: server.localhost

Additional configuration for CentOS:

For CentOS, lets open /etc/sysconfig/network file with an editor and modify it:
sudo nano /etc/sysconfig/network

Add or modify existing HOSTNAME data shown in below.


To affect changes, restart network service:
/etc/init.d/network restart

Share this