This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: gethostbyname(gethostname()) is wrong when IP is changed
Type: Stage:
Components: IO Versions: Python 2.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, psklenar
Priority: normal Keywords:

Created on 2011-01-04 10:18 by psklenar, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg125298 - (view) Author: Petr Sklenář (psklenar) Date: 2011-01-04 10:18
tried python 2.6 on rhel55
tried python-2.7-8 on fedora14

Steps to Reproduce:
1. install machine, have a fixed hostname up to mac address =

2. wait a week or longer when your local dhcp server changes your IP but not
hostname =

[ ~]# host has address

ifconfig shows the same

3.   gethostbyname(gethostname()) shows wrong IP, the original one

Actual results:
[ ~]# python
Python 2.4.3 (#1, Jun 11 2009, 14:09:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from socket import gethostname
>>> from socket import gethostbyname
>>> gethostname()
>>> gethostbyname(gethostname())

Expected results:
gethostbyname(gethostname()) will return your actual IP,

Other: = is added in /etc/hosts in the time of OS installation , then its not changed
msg125300 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-01-04 10:32
This is not a Python issue.  gethostbyname() and gethostname() are just a wrapper for the OS's functions of the same name; you'd get the same result when coding the example in C.
Date User Action Args
2022-04-11 14:57:10adminsetgithub: 55030
2011-01-04 10:32:30georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg125300

resolution: not a bug
2011-01-04 10:18:13psklenarcreate