Proper way to change server hostname

Post Reply
User avatar
myVesta
Site Admin
Posts: 949
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 9 times
Been thanked: 6 times

Before we begin, it's crucial to confirm that your newly chosen hostname is correctly configured to point to your server's IP address. Once this DNS configuration is in place, proceed to your myVesta control panel as an admin user.

Within the WEB section, you should add your new hostname as a new domain entry, activate Let's Encrypt for it and delete the old hostname.

Next, in your SSH terminal as the root user, execute the following commands to update your server's hostname and DNS settings. Replace the placeholder values with your specific information:

Code: Select all

OLDHOST=''  # enter here old hostname
OLDNS1=''   # enter here old NS1
OLDNS2=''   # enter here old NS2

NEWHOST=''  # enter here new hostname
NEWNS1=''   # enter here new NS1
NEWNS2=''   # enter here new NS2

/usr/local/vesta/bin/v-change-sys-hostname "$NEWHOST"
hostname $NEWHOST

find /home/*/conf/dns/ -type f -exec sed -i "s#$OLDHOST#$NEWHOST#g" {} \;
find /home/*/conf/dns/ -type f -exec sed -i "s#$OLDNS1#$NEWNS1#g" {} \;
find /home/*/conf/dns/ -type f -exec sed -i "s#$OLDNS2#$NEWNS2#g" {} \;
find /usr/local/vesta/data/users/*/dns/ -type f -exec sed -i "s#$OLDHOST#$NEWHOST#g" {} \;
find /usr/local/vesta/data/users/*/dns/ -type f -exec sed -i "s#$OLDNS1#$NEWNS1#g" {} \;
find /usr/local/vesta/data/users/*/dns/ -type f -exec sed -i "s#$OLDNS2#$NEWNS2#g" {} \;
sed -i "s#$OLDHOST#$NEWHOST#g" /usr/local/vesta/data/users/*/dns.conf
sed -i "s#$OLDNS1#$NEWNS1#g" /usr/local/vesta/data/users/*/dns.conf
sed -i "s#$OLDHOST#$NEWHOST#g" /usr/local/vesta/data/users/*/user.conf
sed -i "s#$OLDNS1#$NEWNS1#g" /usr/local/vesta/data/users/*/user.conf
sed -i "s#$OLDNS2#$NEWNS2#g" /usr/local/vesta/data/users/*/user.conf
sed -i "s/$OLDHOST/$NEWHOST/g" /etc/roundcube/plugins/password/config.inc.php
grep -rl "$OLDHOST" /etc | xargs sed -i "s/$OLDHOST/$NEWHOST/g"
grep -rl "$OLDHOST" /usr/local/vesta/conf | xargs sed -i "s/$OLDHOST/$NEWHOST/g"
sed -i "s#$OLDNS1#$NEWNS1#g" /usr/local/vesta/data/packages/*.pkg
sed -i "s#$OLDNS2#$NEWNS2#g" /usr/local/vesta/data/packages/*.pkg
systemctl reload bind9

PHPVER=$(/usr/local/vesta/bin/v-get-php-version-of-domain $NEWHOST)
sed -i "/^group =/c\group = www-data" /etc/php/$PHPVER/fpm/pool.d/$NEWHOST.conf
sed -i "/request_terminate_timeout/c\request_terminate_timeout = 900s" /etc/php/$PHPVER/fpm/pool.d/$NEWHOST.conf
sed -i "/max_execution_time/c\php_admin_value[max_execution_time] = 900" /etc/php/$PHPVER/fpm/pool.d/$NEWHOST.conf
systemctl restart php$PHPVER-fpm
These commands will systematically update your server's hostname and DNS records across various configuration files. This ensures a seamless transition to your new hostname while maintaining system integrity and security.

Tags:
infiinite
Posts: 14
Joined: Mon May 31, 2021 2:05 pm

Hey dpeca,

there's a little typo in your command, it should be /local/ and not loal.

However, this is the error I got when I executed it

Code: Select all

root@s628141:~# /usr/local/vesta/bin/v-change-sys-hostname MYNEWHOSTNAME
/usr/local/vesta/bin/v-change-sys-hostname: line 16: /func/main.sh: No such file or directory
/usr/local/vesta/bin/v-change-sys-hostname: line 17: /conf/vesta.conf: No such file or directory
/usr/local/vesta/bin/v-change-sys-hostname: line 24: check_args: command not found
/usr/local/vesta/bin/v-change-sys-hostname: line 25: is_format_valid: command not found
/usr/local/vesta/bin/v-change-sys-hostname: line 53: log_event: command not found
User avatar
myVesta
Site Admin
Posts: 949
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 9 times
Been thanked: 6 times

infiinite wrote: Wed Jun 02, 2021 8:16 am However, this is the error I got when I executed it

Code: Select all

root@s628141:~# /usr/local/vesta/bin/v-change-sys-hostname MYNEWHOSTNAME
/usr/local/vesta/bin/v-change-sys-hostname: line 16: /func/main.sh: No such file or directory
/usr/local/vesta/bin/v-change-sys-hostname: line 17: /conf/vesta.conf: No such file or directory
/usr/local/vesta/bin/v-change-sys-hostname: line 24: check_args: command not found
/usr/local/vesta/bin/v-change-sys-hostname: line 25: is_format_valid: command not found
/usr/local/vesta/bin/v-change-sys-hostname: line 53: log_event: command not found
See viewtopic.php?f=17&t=49

Tnx for typo :D
infiinite
Posts: 14
Joined: Mon May 31, 2021 2:05 pm

Thanks, adding that to env worked.

But now I got this. I tried making a bash file as well as pasting it directly in terminal.
Same error in both cases

Code: Select all

root@janus:~# grep -rl "$OLDHOST" /etc | xargs sed -i "s/$OLDHOST/$NEWHOST/g"
sed: no input files
root@janus:~# grep -rl "$OLDHOST" /usr/local/vesta/conf | xargs sed -i "s/$OLDHOST/$NEWHOST/g"
sed: no input files
User avatar
myVesta
Site Admin
Posts: 949
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 9 times
Been thanked: 6 times

That's ok, grep found nothing and just printed that warning.
Actually, sed got empty list of files from grep...
infiinite
Posts: 14
Joined: Mon May 31, 2021 2:05 pm

Alright. Perfect then.
kjernekrafttrikk
Posts: 9
Joined: Sat Apr 09, 2022 1:17 pm

I've got some number of domains associated with my server. Is it right to change server hostname to IP address? I guess, this one bring me some errors (such as ssl cert applied to one domain, but from the another one)/
Post Reply