I tried what you did on a Linux box. Maybe you should state what OS and network situation you are running on.
Using strace
I found that socket.getfqdn()
is using information provided in the file /etc/hosts
while socket.gethostname()
only prints data from the result of the system call uname()
; basically you could say the one asks the network module while the other asks the kernel. Both have an answer to your question but they do not necessarily match because they have different views on that matter.
Calling socket.gethostbyname()
also queries the network module (searches the contents of the file /etc/hosts
for a match in my case). Giving the answer of the kernel to the network function isn't really what you should do. In most cases this will work nevertheless. You found a spot in which it produced strange results.