Change hostname and FQDN on debian
On Debian, the hostname is set at startup to the script /etc/init.d/hostname.sh which uses the file /etc/hostname. We can use this file to update the computer hostname and its FQDN (fully qualified domain name).
Caution: in the /etc/hosts file, the hostname and FQDN order must be respected.
~$ echo "my-computer" > /etc/hostname
~$ echo "127.0.0.1 my-computer.my-domain.ext my-computer localhost" > /etc/hosts
~$ /etc/init.d/hostname.sh
You can check the change with the following lines:
~$ hostname
my-computer
~$ hostname --fqdn
my-computer.my-domain.ext
The old hostname may still be present in the command line prompt. Just logoff then login to make it dissapear
Name Resolution
the hosts entry in /etc/nsswitch.conf is used for resolving host names, this line is configured as:
hosts: files dns
This means that when when the resolver functions look up hostnames or IP address, they first check for an entry in the /etc/hosts file and next try the DNS server(s) which are listed in /etc/resolv.conf.
When running hostname -f to obtain the FQDN of a host, the resolver functions try to get the FQDN for the system’s hostname. If the host is not listed in the /etc/hosts file or by the relevant DNS server.
http://www.rooot.net/en/geek-stuff/linux/13-change-hostname-fqdn-debian.html
https://unix.stackexchange.com/questions/239920/how-to-set-the-fully-qualified-hostname-on-centos-7-0
Caution: in the /etc/hosts file, the hostname and FQDN order must be respected.
~$ echo "my-computer" > /etc/hostname
~$ echo "127.0.0.1 my-computer.my-domain.ext my-computer localhost" > /etc/hosts
~$ /etc/init.d/hostname.sh
You can check the change with the following lines:
~$ hostname
my-computer
~$ hostname --fqdn
my-computer.my-domain.ext
The old hostname may still be present in the command line prompt. Just logoff then login to make it dissapear
Name Resolution
the hosts entry in /etc/nsswitch.conf is used for resolving host names, this line is configured as:
hosts: files dns
This means that when when the resolver functions look up hostnames or IP address, they first check for an entry in the /etc/hosts file and next try the DNS server(s) which are listed in /etc/resolv.conf.
When running hostname -f to obtain the FQDN of a host, the resolver functions try to get the FQDN for the system’s hostname. If the host is not listed in the /etc/hosts file or by the relevant DNS server.
http://www.rooot.net/en/geek-stuff/linux/13-change-hostname-fqdn-debian.html
https://unix.stackexchange.com/questions/239920/how-to-set-the-fully-qualified-hostname-on-centos-7-0
Komentar