How to resolve : getaddrinfo: new-hostname No address associated with hostname

Recently, we got the error “getaddrinfo: new-hostname No address associated with hostname” while working with some commands,
This error means, we are missing somewhere an assignment of IP and its related hostname.
You can use command,

$ hostname

new-hostname
To get, the hostname of your machine.

Now, to assign an IP with this hostname is,

sudo vim /etc/hosts

Add, a line like below,

192.168.0.103   new-hostname

Where. 192.168.0.103, is the IP you want to assign with hostname “new-hostname” [ Note: you can assign any IP as per your requirement in case you are trying to set for remote hostname ]

Save, and close the file, and now try to see if its working by using ping with hostname,

$ ping new-hostname

PING new-hostname (192.168.0.103) 56(84) bytes of data.
64 bytes from new-hostname (192.168.0.103): icmp_seq=1 ttl=64 time=1.93 ms
64 bytes from new-hostname (192.168.0.103): icmp_seq=2 ttl=64 time=1.28 ms
64 bytes from new-hostname (192.168.0.103): icmp_seq=3 ttl=64 time=1.30 ms
^C
— new-hostname ping statistics —
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 1.282/1.509/1.939/0.305 ms

So, it seems now working.

Follow Lynxbee
Tags:

Leave a Reply / Ask Question