Python giving wrong FQDN

Issues related to applications and software problems
albegadeep
Posts: 6
Joined: 2021/06/25 15:18:31

Python giving wrong FQDN

Post by albegadeep » 2021/06/26 01:25:04

I'm running duplicity to a B2 account. I recently updated duplicity and b2. Now when I try to do my updates, it warns that my domain has changed. Looks like this is coming from python itself:

Code: Select all

import socket
print(socket.gethostname())
print(socket.getfqdn())
results in my "non-qualified" hostname (let's call it "fred", it's one word without any dots), then "a[ip address].deploy.static.akamaitechnologies.com". And that's not my internal or external IP address, either. A quick nslookup on "fred" (again, not the real hostname) gives that same address, so it looks like it's resolving the hostname to an IP using DNS, then using reverse-DNS to get the FQDN. Weird.

So I tried putting "fred" on each 127.0.0.1 line of /etc/hosts. Now it returns "fred" and "localhost.localdomain".
Here's my hosts file at the moment:

Code: Select all

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 fred
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1   fred
If I put "fred." (note the dot) at the start of the first line, then it reports "fred" and "fred." respectively. I'm trying to get getfqdn to say exactly "fred", so duplicity won't give warnings (or make me override it). Any idea how to get socket.getfqdn() to report "fred"?

pjsr2
Posts: 614
Joined: 2014/03/27 20:11:07

Re: Python giving wrong FQDN

Post by pjsr2 » 2021/07/06 08:21:31

You should not need to add the computer name to the /etc/hosts file.

What is the output of:

Code: Select all

hostname
See https://www.server-world.info/en/note?o ... p=hostname on how to change the hostname of your system.

albegadeep
Posts: 6
Joined: 2021/06/25 15:18:31

Re: Python giving wrong FQDN

Post by albegadeep » 2021/07/09 11:27:14

"hostname" reports "fred" as expected, just like it does in python. It's python's socket.getfqdn() that I'd like to change from "localhost.localdomain" or "a[ip address].deploy.static.akamaitechnologies.com" to "fred".

pjsr2
Posts: 614
Joined: 2014/03/27 20:11:07

Re: Python giving wrong FQDN

Post by pjsr2 » 2021/07/09 13:21:04

If hostname only reports "fred" then you have not set a fqdn for your host.
In that case functions that try to find your fqdn need another way to figure out your fqdn and may do so by starting to look at your network addresses and determining the fqdn through a reverse lookup of the IP address. I am not a Python-expert, so I cannot tell you how this exactly is implemented in socket.gethostname() and socket.getfqdn().

If your host has multiple addresses the reverse lookups may result in several fqdn-s that don't need to be identical. There is nothing that the functions can use, to tell which of these fqdn-s is the preferred one. Therefor you should set a fqdn with

Code: Select all

hostnamectl set-hostname fred.toplevel.domain
as described in the document I referred to above.

It is completely valid that a host is identified in the DNS by multiple fqdn-s. These fqdn-s may refer to the same or to different IP-addresses of the host.

User avatar
TrevorH
Site Admin
Posts: 33191
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Python giving wrong FQDN

Post by TrevorH » 2021/07/09 18:59:59

Also "fred" is NOT an FQDN. It's a hostname. The fq in fqdn is fully qualified which means "all of it".
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

albegadeep
Posts: 6
Joined: 2021/06/25 15:18:31

Re: Python giving wrong FQDN

Post by albegadeep » 2021/07/10 11:36:26

I suppose the question boils down to "how do I set a FQDN that isn't a "full" FQDN?" After all, not all computers are world-accessible; some machines legitimately don't HAVE a true FQDN, just a local name. I tried using "hostnamectl sethostname fred", and "hostname -f" reports "fred". But python still reports it as the first entry containing a dot in /etc/hosts. Looks like the answer is "you can't".

User avatar
jlehtone
Posts: 4523
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Python giving wrong FQDN

Post by jlehtone » 2021/07/10 17:01:59

albegadeep wrote:
2021/07/10 11:36:26
After all, not all computers are world-accessible
You could call her "fred.localdomain", or invent an unique domainname for your subnet. As you said, nobody "out there" will know.

albegadeep
Posts: 6
Joined: 2021/06/25 15:18:31

Re: Python giving wrong FQDN

Post by albegadeep » 2021/07/11 00:48:36

You could call her "fred.localdomain"
Looks like that's my best bet. My original intent was to have python (and thus duplicity) see the FQDN as "fred", but since that doesn't appear possible, I'll have to go with something ilke "fred.localdomain", and use the switch to force duplicity to accept it, at least for the initial run.

Thank you all for trying to find a way to get this to work.

Whoever
Posts: 1357
Joined: 2013/09/06 03:12:10

Re: Python giving wrong FQDN

Post by Whoever » 2021/07/11 03:02:03

albegadeep wrote:
2021/06/26 01:25:04
Here's my hosts file at the moment:

Code: Select all

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 fred
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1   fred
I don't think that does what you think it does. Only one of those 127.0.0.1 lines is actually going to be used.

chemal
Posts: 776
Joined: 2013/12/08 19:44:49

Re: Python giving wrong FQDN

Post by chemal » 2021/07/13 16:54:04

Try this:

Code: Select all

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.2   fred

Post Reply