Page 2 of 4

Re: How to Auto Change IP Address in VestaCP

Posted: Thu Mar 26, 2015 5:36 pm
by jobarte
Hi @crypto,

You have this code on github? I want to help you wtih bug fixes. If not, I can put on github?

Re: How to Auto Change IP Address in VestaCP

Posted: Mon Nov 30, 2015 5:44 am
by psaproxy
Hello

I have completed the instruction. Ip has been successfully changed.
But now problem. Site is not open: 504 Gateway Time-out (nginx).

nginx log:
[error] 11506#0: *7 upstream timed out (110: Connection timed out) while connecting to upstream, client: 178.76.231.212, server: _, request: "GET /favicon.ico HTTP/1.1", upstream: "http://10.73.117.115:8080/error/50x.html", host: "54.74.17.21", referrer: "http://54.74.87.18/"

178.76.231.212 - it is my ip
10.73.117.115 - it is new private ip, it used in instruction
54.74.17.21 - it is new public ip, I was set this ip as NAT ip in control panel

How fix it?

Re: How to Auto Change IP Address in VestaCP

Posted: Tue Dec 01, 2015 9:39 pm
by kaines
hi, i have the same issue... i get:

2015/12/01 22:36:14 [error] 3075#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: MYIP, server: domainame.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://SERVERIP2:8080/favicon.ico", host: "DOMAINAME.COM", referrer: "http://DOMAINNAME.COM/"

any idea what could this be?

Re: How to Auto Change IP Address in VestaCP

Posted: Wed Dec 02, 2015 10:05 am
by psaproxy
my solution
xx.xx.xx.xx - old private IP
yy.yy.yy.yy - new private IP

1) run instruction from first post

2)
grep -r "xx.xx.xx.xx" /etc/
grep -r "xx.xx.xx.xx" /home/
grep -r "xx.xx.xx.xx" /usr/local/
and replace all "xx.xx.xx.xx"/"xx-xx-xx-xx" on "yy.yy.yy.yy"/"yy-yy-yy-yy"

3)
rename files
/etc/apache2/conf.d/xx.xx.xx.xx.conf in yy.yy.yy.yy.conf
/etc/nginx/conf.d/xx.xx.xx.xx.conf in yy.yy.yy.yy.conf

4)
set new public IP in NAT Vesta control panel

5)
restart server

And may be you need change public IP on WEB and DNS sections in Vesta control panel

Re: How to Auto Change IP Address in VestaCP

Posted: Thu Dec 03, 2015 11:15 pm
by kaines
in my case i had to do this:

/etc/apache2/conf.d - rename OLDIP.conf to NEWIP.conf than edit NEWIP.conf and ranem old ip to new one.
/etc/iptables.rules - change this line: -A INPUT -s OLDIP/32 -j ACCEPT -> -A INPUT -s NEWIP/32 -j ACCEPT

after that i restarted apache and nginx and everything worked well.

Hope it will help someone ;)

Re: How to Auto Change IP Address in VestaCP

Posted: Tue Feb 23, 2016 6:34 am
by conneXions
I think psaproxy's post above is quite helpful
though that NAT step may not apply for everyone (not for me anyway).

an additional step that finally got everything working (before this only vestacp is accessable using domain.com:8083) for me is:

restart iptables from within the server tab of vestacp (or use command line I suppose)

otherwise I couldn't even get my homepage (domain.com) to load.

Re: How to Auto Change IP Address in VestaCP

Posted: Fri Apr 08, 2016 11:09 am
by aeromaxx
Hello,

I have amended crypto's original script from post #1.

It now contains a switch to be verbose or not.

It also has some checks for empty directories, as the original script gave errors when my dns folder was empty, so it now checks for this.

Some users like myself use apache2 and not httpd, and as such the configuration options may need to changed to reflect this.

Code: Select all

#!/bin/sh

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

#########################
# Configuration Options #
#########################

HAVE_APACHE2=1;
HAVE_HTTPD=0;
HAVE_NGINX=1;
VERBOSE=0;

# DON'T CHANGE ANYTHING BELOW THIS LINE
# -------------------------------------

clear;

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;

echo "";
echo "######################################";
echo "# Changing VestaCP Server IP Address #";
echo "######################################";
echo "";
sleep 5;

OLD_IP=$1;
NEW_IP=$2;

if [ "${VERBOSE}" -eq 1 ]; then
	echo "Old IP: $OLD_IP";
        echo "New IP: $NEW_IP";
        echo "";

        sleep 5;
fi;

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

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

	if [ "${VERBOSE}" -eq 1 ]; then
                echo "";
        fi;
}

swapfile()
{
	if [ "${VERBOSE}" -eq 1 ]; then
		echo "Replacing Old IP with New IP in $1...";
	        sleep 5;
	fi;

        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;

        echo "";

        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_APACHE2}" -eq 1 ]; then
        if [ -e /etc/apache2/conf.d/${OLD_IP}.conf ]; then
		swapfile /etc/apache2/conf.d/${OLD_IP}.conf;
                mv -f /etc/apache2/conf.d/$OLD_IP.conf /etc/apache2/conf.d/${NEW_IP}.conf;
        fi;
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;

        if [ `find $ULDDU/$i/dns/ -type f | wc -l` -gt 0 ]; then
                for j in `ls $ULDDU/$i/dns/*.conf`; do
                {
                        swapfile $j;
                };
                done;

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

        if [ "${HAVE_APACHE2}" -eq 1 ]; then
                swapfile /home/$i/conf/web/apache2.conf;
        fi;

        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;

};
done;

#this is needed to update the serial in the db files.
if [ "${HAVE_APACHE2}" -eq 1 ]; then
	if [ "${VERBOSE}" -eq 1 ]; then
		echo "Restarting service: apache2...";
	fi;

        service apache2 restart;

	if [ "${VERBOSE}" -eq 1 ]; then
		echo " done.";
		echo "";
	fi;
fi;

if [ "${HAVE_HTTPD}" -eq 1 ]; then
	if [ "${VERBOSE}" -eq 1 ]; then
		echo "Restarting service: httpd...";
	fi;

        service httpd restart;

	if [ "${VERBOSE}" -eq 1 ]; then
		echo " done.";
		echo "";
	fi;
fi;

if [ "${HAVE_NGINX}" -eq 1 ]; then
	if [ "${VERBOSE}" -eq 1 ]; then
		echo "Restarting service: nginx...";
	fi;

        service nginx restart;

	if [ "${VERBOSE}" -eq 1 ]; then
		echo " done.";
		echo "";
	fi;
fi;

if [ "${VERBOSE}" -eq 0 ]; then
        echo "";
fi;

echo "*** Done swapping $OLD_IP to $NEW_IP ***";
echo "";

Re: How to Auto Change IP Address in VestaCP

Posted: Mon Apr 18, 2016 11:09 pm
by pandabb
very useful. thanks

Re: not for the faint heartes

Posted: Fri Apr 22, 2016 9:32 pm
by Falzo
one should easily be able to search and replace either for filenames or for content of files with two commands...
not a lot of magic after all, did this multiple times on standard debian installs - but do use at your own risk!

Code: Select all

find /home /etc /usr -type f -exec perl -i -p -e 's/11\.22\.33\.44/66\.77\.88\.99/g' {} \;
find / -name *11.22.33.44* -exec rename 's/11\.22\.33\.44/66\.77\.88\.99/g' {} \;
- 11.22.33.44 has to be replaced by your old ip and 66.77.88.99 by your new one
- you need to keep the . escaped properly as shown above
- don't do this on /var if you don't exactly know what you are doing. at least mysql doesn't like that kind of find and replace with its files.

as there is not much output at all, you might want to find/grep for your IP as names/in files beforehand, to see whats gonna be changed.
and of course don't forget to restart your services afterwards (including vesta).

Re: How to Auto Change IP Address in VestaCP

Posted: Mon Dec 05, 2016 5:44 am
by anuradhan
Option 1 didnt wrk .
i worked with option 2 and it works.
Thanks for the great script :)
crypto wrote: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!