Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Dev Section 3rd Party Software
  • Search

How to Auto Change IP Address in VestaCP

Section with additional software for Vesta
Post Reply
  • Print view
Advanced search
40 posts
  • Previous
  • 1
  • 2
  • 3
  • 4
mericson
Posts: 44
Joined: Thu Apr 06, 2017 12:37 am

Re: How to Auto Change IP Address in VestaCP
  • Quote

Post by mericson » Mon Apr 23, 2018 8:16 pm

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?
Top

plutocrat
Posts: 232
Joined: Fri Jan 27, 2017 9:16 am

Os: Ubuntu 17x
Web: apache + nginx
Re: How to Auto Change IP Address in VestaCP
  • Quote

Post by plutocrat » Tue Apr 24, 2018 3:26 am

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
Top

mehargags
Support team
Posts: 1096
Joined: Sat Sep 06, 2014 9:58 pm
Contact:
Contact mehargags
Website Skype

Os: Debian 8x
Web: apache + nginx
Re: How to Auto Change IP Address in VestaCP
  • Quote

Post by mehargags » 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.
Top

mericson
Posts: 44
Joined: Thu Apr 06, 2017 12:37 am

Re: How to Auto Change IP Address in VestaCP
  • Quote

Post by mericson » Wed Apr 25, 2018 12:18 am

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
Top

pablolp
Posts: 4
Joined: Wed Jul 25, 2018 1:07 pm

Os: CentOS 6x
Web: apache + nginx
Re: How to Auto Change IP Address in VestaCP
  • Quote

Post by pablolp » Wed Jul 25, 2018 1:27 pm

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
Top

tom256
Posts: 24
Joined: Sun Sep 16, 2018 3:51 pm

Os: Ubuntu 15x
Web: apache + nginx
Re: How to Auto Change IP Address in VestaCP
  • Quote

Post by tom256 » Sat Jan 11, 2020 2:55 pm

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.
Top

dpeca
VestaCP Team
Posts: 473
Joined: Wed Nov 25, 2015 7:30 pm

Re: How to Auto Change IP Address in VestaCP
  • Quote

Post by dpeca » Fri Jan 24, 2020 5:44 pm

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
Top

mehargags
Support team
Posts: 1096
Joined: Sat Sep 06, 2014 9:58 pm
Contact:
Contact mehargags
Website Skype

Os: Debian 8x
Web: apache + nginx
Re: How to Auto Change IP Address in VestaCP
  • Quote

Post by mehargags » Fri Jan 24, 2020 5:52 pm

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)
Top

dpeca
VestaCP Team
Posts: 473
Joined: Wed Nov 25, 2015 7:30 pm

Re: How to Auto Change IP Address in VestaCP
  • Quote

Post by dpeca » Fri Jan 24, 2020 5:52 pm

Edited :)
Top

Spheerys
Posts: 225
Joined: Tue Dec 29, 2015 12:36 pm

Os: Debian 7x
Web: apache + nginx
Re: How to Auto Change IP Address in VestaCP
  • Quote

Post by Spheerys » Fri Jan 24, 2020 5:58 pm

$(curl ipinfo.io/ip) give the IP correctly, but $(curl -s vestacp.com/what-is-my-ip/) don't
There is a % or a # after it....
Top


Post Reply
  • Print view

40 posts
  • Previous
  • 1
  • 2
  • 3
  • 4

Return to “3rd Party Software”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

cron

Login  •  Register

I forgot my password