Determining Which IP Address Db2 Connections are Connecting To

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.

Ember Crooks
Ember Crooks

Ember is always curious and thrives on change. She has built internationally recognized expertise in IBM Db2, spent a year working with high-volume MySQL, and is now learning Snowflake. Ember shares both posts about her core skill sets and her journey learning Snowflake.

Ember lives in Denver and work from home

Articles: 544

One comment

  1. Thank you for sharing. I have DB2 running on Linux RH and I use a combination of LIST APPLICATION and nslookup I get from the DB2 command. Of course you can use dig (Domain Information Groper) which is used to query DNS name servers. Both tools are part of the bind-utils package.

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.