Issue 10821: gethostbyname(gethostname()) is wrong when IP is changed (original) (raw)

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

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

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

ifconfig shows the same

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

Actual results: [root@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() 'machine.something.com' gethostbyname(gethostname()) '1.1.1.1'

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

Other: 1.1.1.1 = machine.something.com is added in /etc/hosts in the time of OS installation , then its not changed