I want to check whether https service is listening on both IPv6 and IPv4.

And also when I am accessing url via browser, I want to know request is served by IPv4 or IPv6.


You can use netstat:

# netstat -tlnp | grep httpd
# netstat -tlnp | grep apache
# netstat -tlnp | grep nginx
# netstat -tlnp | grep ...

Then check that you get a line for each IP protocol version (tcp and tcp6).


ns=$(netstat -tlnp | grep httpd)

if grep 'tcp ' <<< "$ns" >/dev/null; then
    echo "httpd has a listening IPv4 socket."

if grep 'tcp6 ' <<< "$ns" >/dev/null; then
    echo "httpd has a listening IPv6 socket."

Note that you'll need root privileges with netstat if you want to see processes which belong to root (such as the Apache master process). If you want to use netstat as a standard user, remove the -p option and grep by IP and port instead. For instance:

$ netstat -tln | grep ''
$ netstat -tln | grep ''
$ netstat -tln | grep '::1:80'

Note that in this case, you don't need to grep again on tcp or tcp6, since the IP you're grep-ing already provides the information you are looking for. Whether you should look for or depends on your web server configuration.

  • I only get below line: tcp 0 0 :::443 :::* LISTEN 13734/httpd – Gaurav KS Sep 9 '15 at 9:21
  • not always, I only have tcp6 for apache, yet I connect to my site using ipv4. – Archemar Sep 9 '15 at 9:27
  • @Archemar You are probably using IPv6 transport over IPv4, a compatibility workaround put in place for the IPv4 > IPv6 transition phase. Also note that Apache supports IPv4-mapped IPv6 addresses. (Gaurav KS: I edited my answer) – John WH Smith Sep 9 '15 at 9:28

lsof is also useful.

You can see all listening addresses and established connections of nginx using IPv4 and IPv6 respectively as follows (run as root):

lsof -c nginx -a -i4
lsof -c nginx -a -i6

Show all connections of Google Chrome on the client host, both v4 and v6:

lsof -c chrome -a -i
  • I am a root user. and i cant see tcp6 in netstat output. – Gaurav KS Sep 9 '15 at 9:52
  • Then you can conclude that your servers are listening only on IPv4 address. – yaegashi Sep 9 '15 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.