Localhost and hostname in Fedora 35

The Lynis security audit tool has flagged up the following:

Split resolving between localhost and the hostname of the system

The online explanatory note says:

For proper resolving, the entries of localhost and the local defined hostname, could be split. Especially with some middleware and some applications, resolving of the hostname to localhost, might confuse the software.

What is the best way to proceed?

You should always have a hostname set. If not then the IP assigned by your network does not have a specific hostname to refer to and it becomes ambiguous whether localhost refers to the 127.0.0.1 address or the 192.168.nnn.nnn address assigned to network interface. Apps that use hostname lookups rely on the hostname value being there and accurate, especially if the host can be identified by dns.

Using hostname will display the current hostname and sudo hostname [your hostname] will enable you to set the hostname (FQDN) that is the default hostname for that machine. Once the hostname is set all apps that do hostname lookups will be able to properly identify the machine.

I believe sudo hostname only sets the current hostname, and does not persist across reboot. Edit /etc/hostname for it to be permanent.

You can also use hostnamectlto show some additional information sources, including the “pretty name” (which will be displayed on the Workstation login screen, and which can contain spaces, unicode, whatever). sudo hostnamectl your_hostname will set all of the current (“transient”) name, the persistent name (systemd calls it “static”), and also the pretty name. You can also set them separately, like sudo hostnamectl --pretty "My Computer 💻".

(hostnamectl isn’t doing anything magic, by the way — it’s calling the same system calls as hostnamefor the runtime name, and writing the others to /etc/host and /etc/machine-info. It’s just conveniently putting it all in one place.)

4 Likes

sudo hostnamectl hostname --pretty "My Computer 💻" this works :wink:

1 Like

Yes, thanks — fixed!

Hi,

Maybe you could also try the following:

  1. Open and edit file /etc/hostname with sudo nano /etc/hostname and type the name as you like and save it. This name will show next time you open your terminal [ username@yourhostname ]$.

  2. Open and edit file /etc/hosts with sudo nano /etc/hosts and add new line like the following:

    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    127.0.1.1   yourhostname yourhostname.localdomain
    

    Then save it.

  3. Reboot your PC.