大网数据广告活动
服务器运维问答

How to set the domain name on GNU/Linux?

· 52CE 我爱测

Similarly to hostname that can be changed in different ways: temporarily using the hostname command permanently using /etc/hostname (or /etc/sysconfig/network or /etc/HOSTNAME , these files are used by the init scripts) I want to…

问题原文

原帖链接 · Mildred · CC BY-SA 3.0

Similarly to hostname that can be changed in different ways:

  • temporarily using the hostname command
  • permanently using /etc/hostname (or /etc/sysconfig/network or /etc/HOSTNAME, these files are used by the init scripts)

I want to change my domain name. I can use the domainname command, but is there a way to make it permanent across reboots? I think it can be configured in /etc/resolv.conf but this file is generally generated and I don't know exactly the difference between search and domain directives. And at what time exactly the information there is passed to the domainname program to set the domain name?

Do you have any ideas on that?

I'd like to be mostly compatible across distributions. So if if anyone has pointers on the different distributions flavours, I'd gladly accept them.

社区高分解答

原帖链接 · jason · CC BY-SA 4.0

Set FQDN

I'm using Debian 7 and this is what worked for me; thanks to Fernando Ribeiro.

sudoedit /etc/hostname

server # here's where you put the server's host name

activate hostname

sudo hostname -F /etc/hostname

add domain name and address to the server

sudoedit /etc/hosts

192.168.1.2   server.domain server

VERIFY

> hostname --short
server

> hostname --domain
domain

> hostname --fqdn
server.domain

> hostname --ip-address
192.168.1.2

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-03-23)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。