Determining Which IP Address Db2 Connections are Connecting To

Posted by

Database servers these days sometimes have a profusion of IP Addresses. IP V4, V6, management networks, and Virtual IP addresses all add to the ways applications connect in to a database server. I ran into an issue recently where I really needed to know what IP address was being used by an application, and thought I would share what I learned.

Information Needed

The output from the command used is going to be most useful if we first know what port number the Db2 instance we care about is listening on. You can look that up using the methodology in my article on finding what port number Db2 is listening on.

Command

Once you know what port number, you can use the netstat command to understand what IP address connections are coming in on:

$ netstat -an |grep 50004
tcp        0      0 0.0.0.0:50004           0.0.0.0:*               LISTEN
tcp        0      0 192.0.2.10:50004     198.51.100.3:46968      ESTABLISHED
tcp        0      0 192.0.2.10:50004     203.0.113.254:47546     ESTABLISHED
tcp        0      0 192.0.2.10:50004     198.51.100.3:47492      ESTABLISHED
tcp        0      0 192.0.2.10:50004     203.0.113.254:52776     ESTABLISHED
tcp        0      0 192.0.2.10:50004     198.51.100.3:41927      ESTABLISHED
tcp        0      0 192.0.2.10:50004     203.0.113.254:52770     ESTABLISHED
tcp        0      0 192.0.2.10:50004     203.0.113.254:47544     ESTABLISHED
tcp        0      0 192.0.2.10:50004     203.0.113.254:55306     ESTABLISHED
tcp        0      0 192.0.2.10:50004     203.0.113.254:52774     ESTABLISHED
tcp        0      0 192.0.2.10:50004     198.51.100.3:41926      ESTABLISHED
tcp        0      0 192.0.2.10:50004     198.51.100.3:44932      ESTABLISHED
tcp        0      0 192.0.2.10:50004     198.51.100.3:37380      ESTABLISHED
tcp        0      0 192.0.2.10:50004     203.0.113.254:52771     ESTABLISHED
tcp        0      0 192.0.2.10:50004     198.51.100.3:56792      ESTABLISHED
tcp        0      0 192.0.2.10:50004     198.51.100.3:47250      ESTABLISHED

The above was based on actual output from a server, with the IP addresses changed to protect the innocent.

In this output, the applications are all using 192.0.2.10 to connect to the database server. The servers that connections are coming in from are 198.51.100.3 and 203.0.113.254. It is easy using LIST APPLICATIONS or MON_GET_APPLICATION to see the ip addresses that connections are coming in from, but the address they are coming in to is not readily available within Db2 that I have seen.

Uses

This is probably not something you need every day, but for high availability environments that use a virtual IP, checking for connections that are not using the virtual IP is critical. One of the most common mistakes I see in high availability strategies is using the wrong IP address to connect to the database server. A virtual IP address isn’t much use unless every connection in to the database uses the right virtual IP address. I almost wish I could configure Db2 to not allow connections if they come in on the wrong IP address.

Lead Db2 Database Engineer and Service Delivery Manager , XTIVIA
Ember is always curious and thrives on change. Working in IT provides a lot of that change, but after 17 years developing a top-level expertise on Db2 for mid-range servers and more than 7 years blogging about it, Ember is hungry for new challenges and looks to expand her skill set to the Data Engineering role for Data Science. With in-depth SQL and RDBMS knowledge, Ember shares both posts about her core skill set and her journey into Data Science. Ember lives in Denver and work from home for XTIVIA, leading a team of Db2 DBAs.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.