Mass Change VirtualHost IP via CLI/SSH

jefferyw18

Well-Known Member
Apr 10, 2004
45
0
156
Vancouver BC Canada
cPanel Access Level
DataCenter Provider
here is what I have tried so far what am I missing?

Code:
[email protected] [~]# cat /var/cpanel/mainip
192.168.0.10
changed it to.....

Code:
[email protected] [~]# cat /var/cpanel/mainip
192.168.2.10
Code:
[email protected] [~]# grep -rn 192.168. /var/cpanel/users
/var/cpanel/users/user1:13:IP=192.168.0.10
/var/cpanel/users/user2:13:IP=192.168.0.10
/var/cpanel/users/user3:13:IP=192.168.0.10
[email protected] [~]# sed -i 's/192.168.0.10/192.168.2.10/g' /var/cpanel/users/*
[email protected] [~]# grep -rn 192.168. /var/cpanel/users
/var/cpanel/users/user1:13:IP=192.168.2.10
/var/cpanel/users/user2:13:IP=192.168.2.10
/var/cpanel/users/user3:13:IP=192.168.2.10
Looks like these changed just fine ;-)

Code:
[email protected] [~]# /usr/local/cpanel/scripts/updateuserdomains
[email protected] [~]# /scripts/rebuildhttpdconf
httpd.conf is still showing old IP

Code:
[email protected] [~]# cat /usr/local/apache/conf/httpd.conf | grep '<VirtualHost'
<VirtualHost *>
<VirtualHost 192.168.0.10:80>
<VirtualHost 192.168.0.10:80>
<VirtualHost 192.168.0.10:80>
<VirtualHost 192.168.0.10:80>
<VirtualHost 192.168.0.10:80>
<VirtualHost 192.168.0.10:80>
<VirtualHost 192.168.0.10:80>
 

jefferyw18

Well-Known Member
Apr 10, 2004
45
0
156
Vancouver BC Canada
cPanel Access Level
DataCenter Provider
Code:
[email protected] [~]# strace -F /scripts/rebuildhttpdconf 2>&1 | grep 192.168.
read(3, "pst0\5\t\2\0\0\0\1\n\f192.168.2.10", 8192) = 25
read(3, "192.168.2.10\n", 8192)  = 13
stat("/var/cpanel/userdata/nobody/192.168.0.10", {st_mode=S_IFREG|0644, st_size=293, ...}) = 0
stat("/var/cpanel/userdata/nobody/192.168.0.10", {st_mode=S_IFREG|0644, st_size=293, ...}) = 0
stat("/var/cpanel/userdata/nobody/192.168.0.10", {st_mode=S_IFREG|0644, st_size=293, ...}) = 0
open("/var/cpanel/userdata/nobody/192.168.0.10.cache", O_RDONLY) = 3
stat("/var/cpanel/userdata/nobody/192.168.0.10_SSL", 0x7f09f5889880) = -1 ENOENT (No such file or directory)
[pid 11374] read(5, "#<VirtualHost 192.168.2.10:80>\n#"..., 4096) = 4096
 

jefferyw18

Well-Known Member
Apr 10, 2004
45
0
156
Vancouver BC Canada
cPanel Access Level
DataCenter Provider
Solved the problem with this method

Code:
[email protected] [~]# sed -i 's/192.168.0.10/192.168.2.10/g' /usr/local/apache/conf/httpd.conf
[email protected] [~]# /usr/local/cpanel/bin/userdata_update
[email protected] [~]# /scripts/rebuildhttpdconf
info [rebuildhttpdconf] Missing owner for domain <HOSTNAME HERE>, force lookup to root
info [rebuildhttpdconf] Missing group for domain <HOSTNAME HERE>, using nobody
Built /usr/local/apache/conf/httpd.conf OK
Code:
[email protected] [~]# cat /usr/local/apache/conf/httpd.conf | grep '<VirtualHost'
<VirtualHost 192.168.2.10:80>
<VirtualHost *>
<VirtualHost 192.168.2.10:80>
<VirtualHost 192.168.2.10:80>
<VirtualHost 192.168.2.10:80>
<VirtualHost 192.168.2.10:80>
<VirtualHost 192.168.2.10:80>
<VirtualHost 192.168.2.10:80>
<VirtualHost 192.168.2.10:80>
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,910
2,216
363
Hello :)

Note that you may also find this command helpful in the future:

Code:
# /usr/local/cpanel/bin/setsiteip --help
Usage: /usr/local/cpanel/bin/setsiteip [-u user | domain] ip
Usage: /usr/local/cpanel/bin/setsiteip --help
Thank you.