How to change hostname for my VPS?

Gmeister4

Well-known member
Joined
Apr 19, 2016
Messages
114
Best answers
0
Ratings
7
Points
18
#1
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
149
Best answers
0
Ratings
9
Points
18
#2
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!
 
Joined
Apr 15, 2016
Messages
60
Best answers
0
Ratings
18
Points
0
#3
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
 
Joined
Jul 6, 2016
Messages
27
Best answers
0
Ratings
2
Points
3
#5
#hostname "yourhostname"

This will change the host name on a Linux server
 

fwh

Administrator
Staff Member
Joined
Dec 8, 2012
Messages
664
Best answers
0
Ratings
258 1
Points
63
#6
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,489
Best answers
4
Ratings
371 8
Points
83
#7
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
 
Joined
Apr 28, 2016
Messages
22
Best answers
0
Ratings
1
Points
0
#8
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
Best answers
0
Ratings
5
Points
18
#9
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,489
Best answers
4
Ratings
371 8
Points
83
#10
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
 
Joined
Mar 15, 2017
Messages
33
Best answers
0
Points
0
#13
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
65
Best answers
0
Ratings
5 2
Points
8
#14
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
Best answers
0
Ratings
12
Points
0
#15
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
888
Replies
6
Views
1,032
Replies
7
Views
631
Replies
4
Views
611
Similar Threads
Replies
5
Views
107
Replies
2
Views
1,059
Replies
1
Views
651
Replies
5
Views
1,228

Latest Hosting OffersNew Reviews

Sponsors