How to change your Hostname on Debian

FerdieQO

Well-known member
Joined
Jul 15, 2016
Messages
222
Points
28
After having a fresh VPS or reinstall my VPS to install a new hosting control panel. How can I change the hostname of a Debian Linux system permanently using the command line tools?
 

LJSHost

Well-known member
Hosting Provider
Registered
Joined
Jul 5, 2016
Messages
1,031
Points
63
To make a permanent host name change on Debian edit the /etc/hostname file. Replace the contents of the file with your new host name.

Then run: /etc/init.d/hostname.sh start

This will make the change active, you can check the host name by using the hostname command.
 

VirtuBox

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
Points
83
On Debian/Ubuntu Linux, hostname is set in two files: /etc/hostname and /etc/hosts.

  • /etc/hostname: short hostname, not FQDN.
Code:
mx
  • /etc/hosts: static table lookup for hostnames. Warning: Please list the FQDN hostname as first item.
# Part of file: /etc/hosts
Code:
127.0.0.1   mx.example.com mx
 

LJSHost

Well-known member
Hosting Provider
Registered
Joined
Jul 5, 2016
Messages
1,031
Points
63
MX is the host name in this example mx.example.com is the FQDN
No, you do not need to add the host name after the FQDN

Either of these examples with /etc/hosts are fine:

127.0.0.1 servername.domain.com
127.0.0.1 servername.domain.com servername
 

VirtuBox

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
Points
83
VirtuBox
Yes you can use the subdomain of your choice to have a FQDN. But you have to add whatyouwant.yourdomain.com whatyouwant to make it work.
To verify you have done it properly use, you should have this result :
Code:
[SIZE=4]root@host# hostname
-> host

root@host# hostname -f 
-> host.yourdomain.com[/SIZE]
If you are planning to use a DNS server or an email server, you have to use a FQDN.
 
Similar Threads
Replies
16
Views
5,527
Replies
2
Views
2,657
Replies
1
Views
2,337
Replies
14
Views
14,867

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top