Proper way to change server hostname

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

In your SSH, as root, run:

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"

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
service bind9 reload

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: 908
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 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: 908
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 8 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: 7
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