How to Fix : sudo: unable to resolve host my_user: No such file or directory

If you have changed the hostname of your Linux PC, by using command from https://lynxbee.com/changing-hostname-in-ubuntu/ there are chances you may get an warnings like below everytime you type some commands with sudo permission in terminal and taking considerable time to return the command output,

$ time sudo cat /proc/version
sudo: unable to resolve host laptop: No such file or directory

real	0m30.039s
user	0m0.012s
sys	0m0.004s

So, it shows it took almost 30 sec for simple cat command to return and also returned an error/warning like “sudo: unable to resolve host laptop: No such file or directory” where “laptop” is my hostname.

To resolve this, we need to make sure following files has contents like below,

 $ cat /etc/hostname 

This should show your existing hostname you set using hostnamectl command.

 $ sudo vim /etc/hosts 

has follwing line,

Related :   Linux commands to find files based on type, size etc.

127.0.0.0 your_hostname

Replace, “your_hostname” with proper hostname you have, in my case it should “laptop” as hostname.

Now try again same comamnd as above,

$ time sudo cat /proc/version

real	0m0.012s
user	0m0.000s
sys	0m0.008s 

and you see now warning, and very less time it took to execute that command.


lynxbee_ezoic

Subscribe with Valid Email Id to receive updates in Inbox. ( Secured by Google FeedBurner )

   


Leave a Comment

Android Android Build system Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development & Build Development, Debugging and Performance Tools Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia Audio, Video, Images NDK / Middleware / HAL OS Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web design and development Website Hosting Wordpress Yocto / Bitbake / Openembedded