# Problema getaddrinfo: Name or service not known (SocketError)!

**URL:** <https://www.ruby-forum.com/t/problema-getaddrinfo-name-or-service-not-known-socketerror/215252>\
**Category:** IT\
**Created:** [December 28, 2011, 3:15pm UTC](https://www.ruby-forum.com/t/problema-getaddrinfo-name-or-service-not-known-socketerror/215252 "2011-12-28T15:15:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [December 28, 2011, 3:15pm UTC](https://www.ruby-forum.com/t/problema-getaddrinfo-name-or-service-not-known-socketerror/215252/1 "2011-12-28T15:15:22Z")

</div>

Ciao a tutti,  
in un mio script che funge da crawler ed è installato su differenti  
server quando ci sono dei problemi mi viene inviata un email.  
Per non modificare manualmente la variabile che mi dice da quale server  
proviene l’avvertimento utilizzo questa riga di codice:

$host=Socket.gethostbyname(Socket.gethostname).first

Sui server che hanno installato Apache tutto ok mentre su alcuni server  
che hanno installato solamente ruby questa istruzione non funziona e mi  
genera l’errore in oggetto. Ma se inserisco manualmente il nome del  
server l’email viene correttamente spedita.

Tutti i server su cui lo sto testando sono Ubuntu 10.04.

Qualcuno mi saprebbe dire cosa devo fare o cosa devo installare per non  
dovere ogni volta installare apache2 ed ovviare a questo errore?

Grazie  
Ciao a tutti  
Buon Lavoro  
Luca

---

<div class="post-metadata">

**Author:** ![panthe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e4f/32.png) [@panthe](https://www.ruby-forum.com/u/panthe)\
**Post date:** [December 28, 2011, 6:59pm UTC](https://www.ruby-forum.com/t/problema-getaddrinfo-name-or-service-not-known-socketerror/215252/2 "2011-12-28T18:59:04Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On 28/12/2011 15:15, Lucas P. wrote:

> $host=Socket.gethostbyname(Socket.gethostname).first

Il resolver fallisce, per info: man getaddrinfo e man 5 resolver

Forse perch non hai un dominio di default, se proprio lo vuoi aggiungi a  
/etc/resolv.conf:  
domain MioDominio

Io piuttosto mi farei scrivere il nome host, quindi solo  
Socket.gethostname,  
che ti dovrebbe restituire quello che c’ scritto in /etc/hosts

Antonio B.

-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.11 (GNU/Linux)

iQEcBAEBAgAGBQJO+1i+AAoJELgLplTPZUF9aKgIAJD+JuO6G6M7IQv23CkPFg2f  
XtI94K4Zcb2aRVKVPEUhA2VB4L1CITBn6lBl4qaPsdKemNpBoaHiYmk3LIhJZewk  
c9ge2ent4KxX8/KFj4NHnshFDC2zKraSMcMNCUtjdv9ZMVwHja/hJf9ZAnt3pUG2  
m77lxfBnjDSVvFeEjBMS3JnRq5Yx3SKUwXlszJ5BHcPYJGcMsdgp3ajYw6jjQcJQ  
MDtmMiD4vaRKEy3PtlV24GrzwCXCRNXV/EzDPfJ7DiLszQl2OfWGnXBKwqmQktxS  
JtrRrza2Zu2tCLFwzf7gW6g/fuPtXbfA8DL0N76H1Tt6VsEWV7QW2AqyyOrQV1U=  
=6RqO  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![panthe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a88e4f/32.png) [@panthe](https://www.ruby-forum.com/u/panthe)\
**Post date:** [December 28, 2011, 10:09pm UTC](https://www.ruby-forum.com/t/problema-getaddrinfo-name-or-service-not-known-socketerror/215252/3 "2011-12-28T22:09:12Z")

</div>

Antonio B. wrote in post #1038464:

> Io piuttosto mi farei scrivere il nome host, quindi solo  
> Socket.gethostname,  
> che ti dovrebbe restituire quello che c’ scritto in /etc/hosts

Grazie 1000 Antonio.  
Ho fatto come da suggerito ed è proprio quello che mi serviva.  
Grazie  
Ciao  
Luca
