Follow these steps to change the hostname of your Ubuntu system:
In this blog, I will explain how to change the hostname of a Linux server. For example, I want to install the Oracle database on the server and want my server to be named "Database". For this reason, this guide might be useful to change the name of your Linux system.
Steps
1. Open the Terminal
Open the terminal on your Ubuntu system. This is the first and fundamental tool you need to make changes to the system.
2. Check the Current Hostname
Enter the following command to check the current hostname:
This command outputs the current hostname of your system. It is important to know the current hostname before changing it.
3. Temporarily Change the Hostname
To temporarily change the hostname, enter the following command:
sudo
indicates that you are running the command as a superuser.hostname
is the command to change the hostname.database
is the new hostname you want to set.
This changes the hostname until the next reboot. It is useful for testing immediate changes without restarting the system.
4. For a Permanent Change, Edit the /etc/hostname
File
To permanently change the hostname, edit the
/etc/hostname
file:sudo
indicates that you are running the command as a superuser.nano
is a simple text editor that runs in the console./etc/hostname
is the file that contains the current hostname.
Replace the existing name with the new hostname. Save the file and close the editor.
Note: If
nano
is not installed, install the editor with the following command:5. Edit the /etc/hosts
File to Ensure Consistency
Edit the
/etc/hosts
file to ensure that the new hostname is used consistently:In this file, you will find lines that contain the old hostname. Change every mention of the old hostname to the new hostname. A typical line might look like this:
Change it to:
Save the file and close the editor.
6. Reboot the System to Apply the Change
Reboot the system to make the changes effective:
After the reboot, you will see that the hostname has changed. This can sometimes be useful, for example, when we want to install the Oracle Apex database and thus know that this server is a database server.
Summary
- Open the terminal.
- Check the current hostname with .
- Temporarily change the hostname with .
- Edit the file for a permanent change.
- Edit the file to ensure consistency.
- Reboot the system with .
Good luck with changing the hostname!
Tips:
- Backups: It is always a good idea to make backups of the files you are editing. For example:
- sudo cp /etc/hostname /etc/hostname.baksudo cp /etc/hosts /etc/hosts.bak
- Alternative Editors: If you don't like
nano
, you can also use other editors likevim
orgedit
. For example: - sudo vim /etc/hostnamesudo gedit /etc/hosts
- Verification: After the reboot, you can check the new hostname again to ensure that the changes were successful:
- hostname
Common Issues:
- Lack of Superuser Rights: If you do not have the correct permissions to edit the files, make sure you are using
sudo
. - DNS Conflicts: If your new hostname is already used in the network, it may cause conflicts. Make sure the new hostname is unique.
Further Information:
- Ubuntu Documentation: The official Ubuntu documentation provides more details and advanced options for changing the hostname.
- Man Pages: Use the man pages for detailed information on the commands used:
- man hostnameman nanoman sudo
{fullWidth}
0 $type={blogger}:
Kommentar veröffentlichen