Proper way to change server IP

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

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
Jpsciolli
Posts: 13
Joined: Sun Feb 21, 2021 6:54 pm

Sorry : got this message

sed: no input files

is the format correct?

OLDIPV4=’’ # x.x.x.x
NEWIPV4=‘’ # y.y.y.y
User avatar
myVesta
Site Admin
Posts: 946
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 9 times
Been thanked: 6 times

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
Jpsciolli
Posts: 13
Joined: Sun Feb 21, 2021 6:54 pm

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
User avatar
myVesta
Site Admin
Posts: 946
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 9 times
Been thanked: 6 times

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'
Post Reply