[New-bugs-announce] [issue10821] gethostbyname(gethostname()) is wrong when IP is changed

Petr Sklenář report at bugs.python.org
Tue Jan 4 11:18:18 CET 2011

New submission from Petr Sklenář <psklenar at redhat.com>:

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 = machine.something.com

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

[root at machine.something.com ~]# host machine.something.com
machine.something.com has address

ifconfig shows the same

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

Actual results:
[root at machine.something.com ~]# 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: = machine.something.com is added in /etc/hosts in the time of OS installation , then its not changed

components: IO
messages: 125298
nosy: psklenar
priority: normal
severity: normal
status: open
title: gethostbyname(gethostname()) is wrong when IP is changed
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list