Hi guys

Everytime i use sudo in the terminal i get
"sudo: unable to resolve host legacy"

I had a look at /etc/hosts file, all i have is this

127.0.0.1 localhost

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Any other suggestions?

Dani AI

Generated

This warning means the system hostname cannot be resolved when sudo asks the resolver for it. That usually happens after the hostname is changed (or was never recorded) and /etc/hosts or DNS doesn’t return an address for that name. got it working by adding the missing hostname entry — that is the right idea. Below are quick diagnostic steps and safer, more robust fixes to avoid surprises later.

Check what the machine thinks its name is and whether name resolution returns anything:

hostname
hostname -f
cat /etc/hostname
getent hosts "$(hostname)"

If the last command prints nothing, the hostname isn’t resolvable by the local resolver. Before editing, back up the hosts file:

sudo cp /etc/hosts /etc/hosts.bak
sudo nano /etc/hosts

Add a single line mapping your hostname (both short name and FQDN) to an appropriate IP, replacing placeholders:

<IP-address> <fully-qualified-hostname> <short-hostname>

For a laptop/desktop the loopback can be used; for a server use its real network IP so services bind correctly.

Additional tips: use sudo hostnamectl set-hostname newname on systemd systems to set the persistent hostname and keep /etc/hostname and /etc/hosts consistent. After changes, verify with getent hosts "$(hostname)" and force a sudo check with sudo -v — the warning should disappear. If you rely on IPv6, add the hostname to the IPv6 loopback entry too. Keep hostnames lowercase, avoid duplicate/conflicting mappings, and restore the backup if something breaks. The message is harmless but fixing name resolution removes the warning and avoids obscure network/service behavior.

heh
I sorted the problem out
in the /etc/hosts file i added
127.0.0.1 Legacy
Now problem is sorted out :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.