The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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:
    6
    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:
    6
    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:
    6
    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:
    30,678
    Likes Received:
    652
    Trophy Points:
    113
    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.
     
Loading...

Share This Page