How to Change Your VPS Hostname
Changing the hostname of your VPS is a simple process that allows you to personalize and identify your server more easily. Follow these steps to update the hostname on your VPS.
Step 1: Connect to Your VPS
- Use SSH to connect to your VPS from your local machine:
ssh username@your_vps_ip
- Replace
username
with your VPS username (usuallyroot
), andyour_vps_ip
with the actual IP address of your VPS.
Step 2: Check the Current Hostname
- Before changing the hostname, check the current one:
hostname
- This will display the current hostname of your VPS.
Step 3: Change the Hostname Temporarily
- To change the hostname temporarily (until the next reboot), use the following command:
sudo hostname new_hostname
- Replace
new_hostname
with your desired hostname.
Note: This change will not persist after a reboot.
Step 4: Change the Hostname Permanently
To ensure the hostname persists after reboot, you need to update the system configuration files.
- Open the
/etc/hostname
file for editing:sudo nano /etc/hostname
- Replace the current hostname with your new one.
- Save the file and exit the editor by pressing
CTRL + X
, thenY
to confirm changes, andEnter
to save.
Step 5: Update the /etc/hosts
File
Next, update the /etc/hosts
file to reflect the new hostname.
- Open the file for editing:
sudo nano /etc/hosts
- Find the line that starts with
127.0.1.1
and replace the old hostname with the new one:127.0.1.1 new_hostname
- Save and exit the editor (
CTRL + X
, thenY
, andEnter
).
Step 6: Reboot Your VPS
- To apply the changes, reboot your VPS:
sudo reboot
- Once the VPS has rebooted, the new hostname should be in effect.
Step 7: Verify the Change
After rebooting, verify that the hostname has been updated:
- Run the following command to check the hostname:
hostname
- It should display your new hostname.
Conclusion
You have successfully changed the hostname of your VPS. The new hostname will now persist after system reboots and can be used to identify your VPS more easily.