How do I change the hostname of a VPS or Dedicated server via SSH?

Finding the current server's hostname:

  1. Login with SSH as root.
  2. You will see whether your hostname is by entering the command "hostname".
[root@server]# hostname

It will display the current hostname. It should be a domain name resolving to your server's main IP address.

To change the server's hostname, please use this procedure:

    1.   Configure /etc/hosts:

 Open the file /etc/hosts with any text editor. It will show the contents similar to this. localhost.localdomain localhost server

Replace the second line with your server's main IP address and hostname.

   2.   Setup the hostname using the command "hostname"

Type this command to change the hostname;


   3.   Edit the file /etc/sysconfig/network (CentOS)
         Edit the file /etc/hostname (Debian)

Replace the "HOSTNAME" field with your server's new hostname.

After editing the file should look like this:

  • hostname, vps, server, change hostname, host name, ssh
  • 2027 Users Found This Useful
Was this answer helpful?

Related Articles

How to flush your DNS cache

Your home computer creates a cache for all DNS settings. It does this to save time each time you...

What is the root login for my new VPS server?

The root login is the same password our system sent you in your welcome email. You just change...

What is the path to PERL?

The path to PERL in PERL script is:#!/usr/local/bin/perl

Do you troubleshoot scripts and apps?

Hello,Sorry, but troubleshooting sripts and apps needs to be done by the scipt maker or a...

How to use PHP-CLI

You would call '/usr/local/bin/php' if you need the php-cli binary, and '/usr/bin/php' if you...