Open ports by interface

I often use what is below to get a listing of currently open ports by interface. If you find you can’t “see” a port from another computer, and…

it is open on the IP to which you are trying to connect

-or-

it is open on 0.0.0.0 (all interfaces)

…then check the server firewall (iptables), or check with the network team.

for ip in $(netstat -an | awk '$NF == "LISTEN" {split($4,s,":");print s[1]}' | sort -u); do
  echo $ip
  echo "------------------------"
  netstat -an | awk -v ip=$ip '$NF == "LISTEN" && $4 ~ ip":" {split($4,s,":"); print s[2]}' | sort -n
  echo "------------------------"
done

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.