6

Change Hostname on Fedora

 2 years ago
source link: https://www.vultr.com/docs/change-hostname-on-fedora-best-practices
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
<?xml encoding="utf-8" ??>

Supported Versions

This guide applies to:

  • Fedora 32
  • Fedora 31

Introduction

When creating a new Vultr VPS, you can set the Server Hostname before deployment. If you skip this step or decide to rename your server later, you'll discover that changing the server hostname from the Customer Portal also performs a fresh reinstall of the entire server.

Change Hostname Example Screenshot

Follow this guide if you need to change the server hostname without reinstalling.

Examples

This guide uses olddog for the old hostname and newtricks for the new hostname.

1. Check the Current Hostname

Check the hostname with hostname.

$ hostname
olddog

You can also use hostnamectl.

 $ hostnamectl 
 Static hostname: olddog
       Icon name: computer-vm
         Chassis: vm
      Machine ID: 58faa01902374a109313e96814764892
         Boot ID: 25d09e7586c045d2954af4259416433b
  Virtualization: kvm
Operating System: Fedora 32 (Server Edition)
     CPE OS Name: cpe:/o:fedoraproject:fedora:32
          Kernel: Linux 5.6.7-300.fc32.x86_64
    Architecture: x86-64

2. Change Hostname

Change the hostname to newtricks.

$ sudo hostnamectl set-hostname newtricks

3. Update /etc/hosts

Use your favorite text editor to change any instances of your old hostname to the new hostname in /etc/hosts. If you have a DNS name pointed to this instance, it's a best practice to also set that name here.

$ sudo nano /etc/hosts

From:

127.0.0.1 olddog
::1       olddog

To:

127.0.0.1 newtricks newtricks.example.com
::1       newtricks newtricks.example.com

4. Confirm the Change

Reboot the server.

Test your change with hostnamectl and hostname.

$ hostnamectl
 Static hostname: newtricks
       Icon name: computer-vm
         Chassis: vm
      Machine ID: 58faa01902374a109313e96814764892
         Boot ID: 25d09e7586c045d2954af4259416433b
  Virtualization: kvm
Operating System: Fedora 32 (Server Edition)
     CPE OS Name: cpe:/o:fedoraproject:fedora:32
          Kernel: Linux 5.6.7-300.fc32.x86_64
    Architecture: x86-64

$ hostname
newtricks
$ hostname -a
newtricks.example.com

Update DNS

Your server hostname is changed and ready to use. This procedure does not change your DNS name, and you'll need to perform those steps at your domain registrar.

Want to contribute?

You could earn up to $600 by adding new articles


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK