为什么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?
mlm@matt-mmf-macbook.local:~
$ 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'
>>>
mlm@matt-mmf-macbook.local:~
$ hostname
matt-mmf-macbook.local
mlm@matt-mmf-macbook.local:~
$ hostname -f
matt-mmf-macbook.local
socket.getfqdn()
的意外输出使我的Duplicity备份失败,输出如下。我最后一次成功的Duplicity备份是在12月19日。
mlm@matt-mmf-macbook.local:~
$ ~/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
mlm@matt-mmf-macbook.local:~
$
我的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)/
答案 0 :(得分:3)
我遇到了类似的问题。 getfqfn()返回'local.localdomain'而不是hostname
返回的值'host.mydomain.com'。检查getfqfn() docs节目:
返回name的完全限定域名。如果省略名称或 空,它被解释为本地主机。 完全找到 限定名称,检查gethostbyaddr()返回的主机名, 然后是主机的别名(如果有)。第一个名字 包括一个期间被选中。如果没有完全合格的域名 如果可用,则返回gethostname()返回的主机名。
就我而言,getfqdn()实际上是在我的/ etc / hosts中查找,其中列出了:
127.0.0.1 local.localdomain localhost host.mydomain.com
由于“真正的”主机名在最后,“local.localdomain”是“包含句点的第一个名字”,因此它就是它使用的那个。将我的/ etc / hosts更改为:
127.0.0.1 host.mydomain.com local.localdomain localhost
导致返回正确的主机名。
我认为你也有类似的问题。
答案 1 :(得分:0)
我认为它只是跳过本地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
,加上本地定义的名称 - 但互联网不知道该地址。
答案 2 :(得分:0)
我导航到系统偏好设置>网络> Wi-Fi>高级> TCP / IP,并从以下位置更改配置IPv6:
Off
为:
Automatically
现在我得到了我的期望:
mlm@matt-mmf-macbook.local:~
$ python -c 'import socket ; print socket.getfqdn()'
matt-mmf-macbook.local
mlm@matt-mmf-macbook.local:~
$
我还注意到在更改为自动后,Off不再是一个选项。