Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name or service not known

I have been trying to get the ipaddress of the person who logged into the machine using the below code but I get a error.

>>> import socket
>>> socket.gethostbyname_ex(socket.gethostname())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known

The same code works in other linux box. Not sure I fix it.

like image 981
user1050619 Avatar asked Jul 07 '16 20:07

user1050619


1 Answers

Error has occurred just because of not setting up hostname properly. Set the hostname at three different places, which are in -

  1. /etc/hostname
  2. /etc/hosts
  3. run command $ hostname

then logout and login again. You are done.

like image 71
Yogesh Jilhawar Avatar answered Oct 02 '22 00:10

Yogesh Jilhawar