为什么“主机名 --fqdn”在我的 Ubuntu 计算机上不起作用?

Rad*_*Hex 10 networking linux hostname ubuntu

我使用的是 Ubuntu 10.04 LTS,当我输入命令时hostname --fqdn,我收到消息:hostname: Name or service not known

因此,我无法global成功安装,并在尝试时出现以下错误:

Setting up global (5.7.1-1) ...
hostname: Name or service not known
dpkg: error processing global (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 global
E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)

我的/etc/nsswitch.conf是下面。

# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat

hosts:          files dns
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis
Run Code Online (Sandbox Code Playgroud)

有没有人对这意味着什么以及我如何解决这个问题有任何想法?

小智 11

你能提供内容/etc/nsswitch.conf吗?

看起来 /etc/nsswitch.conf 对“hosts”行的值不好。它是否以“文件”开头?

否则,通过编辑 /etc/hosts 并将 FQDN 放在主机名出现的行上来设置 FQDN。假设您有一个主机名“foo”,并且您找到了一行:

127.0.0.1 foo
Run Code Online (Sandbox Code Playgroud)

你会像这样编辑它:

127.0.0.1 foo.localdomain foo
Run Code Online (Sandbox Code Playgroud)

foo.localdomain 将是您的新 FQDN。


Mud*_*fly 6

编辑 /etc/hosts 以添加您的 FQDN

位于此处的语法信息:http : //www.faqs.org/docs/securing/chap9sec95.html

更新:再次阅读你的问题,听起来你要么没有正确设置路径,要么主机名程序有问题。

做'哪个主机名'

它应该返回路径“/bin/hostname”

如果可行,请再次尝试该命令,例如

'/bin/主机名--fqdn'

  • 这在这里进行了一次疯狂的跳跃,但是,Ubuntu 更喜欢使用 sudo 而不是使用 root。shell 很可能没有正确设置。测试这个非常简单。首先,您可以执行 'ls -al /root/' 并查看是否可以看到 .bashrc 其次,如果您没有 .bashrc,则从 skel 'cp /etc/skel/.bashrc ./' 复制它,您可以执行即使您已经拥有该文件。第三次执行 '/bin/bash' 以确保您正在运行 bash。最后再次尝试您的原始命令,您应该在完全配置的 bash shell 中运行。 (2认同)