회사에서 Ubuntu 16.04를 실행하는 서버를 임대하고 이름을 company.org로 지정하겠습니다.
현재 내 서버는 다음과 같이 구성되어 있습니다.
- 호스트 이름 :
server737263
- 도메인 이름:
company.org
내 FQDN은 다음과 같습니다.
user@server737263:~ $ hostname --fqdn
server737263.company.org
이것은 놀라운 일이 아닙니다.
또한 도메인 이름을 임대하고 있습니다 domain.org
. 이름을 지정하겠습니다 . 내가하고 싶은 것은 서버 이름을로 바꾸는 것 server1.domain.org
입니다.
이것은 내 호스트 이름을 server1
내 도메인 이름을로 구성하는 것을 의미합니다 domain.org
.
어떻게 올바르게 할 수 있습니까?
실제로 맨 페이지 hostname
가 명확하지 않습니다. 적어도 나에게 :
호스트 이름 (1)
[…]
이름 설정
- 하나의 인수 또는 –file 옵션으로 호출하면 명령이 호스트 이름 또는 NIS / YP 도메인 이름을 설정합니다. hostname은 sethostname (2) 함수를 사용하는 반면 세 개의 domainname, ypdomainname 및 nisdomainname은 모두 setdomainname (2)를 사용합니다. 이는 다음에 다시 부팅 할 때까지만 유효합니다. 영구적으로 변경되도록 / etc / hostname을 편집하십시오.
[…]
FQDN
- 호스트 이름 또는 dnsdomainname으로 FQDN을 변경할 수 없습니다.
[…]
편집 /etc/hostname
이 충분하지 않은 것 같습니다 . 실제로 호스트 이름을 변경 한 경우 FQDN이 변경되었을 것입니다. 커맨드로 호스트 이름을 변경하기 위해 읽은 트릭도 sysctl kernel.hostname=server1
있지만 이것이 올바른 방법인지 또는 추한 트릭인지는 아무것도 알 수 없습니다.
그래서:
-
호스트 이름을 설정하는 올바른 방법은 무엇입니까?
-
도메인 이름을 설정하는 올바른 방법은 무엇입니까?
답변
호스트 이름 설정 :
-
/etc/hostname
새 호스트 이름 으로 편집하고 싶을 것 입니다. -
그런 다음을 실행하십시오
sudo hostname $(cat /etc/hostname)
.
도메인 설정 :
-
그런 다음
/etc/resolvconf/resolv.conf.d/head
에 다음 줄domain your.domain.name
(FQDN이 아닌 도메인 이름)을 추가합니다. -
그런 다음을 실행
sudo resolvconf -u
하여 업데이트하십시오/etc/resolv.conf
(또는 이전 변경 사항을로 변경하십시오/etc/resolv.conf
).
양자 모두:
마지막으로 /etc/hosts
파일을 업데이트하십시오 . IP (루프백 여부) 중 하나, FQDN 및 호스트 이름으로 시작하는 줄이 하나 이상 있어야합니다. ipv6 주소를 제거하면 호스트 파일은 다음과 같습니다.
127.0.0.1 localhost
1.2.3.4 service.domain.com service
답변
sudo nano / etc / hostname
hostname.domain.com
sudo nano / etc / hosts
127.0.0.1 hostname.domain.com hostname localhost
리 부트!
/ etc / hosts 파일에서 FQDN 다음에 단일 호스트 이름이 있어야합니다. Ubuntu 18.04.1 및 기타 모든 버전에서 제대로 작동합니다. EC2 및 다른 곳에서.
해결 파일이나 다른 것을 엉망으로 만들지 않았습니다.
그러면 쉘에 호스트 이름이 표시되고 필요할 때 FQDN이 나타납니다.
답변
~ $ 남자 호스트 이름
[…]
You cannot change the FQDN with hostname or dnsdomainname.
The recommended method of setting the FQDN is to make the hostname be an alias for the fully qualified name using /etc/hosts,
DNS, or NIS. For example, if the hostname was "ursula", one might have a line in /etc/hosts which reads
127.0.1.1 ursula.example.com ursula
Technically: The FQDN is the name getaddrinfo(3) returns for the host name returned by gethostname(2). The DNS domain name is
the part after the first dot.
Therefore it depends on the configuration of the resolver (usually in /etc/host.conf) how you can change it. Usually the hosts
file is parsed before DNS or NIS, so it is most common to change the FQDN in /etc/hosts.
If a machine has multiple network interfaces/addresses or is used in a mobile environment, then it may either have multiple
FQDNs/domain names or none at all. Therefore avoid using hostname --fqdn, hostname --domain and dnsdomainname. hostname --ip-
address is subject to the same limitations so it should be avoided as well.
[…]
이것은 다른 스레드 에서 poige 에 의해 친절하게 지적되었으며 Lutz가 여기서 제안한 것과 정확히 같습니다.
fqdn을 넣지 마십시오 /etc/hostname
.
답변
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
매개 변수를 편집 하고 변경하여 새 네트워크 관리자 Netplan을 통해 도메인을 /etc/netplan/01-netcfg.yaml
변경하십시오 search
.
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
문제가 해결되면 sudo netplan try
프롬프트 에서 ENTER를 눌러 항목을 영구적으로 만드십시오.
답변
나는에서 내 도메인 항목을 변경하려고 myhome.local
에 myhome.lan
내가 편집 한 /etc/hosts
파일과 /etc/network/interfaces
파일을. 내 /etc/hosts
파일은 다음과 같습니다.
127.0.0.1 localhost
192.168.3.2 server.myhome.lan server
내 /etc/network/interfaces
파일은 다음과 같습니다.
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp2s0
iface enp2s0 inet static
address 192.168.3.2
netmask 255.255.255.0
network 192.168.3.0
broadcast 192.168.3.255
gateway 192.168.3.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 192.168.3.1
dns-search myhome.lan
그것은 나를 위해 잘 작동합니다.