Page 1 of 1

Proper way to change server IP

Posted: Tue Dec 22, 2020 9:00 am
by myVesta
In your SSH, as root, run:

Code: Select all

OLDIPV4='' # enter here your old IP
NEWIPV4='' # enter here your new IP

grep -rl "$OLDIPV4" /etc | xargs sed -i "s#$OLDIPV4#$NEWIPV4#g"
find /home/*/conf/ -type f -exec sed -i "s#$OLDIPV4#$NEWIPV4#g" {} \;
mv /usr/local/vesta/data/ips/$OLDIPV4 /usr/local/vesta/data/ips/$NEWIPV4
mv /etc/apache2/conf.d/$OLDIPV4.conf /etc/apache2/conf.d/$NEWIPV4.conf
mv /etc/nginx/conf.d/$OLDIPV4.conf /etc/nginx/conf.d/$NEWIPV4.conf
grep -rl "$OLDIPV4" /usr/local/vesta/data | xargs sed -i "s#$OLDIPV4#$NEWIPV4#g"

service bind9 restart
service apache2 restart
service nginx restart
service vesta restart

v-stop-firewall
v-update-firewall

Re: Proper way to change server ip

Posted: Tue Sep 28, 2021 8:23 pm
by Jpsciolli
Sorry : got this message

sed: no input files

is the format correct?

OLDIPV4=’’ # x.x.x.x
NEWIPV4=‘’ # y.y.y.y

Re: Proper way to change server ip

Posted: Tue Sep 28, 2021 8:45 pm
by myVesta
Jpsciolli wrote: Tue Sep 28, 2021 8:23 pm sed: no input files
it's fine, since sometimes some folders does not contain old IP

Re: Proper way to change server ip

Posted: Tue Sep 28, 2021 10:16 pm
by Jpsciolli
Thanks again,

Guess it is not recognizing something:

root@cp:/home/jpsciolli# mv /usr/local/vesta/data/ips/$OLDIPV4 /usr/local/vesta/data/ips/$NEWIPV4
mv: cannot stat '/usr/local/vesta/data/ips/'$'\342\200\231\342\200\231': No such file or directory
root@cp:/home/jpsciolli# mv /etc/apache2/conf.d/$OLDIPV4.conf /etc/apache2/conf.d/$NEWIPV4.conf
mv: cannot stat '/etc/apache2/conf.d/'$'\342\200\231\342\200\231''.conf': No such file or directory
root@cp:/home/jpsciolli# mv /etc/nginx/conf.d/$OLDIPV4.conf /etc/nginx/conf.d/$NEWIPV4.conf
mv: cannot stat '/etc/nginx/conf.d/'$'\342\200\231\342\200\231''.conf': No such file or directory

Re: Proper way to change server ip

Posted: Tue Sep 28, 2021 10:33 pm
by myVesta
looks like you didn't enter ip inside first two variables.

it should be:

Code: Select all

OLDIPV4='x.x.x.x'
NEWIPV4='y.y.y.y'