Just the title, what the difference between them?
In python, socket.gethostbyname(socket.gethostname()) and socket.gethostbyname(socket.getfqdn()) return different results on my computer.
Note that the selected reply above is quite confusing.
YES socket.getfqdn WILL return a full-qualified hostname. But if it's going to be 'localhost.localdomain' you probably actually want socket.gethostname instead so that you get something that is somewhat useable.
The difference is that one reads from /etc/hostname and /etc/domainname while the other reads the kernel nodename. Depending on your distribution, configuration, OS, etc. your mileage WILL vary.
What this means is that you generally want to first check socket.getfqdn, and verify if it returns 'localhost.localdomain'. if it does, use socket.gethostname instead.
Finally, python also has platform.node which is basically the same as socket.gethostname on python, though this might be a better choice for multiplatform code.
That's quite an important detail.
what's the difference between gethostname and getfqdn?