Commands
  • About
  • Software Development
    • Glossary
    • System Design
      • CAP Theorem
      • Data Migration
      • EAV Model
      • ETL Process
      • Event Sourcing
      • Outbox Pattern
      • SOLID Principles
    • Standards
      • Character Encoding
      • Twirp
    • Elixir
      • IEx
      • Mix
      • Libraries
      • Code Snippets
    • Node.js
      • TypeScript
  • Commands
    • Bookmarks
    • AWS
      • Athena
      • ECS
    • Docker
      • Manage Images
      • Manage Containers
    • File System
      • Grep
      • Search Files
      • Miscellaneous
    • Git
      • Setup New Project
      • Manage Remotes
      • Release Project
    • GPG
    • Kafka
      • Quick Start
    • Kubernetes
    • OpenShift
      • Manage Roles and Bindings
    • PostgreSQL
    • SSL / TLS
      • Common OpenSSL Commands
      • Create Self-signed Certificate
      • Java Truststore and Keystore
    • SSH
      • Key Management
      • Port Forwarding
    • YUM
      • List Repositories
      • List Packages
    • Miscellaneous
      • Network
Powered by GitBook
On this page
  1. Commands
  2. Miscellaneous

Network

PreviousMiscellaneous

Last updated 3 years ago

netstat

Linux

$ netstat -anp

-a: Show both listening and non-listening (for TCP this means established connections) sockets. -n: Show numerical addresses instead of trying to determine symbolic host, port or user names. -p: Show the PID and name of the program to which each socket belongs.

Mac

$ lsof -n -i

-i: displays all open network connections and the name of the process that is using the connection. Adding a 4, as in -i4, will display only IPv4 connections. Adding a 6 instead (-i6) will display only IPv6 connections. The -i flag can also be expanded to specify further details. -iTCP or -iUDP will only return TCP and UDP connections. -iTCP:25 will only return TCP connections on port 25. A range of ports can be specified with a dash, as it -iTCP:25-50. Using -i@1.2.3.4 will return only connections to the IPv4 address 1.2.3.4. IPv6 addresses can be specified in the same fashion. The @ precursor can also be used to specify hostnames in the same way, but both remote IP addresses and hostnames cannot be used simultaneously.

-P: disables the conversion of port numbers to port names, speeding up output.

-n: disables the conversion of network numbers to host names. When used with -P above, it can significantly speed up lsof's output.

-u: user only returns commands owned by the named user.

Source:

How to Use the Netstat Command on Mac