How do you set a persistent hostname in a Linux system?

Prepare for the LPIC-2 Certification Test with our study tools, including flashcards and multiple choice questions with hints and explanations. Get ready to pass your exam!

Setting a persistent hostname in a Linux system involves ensuring that the hostname is correctly configured so that it survives reboots and is recognized by the system. The correct approach includes editing both the /etc/hostname and /etc/hosts files.

The /etc/hostname file is fundamental as it contains the hostname that the system uses to identify itself on the network. When you set the hostname here, it will persist across reboots since the system reads this file on startup.

Editing the /etc/hosts file is also crucial because it typically maps the hostname to an IP address, often the loopback address (127.0.0.1). When you include the hostname in this file, it allows local services to resolve the hostname correctly. Without the appropriate entry in /etc/hosts, there could be issues with local name resolution, which can affect various network operations and services.

In contrast, simply editing /etc/hosts or only the /etc/hostname would not provide a complete solution. While using hostnamectl set-hostname is a valid command for temporarily changing the hostname or for systems using systemd, it does not guarantee the hostname remains persistent across reboots unless it also modifies the /etc/hostname file appropriately.

Thus, the

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy