为什么 Python 的 socket.getfqdn() 返回一个看起来像 IPv6 主机的长字符串,而不是 `hostname -f` 返回的内容?
为什么 Python 的 socket.getfqdn()
返回 '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0。 0.0.ip6.arpa'
而不是 matt-mmf-macbook.local?
[email protected]:~
$ python
Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.getfqdn()
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'
>>>
[email protected]:~
$ hostname
matt-mmf-macbook.local
[email protected]:~
$ hostname -f
matt-mmf-macbook.local
socket.getfqdn()
的意外输出导致我的 Duplicity 备份失败,输出如下。我上次成功的口是心非备份是在 12 月 19 日。
[email protected]:~
$ ~/config/bash/backup.sh
Reading globbing filelist /Users/mlm/config/bash/backup-include-matt-mmf-macbook.txt
Reading globbing filelist /Users/mlm/config/bash/backup-exclude-matt-mmf-macbook.txt
Local and Remote metadata are synchronized, no sync needed.
Warning, found the following remote orphaned signature files:
duplicity-new-signatures.20110929T140604Z.to.20110929T143209Z.sigtar.gpg
duplicity-new-signatures.20110929T143209Z.to.20110929T150055Z.sigtar.gpg
duplicity-new-signatures.20110929T150055Z.to.20110929T161503Z.sigtar.gpg
duplicity-new-signatures.20110929T161503Z.to.20110930T161505Z.sigtar.gpg
duplicity-new-signatures.20110930T161505Z.to.20111005T024235Z.sigtar.gpg
duplicity-new-signatures.20111005T024235Z.to.20111005T024907Z.sigtar.gpg
duplicity-new-signatures.20111005T024907Z.to.20111005T161508Z.sigtar.gpg
duplicity-new-signatures.20111005T161508Z.to.20111006T161509Z.sigtar.gpg
duplicity-new-signatures.20111006T161509Z.to.20111007T161507Z.sigtar.gpg
duplicity-new-signatures.20111007T161507Z.to.20111010T161511Z.sigtar.gpg
duplicity-new-signatures.20111010T161511Z.to.20111011T161507Z.sigtar.gpg
duplicity-new-signatures.20111011T161507Z.to.20111012T161510Z.sigtar.gpg
duplicity-new-signatures.20111012T161510Z.to.20111013T161505Z.sigtar.gpg
duplicity-new-signatures.20111013T161505Z.to.20111017T161506Z.sigtar.gpg
duplicity-new-signatures.20111017T161506Z.to.20111018T161505Z.sigtar.gpg
duplicity-new-signatures.20111018T161505Z.to.20111019T161506Z.sigtar.gpg
duplicity-new-signatures.20111019T161506Z.to.20111020T161506Z.sigtar.gpg
duplicity-new-signatures.20111020T161506Z.to.20111021T161511Z.sigtar.gpg
duplicity-new-signatures.20111021T161511Z.to.20111025T161507Z.sigtar.gpg
duplicity-new-signatures.20111025T161507Z.to.20111026T161510Z.sigtar.gpg
duplicity-new-signatures.20111026T161510Z.to.20111027T161506Z.sigtar.gpg
duplicity-new-signatures.20111027T161506Z.to.20111028T161511Z.sigtar.gpg
duplicity-new-signatures.20111028T161511Z.to.20111104T161506Z.sigtar.gpg
duplicity-new-signatures.20111104T161506Z.to.20111115T222417Z.sigtar.gpg
Last full backup date: Wed Nov 16 12:16:14 2011
Fatal Error: Backup source host has changed.
Current hostname: 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa
Previous hostname: matt-mmf-macbook.local
Aborting because you may have accidentally tried to backup two different data sets to the same remote location, or using the same archive directory. If this is not a mistake, use the --allow-source-mismatch switch to avoid seeing this message
[email protected]:~
$
我的 backup.sh 包含:
#! /bin/bash
PATH=/usr/local/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:$PATH
. ~/config/bash/awskeys.sh
. $(type -p virtualenvwrapper.sh)
workon duplicity
ulimit -n 1024
duplicity \
--encrypt-key DEADBEEF \
--include-globbing-filelist ~/config/bash/backup-include-$(hostname -s).txt \
--exclude-globbing-filelist ~/config/bash/backup-exclude-$(hostname -s).txt \
/ \
s3://s3.amazonaws.com/backup-$(hostname -s)/
Why does Python's socket.getfqdn()
return '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'
rather than matt-mmf-macbook.local?
[email protected]:~
$ python
Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.getfqdn()
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'
>>>
[email protected]:~
$ hostname
matt-mmf-macbook.local
[email protected]:~
$ hostname -f
matt-mmf-macbook.local
The unexpected output of socket.getfqdn()
is making my Duplicity backups fail with the output below. My last successful Duplicity backup was on 12/19.
[email protected]:~
$ ~/config/bash/backup.sh
Reading globbing filelist /Users/mlm/config/bash/backup-include-matt-mmf-macbook.txt
Reading globbing filelist /Users/mlm/config/bash/backup-exclude-matt-mmf-macbook.txt
Local and Remote metadata are synchronized, no sync needed.
Warning, found the following remote orphaned signature files:
duplicity-new-signatures.20110929T140604Z.to.20110929T143209Z.sigtar.gpg
duplicity-new-signatures.20110929T143209Z.to.20110929T150055Z.sigtar.gpg
duplicity-new-signatures.20110929T150055Z.to.20110929T161503Z.sigtar.gpg
duplicity-new-signatures.20110929T161503Z.to.20110930T161505Z.sigtar.gpg
duplicity-new-signatures.20110930T161505Z.to.20111005T024235Z.sigtar.gpg
duplicity-new-signatures.20111005T024235Z.to.20111005T024907Z.sigtar.gpg
duplicity-new-signatures.20111005T024907Z.to.20111005T161508Z.sigtar.gpg
duplicity-new-signatures.20111005T161508Z.to.20111006T161509Z.sigtar.gpg
duplicity-new-signatures.20111006T161509Z.to.20111007T161507Z.sigtar.gpg
duplicity-new-signatures.20111007T161507Z.to.20111010T161511Z.sigtar.gpg
duplicity-new-signatures.20111010T161511Z.to.20111011T161507Z.sigtar.gpg
duplicity-new-signatures.20111011T161507Z.to.20111012T161510Z.sigtar.gpg
duplicity-new-signatures.20111012T161510Z.to.20111013T161505Z.sigtar.gpg
duplicity-new-signatures.20111013T161505Z.to.20111017T161506Z.sigtar.gpg
duplicity-new-signatures.20111017T161506Z.to.20111018T161505Z.sigtar.gpg
duplicity-new-signatures.20111018T161505Z.to.20111019T161506Z.sigtar.gpg
duplicity-new-signatures.20111019T161506Z.to.20111020T161506Z.sigtar.gpg
duplicity-new-signatures.20111020T161506Z.to.20111021T161511Z.sigtar.gpg
duplicity-new-signatures.20111021T161511Z.to.20111025T161507Z.sigtar.gpg
duplicity-new-signatures.20111025T161507Z.to.20111026T161510Z.sigtar.gpg
duplicity-new-signatures.20111026T161510Z.to.20111027T161506Z.sigtar.gpg
duplicity-new-signatures.20111027T161506Z.to.20111028T161511Z.sigtar.gpg
duplicity-new-signatures.20111028T161511Z.to.20111104T161506Z.sigtar.gpg
duplicity-new-signatures.20111104T161506Z.to.20111115T222417Z.sigtar.gpg
Last full backup date: Wed Nov 16 12:16:14 2011
Fatal Error: Backup source host has changed.
Current hostname: 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa
Previous hostname: matt-mmf-macbook.local
Aborting because you may have accidentally tried to backup two different data sets to the same remote location, or using the same archive directory. If this is not a mistake, use the --allow-source-mismatch switch to avoid seeing this message
[email protected]:~
$
My backup.sh contains:
#! /bin/bash
PATH=/usr/local/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:$PATH
. ~/config/bash/awskeys.sh
. $(type -p virtualenvwrapper.sh)
workon duplicity
ulimit -n 1024
duplicity \
--encrypt-key DEADBEEF \
--include-globbing-filelist ~/config/bash/backup-include-$(hostname -s).txt \
--exclude-globbing-filelist ~/config/bash/backup-exclude-$(hostname -s).txt \
/ \
s3://s3.amazonaws.com/backup-$(hostname -s)/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了类似的问题。 getfqfn() 返回“local.localdomain”,而不是
hostname
返回的值“host.mydomain.com”。检查 getfqfn() 文档 显示:就我而言, getfqdn() 实际上是在我的 /etc/hosts 中查找,其中列出了:
由于“真实”主机名位于末尾,而“local.localdomain”是“包含句点的第一个名称”,这就是它使用过的一个。将我的 /etc/hosts 更改为:
导致返回正确的主机名。
我认为您也遇到了类似的问题。
I ran into a similar problem. getfqfn() was returning 'local.localdomain' instead of the value 'host.mydomain.com' returned by
hostname
. Checking the getfqfn() docs shows:In my case, getfqdn() was actually looking in my /etc/hosts, which listed:
Since the "real" hostname was at the end, and "local.localdomain" is "the first name which includes a period", that's the one it used. Changing my /etc/hosts to:
caused the correct hostname to be returned.
I think a similar issue is occurring for you.
我假设它只是跳过本地 DNS 解析并直接向互联网询问主机名。
IPv6 地址
::1
的唯一正确主机名是1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0。 0.0.0.0.ip6.arpa
,加上本地定义的名称 - 但互联网不知道这个名称。I'd assume that it simply skips the local DNS resolution and goes straight to asking the internet for the hostname.
The only correct hostname for the IPv6 address
::1
is1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa
, plus the name defined locally - but the internet doesn't know that one.我导航到“系统偏好设置”>“网络>无线网络>高级> TCP/IP,并将“配置 IPv6”从: 更改
为:
现在我得到了我所期望的:
我还注意到,在更改为“自动”后,“关闭”不再是一个选项。
I navigated to System Preferences > Network > Wi-Fi > Advanced > TCP/IP, and changed Configure IPv6 from:
to:
And now I get what I expect:
I also notice that Off is no longer an option after changing to Automatically.