Name or service not known: Difference between revisions

From Helpful
Jump to navigation Jump to search
mNo edit summary
Tag: New redirect
 
Line 1: Line 1:
{{stub}}
#redirect [[Some_explanation_to_some_errors_and_warnings#Name_or_service_not_known]]
 
...an error, with an errno of -2.
 
A host name lookup problem, and one that can have ''many'' different causes.
 
 
Before digging in to diagnose the problem, check the same thing on a different computer. If any test fails on other computers on the same network, it's likely to be a problem external to you (e.g. DNS server or proxy failing, or such).
 
 
 
 
==Possible causes / things to look at==
===Nonsense lookup===
 
If a hostname lookup is being done that makes no sense, for example <tt>gethostbyname()</tt> on an URL instead of a hostname.
 
===host can't look up itself===
 
If one of the following fails {{comment|(replacing hostx or your favorite resolving utility)}}:
hostx localhost
hostx `hostname`
...then it's likely your <tt>/etc/hosts</tt> is broken, or possibly the hostname you have set (there are some extra details to this when you set an FQDN as your hostname).
 
 
===nameserver / proxy trouble===
* If the above work but things like:
hostx google.com
hostx yourisp.com
...all fail, then it might be DNS trouble - including not having a DNS server set (in *nices, look at <tt>/etc/resolv.conf</tt>) <!--(in rare cases a partial outage, e.g. your ISP being up but it being relatively severed from the rest of the internet somehow)-->
 
 
===nsswitch===
* Another reason for things not to work -- or sometimes for them to have weird patterns of working and not working -- can be that your <tt>/etc/nsswitch.conf</tt> is malconfigured, or configured to include something that does not work consistently (see in particular its <tt>hosts:</tt> line).
 
<!--
 
===Others===
* Perhaps IPv4/IPv6 confusion?
 
 
 
In my case, python seemed to be selectively failing. The following worked:
<code lang="bash">
python -c 'import socket; print socket.gethostbyname(socket.gethostname())'
</code>
 
Note: python code that somehow relies on mimetools (mail stuff) has a line like <tt>socket.gethostbyname(socket.gethostname())</tt>, so if that fials, so will it.
 
 
<code lang="bash">
python -c 'import socket; print socket.gethostbyname("google.com")'
</code>
...failing points to localhost not being listed in /etc/hosts, and to general DNS trouble, respectively. Maybe <tt>/etc/resolv.conf</tt> isn't pointing to something useful?
 
 
In my case, the problem was revealed by python failing to do something specific (HTTP fetching), showing:
urllib2.URLError: <urlopen error [Errno -2] Name or service not known>
...or...
socket.gaierror: (-2, 'Name or service not known')
...depending on the specific code that brought this about.
 
None of the tests mentioned above failed or misbehaved, and even an access on a local URL:
<code lang="python">
import urllib2,socket
urllib2.urlopen( "http://%s/"%socket.gethostbyname(socket.gethostname()))
</code>
...but failing on:
<code lang="python">
import urllib2
urllib2.urlopen( "http://google.com/" )
</code>
 
This in itself tells you little
-->
 
[[Category:Networking]]
[[Category:Warnings and errors]]

Latest revision as of 16:44, 14 July 2023