How to change hostname for my VPS?

Gmeister4

Well-known member
Joined
Apr 19, 2016
Messages
162
Points
18
I tried this way

Code:
sudo nano /etc/sysconfig/network
and in this file I changed

Code:
HOSTNAME=myserver.domain.com
but when I check with hostname -f , it is still not getting right hostname that I wanted.

Do you guide me how to change hostname for my VPS completely?
 

Mihai B.

Well-known member
Joined
Apr 19, 2016
Messages
191
Points
18
If Nano is installed on your server, you might use this additional way

Using this command

nano /etc/hosts
Change to something like this

For example
105.197.10.132 server.yourdomain.com
In the line above, 105.197.10.132 is your IP address

Hope it helps!
 

HostPace

Active member
Joined
Apr 15, 2016
Messages
65
Points
8
I tried this way

Code:
sudo nano /etc/sysconfig/network
and in this file I changed

Code:
HOSTNAME=myserver.domain.com
but when I check with hostname -f , it is still not getting right hostname that I wanted.

Do you guide me how to change hostname for my VPS completely?
# Run the hostname command:
hostname HOST_NAME

# Open /etc/sysconfig/network, update the HOSTNAME line and save:

# vim /etc/sysconfig/network OR # nano /etc/sysconfig/network
HOSTNAME=HOST_NAME

# Open your hosts file, and update the hostname entry and save:
vim /etc/hosts OR nano /etc/hosts
127.0.0.1 HOST_NAME
 
  • Like
Reactions: fwh

FerdieQO

Well-known member
Joined
Jul 15, 2016
Messages
199
Points
18
FerdieQO
You are right but they are for used CentOS 6, if using CentOS 7 we need to run an extra command.

Code:
hostnamectl set-hostname server.example.com
 

ExpertHosters

Member
Joined
Jul 6, 2016
Messages
27
Points
3
#hostname "yourhostname"

This will change the host name on a Linux server
 

fwh

Administrator
Staff Member
Joined
Dec 8, 2012
Messages
744
Points
63
fwh
This doesn't change hostname though and it will back to the previous hostname when you restart your server.

Following tips from @HostPace will change your hostname completely.
 

VirtuBox

Global Mod
Staff Member
Joined
May 3, 2016
Messages
1,621
Points
83
And be careful because Redhat/Centos doesn't work the same than Debian/Ubuntu

With Centos your hostname should be a FQDN like server.yourdomain.com when on debian your will add in /etc/hosts

Code:
188.165.55.XX server.yourdomain.com server
But in /etc/hostname, you should use only "server" and not server.yourdomain.com

The best tutorial I have found for that is in iRedMail documentation :

Centos : http://www.iredmail.org/docs/install.iredmail.on.rhel.html

Debian : http://www.iredmail.org/docs/install.iredmail.on.debian.ubuntu.html
 

Wesley

Member
Joined
Apr 28, 2016
Messages
22
Points
0
And be careful because Redhat/Centos doesn't work the same than Debian/Ubuntu

With Centos your hostname should be a FQDN like server.yourdomain.com when on debian your will add in /etc/hosts

Code:
188.165.55.XX server.yourdomain.com [B]server[/B]
Is it necessary to add server end of line?

I remember I failed once when add this to end of line in /etc/hosts


But in /etc/hostname, you should use only "server" and not server.yourdomain.com
I filled full hostname as server.yourdomain.com
 

Marc A

Well-known member
Joined
Jun 14, 2016
Messages
125
Points
18
I'm sorry if this sounds dumb, but is the hostname the ip? Lol sorry just started a vps and didn't really know what it was.
 

VirtuBox

Global Mod
Staff Member
Joined
May 3, 2016
Messages
1,621
Points
83
Is it necessary to add server end of line?

I remember I failed once when add this to end of line in /etc/hosts


I filled full hostname as server.yourdomain.com
You can use anything to replace server, but a Fully Qualified Domain Name (FQDN) have to be a subdomain because it reveal all the domain authority of your domain.

I'm sorry if this sounds dumb, but is the hostname the ip? Lol sorry just started a vps and didn't really know what it was.

The hostname is the name associated with the IP of the server.

With a correct setup the hostname IP should have a A record like server.yourdomain.com -> YOUR.SERVER.IP and also a reverse to resolve YOUR.SERVER.IP -> server.yourdomain.com
 

optimalgeek

Member
Joined
Mar 15, 2017
Messages
33
Points
0
Change in /etc/sysconfig/network and enter in the file HOSTNAME=server.example.com and reboot your VPS . Reboot once.
This will change it permanently
 

SolaDrive

Active member
Joined
Apr 11, 2017
Messages
67
Points
8
You should actually see if your VPS provider has a VPS control panel to manage your VPS from as you can usually set the VPS hostname there and it will hardcode it to your VPS.
 

racksandcloud

Well-known member
Joined
May 18, 2017
Messages
89
Points
0
Hello,

You should have to reboot the dedicated server or vps once you changed the hostname in /etc/sysconfig/network and its a permanent change. Also, changing the hostname with hostname command is temporary change.
 
Older Threads
Replies
2
Views
1,354
Replies
6
Views
1,513
Replies
7
Views
987
Replies
4
Views
953
Latest Threads
  • Deleted
Hi
  • Deleted by fwh
Replies
0
Views
1
Replies
0
Views
19
SBH
Replies
1
Views
42
Replies
0
Views
29
Replies
1
Views
46
Recommended Threads
Replies
0
Views
642
Replies
3
Views
1,421
Replies
0
Views
1,309
Similar Threads
Replies
16
Views
995
Replies
2
Views
1,399
Replies
1
Views
925
Replies
5
Views
1,746

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Latest Blog ArticlesMost Viewed Threads

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