Find What IP Address cPanel Site Is Using via Command Line

As a sysadmin, for some reason, I needed to find the IP address my websites were using on cPanel. This is probably a hard way but it works.

A huge amount of information is stored in the cPanel user file. Here’s a sample:

$ cat /var/cpanel/users/testusername
#cPanel — If you edit this file directly you must run /scripts/updateuserdomains after to rebuild the cache
BWLIMIT=5242880000
CONTACTEMAIL=admin@domain.com.au
CONTACTEMAIL2=
DEMO=0
DNS=primarydomain.com.au
FEATURELIST=default
HASCGI=0
IP=123.45.67.89
LANG=english
MAXADDON=5
MAXFTP=5
MAXLST=5
MAXPARK=5
MAXPOP=5
MAXSQL=5
MAXSUB=5
OWNER=root
PLAN=simple
RS=x3
STARTDATE=1238043252
USER=testusername

When you start parking domains and using addon domains, they also appear under this file as DNS1=blah.com, etc.

I use this command to extract the IP address out of this file.

$ cat /var/cpanel/users/putusernamehere | grep ‘IP=’ | cut -d’=’ -f2
123.45.67.89

Perfect! What more could you want!

I originally came up with these because when I move websites between servers I modify my local hosts file (C:\Windows\System32\drivers\etc\hosts or /etc/hosts) with the domain name and IP address of the new server to test. So I use this code to format it for me so I can copy and paste:

echo “Host file output for testing…”
websiteIP=`cat /var/cpanel/users/${destinationUserName} | grep ‘IP=’ | cut -d’=’ -f2`

echo “————————-
${websiteIP}    ${domainName}
${websiteIP}    www.${domainName}
————————-”
echo

Results in:

Host file output for testing…
————————-
123.45.67.89    primarydomain.com.au
123.45.67.89    www.primarydomain.com.au
————————-

Similar Posts:

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: -1 (from 1 vote)
Tags: , , , , .

What are your thoughts?