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.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You can use
# 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).
#!/bin/bash ns=$(netstat -tlnp | grep httpd) if grep 'tcp ' <<< "$ns" >/dev/null; then echo "httpd has a listening IPv4 socket." fi if grep 'tcp6 ' <<< "$ns" >/dev/null; then echo "httpd has a listening IPv6 socket." fi
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 '0.0.0.0:80' $ netstat -tln | grep '127.0.0.1:80' $ netstat -tln | grep '::1:80'
Note that in this case, you don't need to
grep again on
tcp6, since the IP you're
grep-ing already provides the information you are looking for. Whether you should look for 127.0.0.1 or 0.0.0.0 depends on your web server configuration.