Proper way to change server ip

Post Reply
User avatar
myVesta
Site Admin
Posts: 579
Joined: Fri Jun 19, 2020 9:59 am
Proper way to change server ip

Post 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

Jpsciolli
Posts: 12
Joined: Sun Feb 21, 2021 6:54 pm
Re: Proper way to change server ip

Post by Jpsciolli »

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: 579
Joined: Fri Jun 19, 2020 9:59 am
Re: Proper way to change server ip

Post 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

Jpsciolli
Posts: 12
Joined: Sun Feb 21, 2021 6:54 pm
Re: Proper way to change server ip

Post by Jpsciolli »

Thanks again,

Guess it is not recognizing something:

[email protected]:/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
[email protected]:/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
[email protected]:/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: 579
Joined: Fri Jun 19, 2020 9:59 am
Re: Proper way to change server ip

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


Post Reply