Proper way to change server hostname

Post Reply
User avatar
dpeca
Site Admin
Posts: 458
Joined: Fri Jun 19, 2020 9:59 am
Proper way to change server hostname

Post by dpeca »

In your SSH, as root, run:

Code: Select all

/usr/local/vesta/bin/v-change-sys-hostname YOUR-NEW-HOSTNAME-HERE
also:

Code: Select all

ACCOUNT='*'  # don't change this

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

find /home/$ACCOUNT/conf/dns/ -type f -exec sed -i "s#$OLDHOST#$NEWHOST#g" {} \;
find /home/$ACCOUNT/conf/dns/ -type f -exec sed -i "s#$OLDNS1#$NEWNS1#g" {} \;
find /home/$ACCOUNT/conf/dns/ -type f -exec sed -i "s#$OLDNS2#$NEWNS2#g" {} \;
find /usr/local/vesta/data/users/$ACCOUNT/dns/ -type f -exec sed -i "s#$OLDHOST#$NEWHOST#g" {} \;
find /usr/local/vesta/data/users/$ACCOUNT/dns/ -type f -exec sed -i "s#$OLDNS1#$NEWNS1#g" {} \;
find /usr/local/vesta/data/users/$ACCOUNT/dns/ -type f -exec sed -i "s#$OLDNS2#$NEWNS2#g" {} \;
sed -i "s#$OLDHOST#$NEWHOST#g" /usr/local/vesta/data/users/$ACCOUNT/dns.conf
sed -i "s#$OLDNS1#$NEWNS1#g" /usr/local/vesta/data/users/$ACCOUNT/dns.conf
sed -i "s#$OLDHOST#$NEWHOST#g" /usr/local/vesta/data/users/$ACCOUNT/user.conf
sed -i "s#$OLDNS1#$NEWNS1#g" /usr/local/vesta/data/users/$ACCOUNT/user.conf
sed -i "s#$OLDNS2#$NEWNS2#g" /usr/local/vesta/data/users/$ACCOUNT/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
service bind9 reload

Tags:

infiinite
Posts: 10
Joined: Mon May 31, 2021 2:05 pm
Re: Proper way to change server hostname

Post by infiinite »

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

[email protected]:~# /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
dpeca
Site Admin
Posts: 458
Joined: Fri Jun 19, 2020 9:59 am
Re: Proper way to change server hostname

Post by dpeca »

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

Code: Select all

[email protected]:~# /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: 10
Joined: Mon May 31, 2021 2:05 pm
Re: Proper way to change server hostname

Post by infiinite »

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

[email protected]:~# grep -rl "$OLDHOST" /etc | xargs sed -i "s/$OLDHOST/$NEWHOST/g"
sed: no input files
[email protected]:~# grep -rl "$OLDHOST" /usr/local/vesta/conf | xargs sed -i "s/$OLDHOST/$NEWHOST/g"
sed: no input files

User avatar
dpeca
Site Admin
Posts: 458
Joined: Fri Jun 19, 2020 9:59 am
Re: Proper way to change server hostname

Post by dpeca »

That's ok, grep found nothing and just printed that warning.
Actually, sed got empty list of files from grep...

infiinite
Posts: 10
Joined: Mon May 31, 2021 2:05 pm
Re: Proper way to change server hostname

Post by infiinite »

Alright. Perfect then.


Post Reply