I am getting the following error when running a sudo
command on Ubuntu 14 server on EC2/VPC on Amazon Web Services.
sudo: unable to resolve host ip-xxx-xx-x-xx
I replaces the private IP address of the server with x's.
In order to solve this, I need to edit /etc/hosts
file. When I add the following line to the hosts file:
127.0.0.1 ip-xxx-xx-x-xx
Now I don't get the error. The value after the 127.0.0.1 resolves to the hostname
command value.
The problem is that I might create an AMI and restore the server in the future, so the private IP will change. In AWS forum, they recommended to add a script that automatically update the hosts file with the new IP (the hostname
value) so it will work when restoring a server from AMI or when autoscaling.
How can I update the hosts file with the hostname value, so I won't need to worry about any future issues?