How to change hostname for my VPS?

Gmeister4

Well-known member
Registered
Joined
Apr 19, 2016
Messages
178
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
Registered
Joined
Apr 19, 2016
Messages
238
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
Registered
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
 

FerdieQO

Well-known member
Joined
Jul 15, 2016
Messages
213
Points
28
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
Registered
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
773
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

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
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
Registered
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
Registered
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

Well-known member
Registered
Joined
May 3, 2016
Messages
1,622
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
Registered
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
Hosting Provider
Registered
Joined
Apr 11, 2017
Messages
72
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
Registered
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
2,564
Replies
6
Views
3,532
Replies
7
Views
2,040
Replies
4
Views
1,983
Newer Threads
Recommended Threads
Similar Threads
Replies
16
Views
4,554
Replies
2
Views
2,293
Replies
1
Views
1,904
Replies
5
Views
3,874

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