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
  • 1
  • 2
  • 3
  • 4
  • Next
crypto
Posts: 5
Joined: Wed Oct 08, 2014 8:16 pm

How to Auto Change IP Address in VestaCP
  • Quote

Post by crypto » Wed Oct 08, 2014 8:48 pm

In case you change vps's/ips and need to change the Shared Ip for your vestacp server, can be a real pain to do by hand.

Option 1 - Best Way Download and Run Code

Code: Select all

wget http://www.nobill.tv/dl/changeip.tar.gz
tar -zxvf changeip.tar.gz
mv v-change-server-ip /usr/local/vesta/bin/
v-change-server-ip OLDIP NEWIP

Option 2 - Long way Create it yourself

Code: Select all

touch /usr/local/vesta/bin/v-change-server-ip
chmod 0755 /usr/local/vesta/bin/v-change-server-ip

Code: Select all

#!/bin/sh

#script to change ips on a VestaCP server.
#usage:
# $0 <oldip> <newip>

LOG=/var/log/vesta/system.log

MYUID=`/usr/bin/id -u`
if [ "$MYUID" != 0 ]; then
        echo "You require Root Access to run this script";
        exit 0;
fi

if [ $# != 2 ] && [ $# != 3 ]; then
        echo "Usage:";
        echo "$0 <oldip> <newip> [<file>]";
        echo "you gave #$#: $0 $1 $2 $3";
        exit 0;
fi

OLD_IP=$1
NEW_IP=$2

HAVE_HTTPD=1
HAVE_NGINX=1

DATE=`date '+%F %X'`
BIN=`echo $0 | awk -F/ '{print $NF}'`

log()
{
        echo -e "$1";
        echo -e "$1" >> $LOG;
}

swapfile()
{
        if [ ! -e $1 ]; then
                log "Cannot Find $1 to change the IPs. Skipping...";
                return;
        fi

        TEMP="perl -pi -e 's/${OLD_IP}/${NEW_IP}/g' $1"
        eval $TEMP;

        log "$DATE $BIN $1\t: $OLD_IP -> $NEW_IP";
}

if [ $# = 3 ]; then
        swapfile $3;
        exit 0;
fi


IPFILE_OLD=/usr/local/vesta/data/ips/$OLD_IP
IPFILE_NEW=/usr/local/vesta/data/ips/$NEW_IP
if [ ! -e $IPFILE_OLD ]; then
        echo -n "$IPFILE_OLD does not exist.  Do you want to continue anyway? (y/n) : ";
        read YESNO;
        if [ "$YESNO" != "y" ]; then
                exit 0;
        fi
else
        mv -f $IPFILE_OLD $IPFILE_NEW
        log "$DATE $0 $IPFILE_OLD\t: $OLD_IP -> $NEW_IP";
fi

if [ "${HAVE_HTTPD}" -eq 1 ]; then
        if [ -e /etc/httpd/conf.d/${OLD_IP}.conf ]; then
                swapfile /etc/httpd/conf.d/${OLD_IP}.conf
                mv -f /etc/httpd/conf.d/$OLD_IP.conf /etc/httpd/conf.d/${NEW_IP}.conf
        fi
        swapfile /etc/httpd/conf.d/mod_extract_forwarded.conf
fi

if [ "${HAVE_NGINX}" -eq 1 ]; then
        if [ -e /etc/nginx/conf.d/${OLD_IP}.conf ]; then
                swapfile /etc/nginx/conf.d/${OLD_IP}.conf
                mv -f /etc/nginx/conf.d/$OLD_IP.conf /etc/nginx/conf.d/${NEW_IP}.conf
        fi
fi

swapfile /etc/hosts

ULDDU=/usr/local/vesta/data/users

for i in `ls $ULDDU`; do
{

        if [ ! -d $ULDDU/$i ]; then
                continue;
        fi

        swapfile $ULDDU/$i/web.conf
        swapfile $ULDDU/$i/dns.conf
        for j in `ls $ULDDU/$i/dns/*.conf`; do
        {
                swapfile $j
        };
        done;

        if [ "${HAVE_HTTPD}" -eq 1 ]; then
                swapfile /home/$i/conf/web/httpd.conf
        fi
        if [ "${HAVE_NGINX}" -eq 1 ]; then
                swapfile /home/$i/conf/web/nginx.conf
        fi

        for j in `ls /home/$i/conf/dns/*.db`; do
        {
                swapfile $j
        };
        done;

};
done;

#this is needed to update the serial in the db files.
if [ "${HAVE_HTTPD}" -eq 1 ]; then
   service httpd restart
fi
if [ "${HAVE_NGINX}" -eq 1 ]; then
   service nginx restart
fi

echo "*** Done swapping $OLD_IP to $NEW_IP ***";
Enjoy!
Top

uscreator
Posts: 43
Joined: Mon Oct 20, 2014 5:05 pm

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

Post by uscreator » Tue Oct 21, 2014 3:49 pm

Wow this is wonderful script and much needed.
Thank you very much!

P.S on a side note it did not fix my apache2 for some reason.
But everything else seems to be changed to new IP.

Apache is still complaining...

EDIT 1:
ok I just figure it out... old IP configuration file was still in Apache directory and it was trying to start it and it collide with new ip.conf file

But nevertheless it's a very useful and excellent script. Thanks again!

EDIT 2:
file location: /etc/apache2/conf.d/11.0.2.75.conf
After script runs it will create file with a new IP.
You need to go and remove file with old IP
Last edited by uscreator on Thu Oct 23, 2014 2:33 pm, edited 1 time in total.
Top

gobinathdpi
Posts: 7
Joined: Wed Mar 12, 2014 9:16 am

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

Post by gobinathdpi » Wed Oct 22, 2014 8:41 am

Ok any idea or explanation on how to remove that file?
Top

uscreator
Posts: 43
Joined: Mon Oct 20, 2014 5:05 pm

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

Post by uscreator » Thu Oct 23, 2014 2:33 pm

gobinathdpi wrote:Ok any idea or explanation on how to remove that file?
file location: /etc/apache2/conf.d/11.0.2.75.conf
After script runs it will create file with a new IP.conf.
You need to go and remove file with old IP.conf
Top

crypto
Posts: 5
Joined: Wed Oct 08, 2014 8:16 pm

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

Post by crypto » Wed Nov 26, 2014 5:08 pm

Not everyone has the /etc/apache2/ dir. Most default centos cloud installs are in /etc/httpd/ but may mod to detect what dir.

Glad you find this usefull, I know it helps me with a large number of servers to manage. Hopefully they will include this script by default with a new release of vestacp.
Top

jhoedram
Posts: 21
Joined: Wed Sep 03, 2014 2:55 pm

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

Post by jhoedram » Mon Dec 29, 2014 7:13 pm

Hello, I am also having problems with apache

I changed ip with the first tutorial Friend "crypto" and everything works fine except for apache, I thought the problem would be for you comment. However I check my files and ip is average.

What do you think could be the problem with apache?

attached image : Image
The new ip is set in the image (this crossed out), I do not see any trace of the old ip.

I hope you can help me, thanks.

uscreator wrote:Wow this is wonderful script and much needed.
Thank you very much!

P.S on a side note it did not fix my apache2 for some reason.
But everything else seems to be changed to new IP.

Apache is still complaining...

EDIT 1:
ok I just figure it out... old IP configuration file was still in Apache directory and it was trying to start it and it collide with new ip.conf file

But nevertheless it's a very useful and excellent script. Thanks again!

EDIT 2:
file location: /etc/apache2/conf.d/11.0.2.75.conf
After script runs it will create file with a new IP.
You need to go and remove file with old IP
Top

uscreator
Posts: 43
Joined: Mon Oct 20, 2014 5:05 pm

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

Post by uscreator » Mon Dec 29, 2014 9:24 pm

jhoedram wrote:Hello, I am also having problems with apache
Try to run configuration check for apache and see what errors you get

Code: Select all

apachectl configtest
Top

jhoedram
Posts: 21
Joined: Wed Sep 03, 2014 2:55 pm

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

Post by jhoedram » Tue Dec 30, 2014 9:26 pm

This is menssage :

[Tue Dec 30 16:23:09 2014] [warn] NameVirtualHost 104.xxx.139.21:8443 has no VirtualHosts
Syntax OK

uscreator wrote:
jhoedram wrote:Hello, I am also having problems with apache
Try to run configuration check for apache and see what errors you get

Code: Select all

apachectl configtest
Top

uscreator
Posts: 43
Joined: Mon Oct 20, 2014 5:05 pm

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

Post by uscreator » Tue Dec 30, 2014 10:05 pm

For fix follow directions → viewtopic.php?f=11&t=4483
jhoedram wrote:This is menssage :
[Tue Dec 30 16:23:09 2014] [warn] NameVirtualHost 104.xxx.139.21:8443 has no VirtualHosts
Syntax OK
Top

xtinagp
Posts: 1
Joined: Sat Jan 10, 2015 1:04 am

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

Post by xtinagp » Sat Jan 10, 2015 1:08 am

This is an old post, but after running the marvelous solution posted by @Crypto I still had some errors on my site.

There are two additional places to change the IP. (Ubuntu 12.04 server)

/home/admin/conf/web/apache2.conf
First line has the virtual host IP

and

/home/admin/conf/web/snginx.conf
Second line lists the IP where it is supposed to listen to.

Hope this helps!
Top


Post Reply
  • Print view

40 posts
  • 1
  • 2
  • 3
  • 4
  • Next

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
 

 

Login  •  Register

I forgot my password