Changing Your Server Hostname: Difference between revisions

From Sympl Wiki
Jump to navigation Jump to search
No edit summary
(Added command required to change the installation hostname.)
 
(4 intermediate revisions by 4 users not shown)
Line 5: Line 5:
Functionality for automatically changing the hostname will be included in Sympl at a future date, however you may follow the instructions below to change the hostname manually via [[SSH]].
Functionality for automatically changing the hostname will be included in Sympl at a future date, however you may follow the instructions below to change the hostname manually via [[SSH]].


=== Set the new hostname ===
===Set the new hostname===
To avoid typing it multiple times, you should set the new hostname as a variable. This can be the URL for a domain it’s already hosting, or just the name of the server from your hosting provider, however the domain must point to the server already, and should have at least one dot (ie: '<code>.</code>') in it.
To avoid typing it multiple times, you should set the new hostname as a variable. This can be the URL for a domain it’s already hosting, or just the name of the server from your hosting provider, however the domain must point to the server already, and should have at least one dot (ie: '<code>.</code>') in it.
====Changing the default host name after installation====
newhost=''''''server.example.com'''''<nowiki/>'
oldhost='localhost.localdomain'
====Changing the host name (when already changed from the default)====
  newhost=''''''server.example.com'''''<nowiki/>'
  newhost=''''''server.example.com'''''<nowiki/>'
oldhost=$(hostname -f)


=== Update the files ===
===Update the files===
Now you should be able to copy and paste the following into your SSH session:
Now you should be able to copy and paste the following into your SSH session:
oldhost=$(hostname -f)
  sudo hostname $newhost
  sudo hostname $newhost
You may be prompted for the <code>sympl</code> user password. Enter it if so.
You may be prompted for the <code>sympl</code> user password. Enter it if so.
  if [ ! -d /srv/$newhost/ ]; then mv /srv/$oldhost/ /srv/$newhost/; fi
  if [ ! -d /srv/$newhost/ ]; then mv /srv/$oldhost/ /srv/$newhost/; fi
You may want to change the SSL provider for the new hostname before continuing (e.g. <code>selfsigned</code> to <code>letsencrypt</code>). See [[SSL Configuration Reference]]
  sudo sympl-ssl --verbose --force $newhost
  sudo sympl-ssl --verbose --force $newhost
   
   
Line 28: Line 34:
  echo $newhost | sudo tee /etc/hostname | sudo tee /etc/mailname
  echo $newhost | sudo tee /etc/hostname | sudo tee /etc/mailname


=== Update /etc/hosts ===
===Update /etc/hosts===
You will need to update the servers hosts file, <code>/etc/hosts</code>, with the new name of the server.
You will need to update the servers hosts file, <code>/etc/hosts</code>, with the new name of the server.


In your text editor of choice, such as <code>nano</code> or <code>vim</code>, edit the <code>/etc/hosts</code> file, and replace each instance of the old name for the server with the new name. You may have entries which are the 'short' hostname (the first part of the hostname, such as '<code>server</code>' in the above example), so remember to change them to the short name also.
In your text editor of choice, such as <code>[https://www.nano-editor.org/dist/v2.2/nano.html nano]</code> or <code>[https://www.vim.org/ vim]</code>, edit the <code>/etc/hosts</code> file, and replace each instance of the old name for the server with the new name. You may have entries which are the 'short' hostname (the first part of the hostname, such as '<code>server</code>' in the above example), so remember to change them to the short name also.
 
Whilst /etc/hosts does not match the server's new hostname various services will fail to start and your websites will not be available. Also /etc/hosts may not stick after a reboot. For example on a Brightbox server the hosts file is recreated from a template each time (as documented in the hosts file) so make sure you edit the template to make the new host name stick.


=== Reboot ===
===Reboot===
Finally, to ensure everything is updated fully and the new hostname is consistent, reboot the server. Once it's rebooted everything should have been updated fully.
Finally, to ensure everything is updated fully and the new hostname is consistent, reboot the server. Once it's rebooted everything should have been updated fully.
[[Category:How To]]
[[Category:How To]]

Latest revision as of 11:02, 16 September 2022

A number of functions in Sympl use the servers hostname to determine its defaults, such as emails sent to unix users, the default fallback site for any unmatched sites, and the default SSL certificates used for things like Email and FTP connections.

This means that properly changing the server hostname can be tricky, and missing one or more elements can cause unexpected problems later on.

Functionality for automatically changing the hostname will be included in Sympl at a future date, however you may follow the instructions below to change the hostname manually via SSH.

Set the new hostname

To avoid typing it multiple times, you should set the new hostname as a variable. This can be the URL for a domain it’s already hosting, or just the name of the server from your hosting provider, however the domain must point to the server already, and should have at least one dot (ie: '.') in it.

Changing the default host name after installation

newhost='server.example.com'
oldhost='localhost.localdomain'

Changing the host name (when already changed from the default)

newhost='server.example.com'
oldhost=$(hostname -f)

Update the files

Now you should be able to copy and paste the following into your SSH session:

sudo hostname $newhost

You may be prompted for the sympl user password. Enter it if so.

if [ ! -d /srv/$newhost/ ]; then mv /srv/$oldhost/ /srv/$newhost/; fi

You may want to change the SSL provider for the new hostname before continuing (e.g. selfsigned to letsencrypt). See SSL Configuration Reference

sudo sympl-ssl --verbose --force $newhost

sudo rm /etc/ssl/ssl.combined /etc/ssl/ssl.crt /etc/ssl/ssl.key

sudo ln -s /srv/$newhost/config/ssl/current/ssl.combined /etc/ssl/ssl.combined
sudo ln -s /srv/$newhost/config/ssl/current/ssl.crt /etc/ssl/ssl.crt
sudo ln -s /srv/$newhost/config/ssl/current/ssl.key /etc/ssl/ssl.key

sudo sympl-web-configure

echo $newhost | sudo tee /etc/hostname | sudo tee /etc/mailname

Update /etc/hosts

You will need to update the servers hosts file, /etc/hosts, with the new name of the server.

In your text editor of choice, such as nano or vim, edit the /etc/hosts file, and replace each instance of the old name for the server with the new name. You may have entries which are the 'short' hostname (the first part of the hostname, such as 'server' in the above example), so remember to change them to the short name also.

Whilst /etc/hosts does not match the server's new hostname various services will fail to start and your websites will not be available. Also /etc/hosts may not stick after a reboot. For example on a Brightbox server the hosts file is recreated from a template each time (as documented in the hosts file) so make sure you edit the template to make the new host name stick.

Reboot

Finally, to ensure everything is updated fully and the new hostname is consistent, reboot the server. Once it's rebooted everything should have been updated fully.