Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Mass Change VirtualHost IP via CLI/SSH

Discussion in 'General Discussion' started by jefferyw18, Dec 7, 2015.

  1. jefferyw18

    jefferyw18 Well-Known Member

    Joined:
    Apr 10, 2004
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    156
    Location:
    Vancouver BC Canada
    cPanel Access Level:
    DataCenter Provider
    here is what I have tried so far what am I missing?

    Code:
    root@server [~]# cat /var/cpanel/mainip
    192.168.0.10
    
    changed it to.....

    Code:
    root@server [~]# cat /var/cpanel/mainip
    192.168.2.10
    
    Code:
    root@server [~]# 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
    root@jeff [~]# sed -i 's/192.168.0.10/192.168.2.10/g' /var/cpanel/users/*
    root@server [~]# 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:
    root@server [~]# /usr/local/cpanel/scripts/updateuserdomains
    root@server [~]# /scripts/rebuildhttpdconf
    
    httpd.conf is still showing old IP

    Code:
    root@server [~]# 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>
    
     
  2. jefferyw18

    jefferyw18 Well-Known Member

    Joined:
    Apr 10, 2004
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    156
    Location:
    Vancouver BC Canada
    cPanel Access Level:
    DataCenter Provider
    Code:
    root@server [~]# 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
    
     
  3. jefferyw18

    jefferyw18 Well-Known Member

    Joined:
    Apr 10, 2004
    Messages:
    45
    Likes Received:
    0
    Trophy Points:
    156
    Location:
    Vancouver BC Canada
    cPanel Access Level:
    DataCenter Provider
    Solved the problem with this method

    Code:
    root@server [~]# sed -i 's/192.168.0.10/192.168.2.10/g' /usr/local/apache/conf/httpd.conf
    root@server [~]# /usr/local/cpanel/bin/userdata_update
    root@server [~]# /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:
    root@server [~]# 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>
    
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,323
    Likes Received:
    1,851
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice