How to change hostname for my VPS?

Gmeister4

Active member
Joined
Apr 19, 2016
Messages
84
Best answers
0
Ratings
2
Points
8
#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
106
Best answers
0
Ratings
6
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
1
Points
0
#5
#hostname "yourhostname"

This will change the host name on a Linux server
 

fwh

Administrator
Staff member
Joined
Dec 8, 2012
Messages
633
Best answers
0
Ratings
248
Points
43
#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
Joined
May 3, 2016
Messages
1,396
Best answers
3
Ratings
310 5
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
0
#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
Joined
May 3, 2016
Messages
1,396
Best answers
3
Ratings
310 5
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
 
Joined
Apr 11, 2017
Messages
58
Best answers
0
Ratings
1
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
10
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.
 

Similar threads

Latest Hosting OffersNew Reviews

Web Hosting

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.