我正在租用一台服务器,在一家公司运行Ubuntu16.04,让我们把它命名为company.org。
目前,我的服务器配置如下:
server737263company.org这是我的FQDN:
user@server737263:~ $ hostname --fqdn
server737263.company.org这并不令人惊讶。
我还租用了一个域名,让我们命名它domain.org。我想要做的是将我的服务器重命名为server1.domain.org。
这意味着将我的主机名配置为server1,将我的域名配置为domain.org。
事实上,hostname的管理手册还不清楚。至少对我来说:
主机名(1) ...集名称
... FQDN
...
那么,仅仅编辑/etc/hostname似乎还不够吗?因为如果它真的更改了主机名,它就会更改FQDN。我还读到了一个用命令sysctl kernel.hostname=server1更改主机名的技巧,但是没有说明这是正确的方法还是丑陋的技巧。
所以:
发布于 2016-11-12 23:51:33
设置主机名:
/etc/hostname。sudo hostname $(cat /etc/hostname)。假设您有一个resolvconf二进制文件,则设置您的域:
/etc/resolvconf/resolv.conf.d/head中,您将添加行domain your.domain.name (而不是FQDN,只是域名)。sudo resolvconf -u来更新您的/etc/resolv.conf (或者,将前面的更改复制到/etc/resolv.conf中即可)。如果没有resolvconf,只需编辑/etc/resolv.conf,添加domain your.domain.name行即可。
无论哪种方式:
最后,更新您的/etc/hosts文件。至少应该有一行以您的IP (回送与否)、FQDN和主机名开头。如果您的主机文件删除了ipv6地址,您的主机文件可能如下所示:
127.0.0.1 localhost
1.2.3.4 service.domain.com service针对hostnamectl在评论中堆积如山的建议:它不是强制性的,也不是详尽无遗的。
如果操作系统附带了systemd,它可以作为步骤1和步骤2的替代品。而上面给出的步骤是有效的,而不管系统是否存在(pclinuxos,devuan,.)。
发布于 2018-11-06 21:41:40
sudo nano /etc/主机名
hostname.domain.comsudo nano /etc/主机
127.0.0.1 hostname.domain.com hostname localhost重新启动!
在/etc/host文件中的FQDN之后必须有一个主机名。在Ubuntu18.04.1和所有其他版本上工作都很好。在EC2和其他地方。
没有弄乱解析文件或其他任何东西。
它在shell中显示主机名,并在需要时拥有FQDN。
发布于 2019-10-22 11:32:06
针对Ubuntu 18.04.3 LTS编写的指令(仿生)
更改主机名:
sudo hostnamectl set-hostname server1通过运行hostnamectl检查结果:
root@www:/# hostnamectl
Static hostname: server1 <-- Check this value
Icon name: computer-vm
Chassis: vm
Machine ID: 202c4264b06d49e48cfe72599781a798
Boot ID: 43654fe8bdbf4387a0013ab30a155872
Virtualization: xen
Operating System: Ubuntu 18.04.3 LTS
Kernel: Linux 4.15.0-65-generic
Architecture: x86-64通过编辑网络计划和更改search参数,通过新的网络管理器/etc/netplan/01-netcfg.yaml更改域:
sudoedit /etc/netplan/01-netcfg.yaml示例配置:
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
nameservers:
search: [ domain.org ]通过第二次日志记录和在其中一个会话中运行sudo netplan try并在另一个会话中检查设置来测试更改:
# netplan try
Do you want to keep these settings?
Press ENTER before the timeout to accept the new configuration
Changes will revert in 97 seconds
Configuration accepted.# systemd-resolve --status
...
Link 2 (eth0)
Current Scopes: DNS
LLMNR setting: yes
MulticastDNS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 8.8.8.8
8.8.4.4
DNS Domain: domain.org <-- Check this value# cat /etc/resolv.conf
...
nameserver 127.0.0.53
options edns0
search domain.org <-- Check this value# hostname -f
server1.domain.org这一切都很好,按ENTER在sudo netplan try提示符使事情永久。
https://unix.stackexchange.com/questions/322883
复制相似问题