How do I change the Hostname?

I am going to be deploying a number of FreePBX systems and I want unique hostnames. How can I do this simply if I am cloning the systems?


Google “centos set hostname”

Edit /etc/sysconfig/network and change HOSTNAME= to the new hostname. Reboot the system.

Thanks for the replies. I got it.

I didn’t need help figuring out how to change my hostname, but once I did that the Asterisk service would give an error "Asterisk not running, this is a critical service."
The problem is that under the amportal.conf file a value references the hostname “localhost”. To change it you need to enable the “Display Readonly Settings” & “Override Readonly Settings” under “Advanced Settings” in the web GUI. It took me a while to figure this out so I’m trying to share the knowledge with anyone else struggling to find a resolution.
In my case I simply reverted back to using “localhost”, but in an environment where you have multiple FreePBX servers it may be necessary to change the hostname of each system.

FYI - if you are cloning servers and need to change the hostname the easiest way to do this is to change the HOSTNAME= string in the /etc/sysconfig/network file. Once you do that also update the /etc/hosts file to reflect the new hostname. Then go into the web GUI of FreePBX in “Advanced Settings” and set “Display Readonly Settings” & “Override Readonly Settings” both to “True”, update the “Asterisk Manager Host” value, save, and reboot the server. Later, rinse, repeat for each server you clone.

jkitz - You don’t need to do all that, you just need to fix your /etc/hosts file to reflect the new hosts name

Quite old post but…
I’m still confused about the right procedure, as I still receive notifications as [email protected] and system name is still localhost.localdomain
We have three settings :

/etc/sysconfig/network HOSTNAME=
Asterisk Manager Host localhost (in admin hidden advanced settings)

What should I modify ? All of three ? With or without domain specification ?
And (linux/centos related) why /etc/hosts have more values and rows ?
mine is : localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
should I add or replace my new hostname ?

Thank you for any clarification

thanks for hints,
what to do if a small company or home installation has no domain (or FQDN) ??
Should I omit the domain name or keep desiredhostname.local ???

To clarify yes you do need to "fix" your hosts file after changing the name in the  /etc/sysconfig/network file, but you can not remove the " localhost ..." line, or modify it with the new host name. If you want your server to resolve an actual name like "asteriskpbx-01" to you need to add a line to the hosts file, otherwise you will get an error.

I personally add a line with the server name both for, and its actual IP like so:     localhost     localhost.localdomain     asteriskpbx-01     asteriskpbx-01

If you leave the localhost entry in your hosts file you will not need make any changes in the web GUI. As for the email address settings I don't think FreePBX will let you edit those values. Your best bet is to set the "myhostname" value in postfix, using:

postconf -e "myhostname ="

...for example. Hope this helps.



Yes - under /etc/sysconfig/network add your server name with the fully qualified domain name as a best practice. Also if you use the postconf -e command, make sure to follow that with a "postfix reload" command so that the new settings are applied.

To test, leave yourself a voicemail and look at the from address in the email.

Much clearer now !!
Rather to add a second line, isn’t it the same to add the new hostname at the end of the first one ?
i.e. localhost localhost.localdomain


Thank you

Yes, one and the same. Just a matter of preference… kinda like indenting your code properly. Either way works.

use the “system-config-network” tool to change it?

That tool takes care of the heavy lifting, and has always worked for us.

You don’t NEED a fqdn - that’s just for your convenience. The above describes how to change the hostname correctly. Try “hostname” and “hostname -f” commands to verify.
If your primary concern is email address (from domain, account, etc). you can you generic postmap to tell postfix to rewrite your sender address. If you want to do that I will post more details (or a link)