Mémo pour changer le nom du serveur de façon permanente sur Ubuntu Server 18.04 et 20.04.
[MAJ !]
Changer le hostname :
1 |
command hostnamectl set-hostname monserveur |
Ajouter la ligne correspondante dans le fichier /etc/hosts :
1 2 3 4 5 6 7 8 9 |
127.0.0.1 localhost.localdomain localhost 127.0.1.1 monserveur.domaine.lan monserveur # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts |
Voir http://manpages.ubuntu.com/manpages/focal/man1/hostname.1.html
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 reads127.0.1.1 ursula.example.com ursula
Si vous utilisez CloudInit :
Editer le fichier /etc/cloud/cloud.cfg et changer la ligne :
1 |
preserve_hostname: false |
en
1 |
preserve_hostname: true |
Sinon désactiver CloudInit : Ubuntu Server – Désactiver CloudInit sur Ubuntu Server 20.04
Exécuter la commande :
1 |
hostname -F /etc/hostname |
Redémarrer le serveur.
Vérifier la prise en compte par :
1 |
command hostnamectl |
Résultat :
1 2 3 4 5 6 7 8 |
Static hostname: monserveur Icon name: computer-desktop Chassis: desktop Machine ID: 771f15b623714acaa15c36e57bcd148b Boot ID: 753acbc90ef543fcb6de76bdff26543a Operating System: Ubuntu 18.04.2 LTS Kernel: Linux 4.15.0-55-generic Architecture: x86-64 |
Puis :
1 |
hostname -f |
Résultat :
1 |
monserveur.domaine.lan |
Et enfin pour vérifier le domaine :
1 |
dnsdomainname |
Résultat :
1 |
domaine.lan |