Konfigurasi Hostname di Ubuntu 18.04

Logo Ubuntu

Untuk melakukan konfigurasi hostname di Ubuntu 18.04, kita akan menggunakan perintah hostnamectl. Informasi lengkap hostnamectl dapat kita baca di link berikut:

Konfigurasi hostname ini merupakan lanjutan dari tulisan sebelumnya terkait Konfigurasi IP Static di Ubuntu 18.04

Konfigurasi

Sebelumnya cek terlebih dahulu konfigurasi hostname saat ini, contoh server saya seperti ini:

# hostnamectl 
Static hostname: server
Icon name: computer-vm
Chassis: vm
Machine ID: df3c9b2646174c108c619bd349aa6c1d
Boot ID: 8fc5cc23f7d3485bb6692a4ed2940c65
Virtualization: vmware
Operating System: Ubuntu 18.04.1 LTS
Kernel: Linux 4.15.0-43-generic
Architecture: x86-64

Kali ini nama hostnamenya akan kita rubah menjadi srv.server.com, jalankan perintah berikut di terminal:

# hostnamectl set-hostname srv.server.com

Cek kembali perubahan hostnamenya:

# hostnamectl 
Static hostname: srv.server.com
Icon name: computer-vm
Chassis: vm
Machine ID: df3c9b2646174c108c619bd349aa6c1d
Boot ID: 8fc5cc23f7d3485bb6692a4ed2940c65
Virtualization: vmware
Operating System: Ubuntu 18.04.1 LTS
Kernel: Linux 4.15.0-43-generic
Architecture: x86-64

Setelah itu rubah value yang ada di file /etc/cloud/cloud.cfg pada bagian reserve_hostname: false menjadi preserve_hostname: true

# vi /etc/cloud/cloud.cfg
.
.
# This will cause the set+update hostname module to not operate (if true)
preserve_hostname: true

Konfigurasi tersebut kita setting agar setelah reboot hostname yang kita setting sebelumnya tidak berubah.

Jangan lupa tambahkan juga hostname tadi di file /etc/hosts, contohnya seperti ini:

# vim /etc/hosts

127.0.0.1    localhost.localdomain localhost
::1          localhost6.localdomain6 localhost6
192.168.1.93 srv.server.com

# 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

Reboot servernya dan cek apakah hostnamenya sesuai dengan konfigurasi sebelumnya.

$ hostname -f
srv.server.com

Sekian dan terima kasih, semoga bermanfaat ya.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top