Page 4 of 5

Re: How to Auto Change IP Address in VestaCP

Posted: Mon Apr 23, 2018 8:16 pm
by mericson
Is this script still current? Been a lot of changes to VestaCP in 4 years.

What is the latest and greatest way to update all the IP addresses when migrating to a new server (including a floating IP I have behind NAT) ?

Did any v-* cli script get created for IP migration?

Basically my scenario is I have created a VM image which has my OS and VestaCP all preconfigured with my preferred setitngs, apps, security, etc. I like to create a new VM instance from that image and easily update to all the new IP addresses. After that I have a new instance, for hosting more websites, or for adding to a cluster.

Recommendations?

Re: How to Auto Change IP Address in VestaCP

Posted: Tue Apr 24, 2018 3:26 am
by plutocrat
mericson wrote:
Mon Apr 23, 2018 8:16 pm
What is the latest and greatest way to update all the IP addresses when migrating to a new server (including a floating IP I have behind NAT) ?
Vesta will always need to use the local IP assigned inside the VM, not the NATted floating IP. The reason for this is that Apache/nginx bind to the local IP.

Was thinking I might have a go at updating the script. What OS are you running?

You might also look at this: viewtopic.php?f=19&t=15055. It works on OSes which have /etc/apache2 as opposed to /etc/httpd

Re: How to Auto Change IP Address in VestaCP

Posted: Tue Apr 24, 2018 11:05 am
by mehargags
I don't know why you really need a script to do this actually?

Just change your IPs in your /etc/network/interfaces,
then

Code: Select all

/usr/local/vesta/bin/v-update-sys-ip
or goto WebUI >> IP >> Re-Read IP

then do

Code: Select all

/usr/local/vesta/bin/v-change-web-domain-ip
for your domains one by one or batch them

After that just rebuild Web/DNS/Email for your users and reboot your server.

I know its not a straightforward thing to change your IPs but Vesta has the functionality built in already. Changing your NIC IP is a bit of an invasive thing... so there isn't really an easier way.

Re: How to Auto Change IP Address in VestaCP

Posted: Wed Apr 25, 2018 12:18 am
by mericson
plutocrat wrote:
Tue Apr 24, 2018 3:26 am
Was thinking I might have a go at updating the script. What OS are you running?
CentOS 7

Re: How to Auto Change IP Address in VestaCP

Posted: Wed Jul 25, 2018 1:27 pm
by pablolp
mehargags wrote:
Tue Apr 24, 2018 11:05 am
I don't know why you really need a script to do this actually?

Just change your IPs in your /etc/network/interfaces,
then

Code: Select all

/usr/local/vesta/bin/v-update-sys-ip
or goto WebUI >> IP >> Re-Read IP

then do

Code: Select all

/usr/local/vesta/bin/v-change-web-domain-ip
for your domains one by one or batch them

After that just rebuild Web/DNS/Email for your users and reboot your server.

I know its not a straightforward thing to change your IPs but Vesta has the functionality built in already. Changing your NIC IP is a bit of an invasive thing... so there isn't really an easier way.
I think you're right

The external ip (WAN) is not needed for hosting but is necessary for the DNS server.

VestaCP automatically changes the current external IP to the new one in all domains and registries when you run v-update-sys-ip

I use a dynamic domain that is updated automatically with the current IP through a router (DD-WRT)

Code: Select all

DDNS: host.ddns.net > X.X.X.X
What I did was execute a CRON task that does this every 10 minutes, so everything stays updated.

Code: Select all

CRON: sudo /usr/local/vesta/bin/v-update-sys-ip */10 * * * *
This is the best I could do to avoid having to pay for a static IP. It's not the most efficient, but it works

Re: How to Auto Change IP Address in VestaCP

Posted: Sun Jan 05, 2020 7:26 am
by fertooos
I need to clarify one thing. Can I change my IP address without changing my residential address and zip code https://worldpostalcode.com/united-stat ... an-antonio? Is there any connection between these two things? I do not have much knowledge about computers so this may sound like a funny question. But I would appreciate it if someone can spend a minute and respond to me. Many thanks!

Re: How to Auto Change IP Address in VestaCP

Posted: Sat Jan 11, 2020 2:55 pm
by tom256
mehargags wrote:
Tue Apr 24, 2018 11:05 am
I don't know why you really need a script to do this actually?
I need this feature too. I'll explain you why I need it.
I buy VPS servers from hourly providers like digitalocean, I buy some servers based on hourly billing for some hours, and then I restore my previous snapshot to create multiple VMs like my main VM, which is configured fully for my needs and it uses VestaCP.
I buy new VMs by API, so everything is done automatically, but because of IPs are changed in New VMs, VestaCP doesn't work on them.
So I need a feature/script which changes my VestaCP settings if a new IP is detected for the server.

I'll add this feature request to this topic too:
viewtopic.php?f=20&t=19502#p80628

I hope VestaCP developers add this feature in their future updates as an option in web UI settings.

Re: How to Auto Change IP Address in VestaCP

Posted: Fri Jan 24, 2020 5:44 pm
by dpeca

Code: Select all

OLDIPV4='' # enter here
NEWIPV4=$(curl -s vestacp.com/what-is-my-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

Re: How to Auto Change IP Address in VestaCP

Posted: Fri Jan 24, 2020 5:52 pm
by mehargags
Nice script Dpeca
and if the guys want to get the NEWIPV4 prgramatically, you can put its value as

Code: Select all

$(curl ipinfo.io/ip)

Re: How to Auto Change IP Address in VestaCP

Posted: Fri Jan 24, 2020 5:52 pm
by dpeca
Edited :)