Error: Servname not supported for ai_socktype
Have you ever seen this error before?
“Error: Servname not supported for ai_socktype”
Well I haven’t seen it until a few days ago, when I have started working on a new server that was heavily customized by the previous sysadmin. The first thing that I wanted to do was to setup the clock properly (as it was completely wrong… not even the day was correct). Also I wanted to setup ntp to keep it synchronized properly. Since it had the ntp package already installed I have quickly launched the command:
ntpdate 0.pool.ntp.org
and instead of the expected result, I got:
Error : Servname not supported for ai_socktype
4 Sep 03:25:02 ntpdate[27310]: can't find host 0.pool.ntp.org
Hmm… Strange… DNS was working on the system, but anyway my first thought after seeing “can’t find host 0.pool.ntp.org” was that there is some dns issue.
Running:
nslookup 0.pool.ntp.org
and I got a bunch of IPs for the hostname. After this I have tried again the ntpdate command with an IP this time:
ntpdate 207.5.137.134
Error : Servname not supported for ai_socktype
4 Sep 03:25:49 ntpdate[27474]: can't find host 207.5.137.134
Hmm… Now what? So this is not caused by dns after all… what could this mean: “Servname not supported for ai_socktype“. After some other tries I have finaly seen the problem… NTP ports were not defined in /etc/services and this was the root of the error. The system didn’t know how to make ntp connections without that. So I’ve added the following lines to /etc/services
ntp 123/tcp
ntp 123/udp
and after this ntpdate started working as expected…
ntpdate 0.pool.ntp.org
3 Sep 13:25:23 ntpdate[30115]: step time server 216.165.129.244 offset -50922.751623 sec
Hopefully this little story will help others seeing similar errors (Servname not supported for ai_socktype) even if this is not related to ntp, but to other application…
The conclusion of this post is to check if you have the application ports defined in /etc/services if you encounter such an error… For example if whois is not working for you and giving a similar error check your services file for port 43/tcp/upd definition, etc.
Share This








3rd October 2006, 10:54
Thank you, you helped me with a similar problem
2nd November 2006, 15:37
The same applies to fetchmail, which outputs a bogus error message refering to the FAQ R12
fetchmail: 6.3.5 querying secure.cnc.net (protocol POP3) at Tue Oct 31 07:41:02 2006: poll started
fetchmail: getaddrinfo(”secure.cnc.net”,”pop3s”) error: Servname not supported for ai_socktype
fetchmail: Try adding the –service option (see also FAQ item R12).
POP3 connection to secure.cnc.net failed: No such file or directory
In this case, you need to add the definition
pop3s 995/tcp
18th February 2007, 13:02
I had this error with something I was doing to (postfix) but I had smtp in the /etc/services. What I didn’t realize was that the use of that file is defined as part of the nsswitch.conf file. It turned out I had some dodgy entries for the protocols line.
26th February 2007, 17:33
Thanks, I had the same problem and I hadn’t figure out this.
15th March 2007, 08:51
Hi, I had faced a similar problem but this time with http://FTP. Thanks to the solution it was not that very difficult for us to fix the issue on embedded board.
6th April 2007, 16:18
Thanks. I had the same issue and it’s now fixed.
18th April 2007, 20:35
thanks!
helped me too
28th April 2007, 20:01
Thanks, that fixed it for me. Had no idea what was wrong.
5th September 2007, 06:34
Oh, thanks
Next time I’ll double check that ‘echo “sample 13135/tcp” >> /etc/services’ has ‘>>’ and not only ‘>’ 
9th June 2008, 18:29
Another place to look is at /etc/nsswitch.conf
if the “services:” line points to something other than “files” then /etc/services will have no effect.
18th June 2008, 22:20
Thanks, I had a problem with telnet:
telnet: could not resolve sw2950t-acc/telnet: Servname not supported for ai_socktype
Turned out my /etc/services file had disappeared completely!