Linux Networking Commands for Security: ip, ss, dig and tcpdump

A small set of Linux commands answers most network security questions on a host you manage. ip shows addresses, routes and neighbours. ss lists listening ports and open connections with the owning process. dig checks DNS answers. curl tests a web service and its TLS certificate. tcpdump captures packets for close inspection.

Mar 21, 2025 - 10:34
Updated: 
103.7k

Networking in IT Infrastructure · Troubleshooting

Network Security, Linux Administration, Security Tools, Authorized Labs & CTFs

Linux Networking Commands for Security: ip, ss, dig and tcpdump

Quick answer: A small set of Linux commands answers most network security questions on a host you manage. ip shows addresses, routes and neighbours. ss lists listening ports and open connections with the owning process. dig checks DNS answers. curl tests a web service and its TLS certificate. tcpdump captures packets for close inspection. The older net-tools commands such as ifconfig and netstat are deprecated on many distributions in favour of iproute2. Use these tools on your own systems, or with written authorisation, to find unexpected listeners, odd connections and misconfigured DNS before an attacker does.

Key takeaways

  • Prefer ip and ss over ifconfig and netstat on modern systems.
  • ss -tulpn quickly shows every listening service and its process.
  • dig reveals what DNS really returns, which helps spot hijacks and typos.
  • tcpdump with a narrow filter captures evidence without flooding the disk.
  • Capture and scan only networks you own or are authorised to test.

Table of Contents

Which Commands Answer Which Security Questions?

QuestionModern commandOlder equivalent
What addresses does this host have?ip -br addrifconfig
Where does traffic go?ip routeroute -n
Which MAC addresses are nearby?ip neigharp -n
What is listening?ss -tulpnnetstat -tulpn
Who is connected now?ss -tnp state establishednetstat -tnp
What does DNS return?dig example.com Anslookup
What is on the wire?tcpdumptcpdump

The Debian wiki records why net-tools was deprecated; our net-tools explainer covers the older commands.

How Do You Inspect Interfaces and Routes With ip?

ip -br addr          # brief list of interfaces and addresses
ip route             # routing table, including the default gateway
ip neigh             # ARP and IPv6 neighbour cache
ip -s link           # per-interface packet and error counters

An unexpected default route, a new interface, or a gateway MAC address that keeps changing in ip neigh can point to misconfiguration or ARP spoofing. The ip manual page lists every object and option.

How Do You Find Listening Ports and Connections With ss?

sudo ss -tulpn                     # TCP and UDP listeners with process names
sudo ss -tnp state established     # current TCP sessions with processes
ss -s                              # summary counts by state

In ss -tulpn, a service bound to 0.0.0.0 or [::] is reachable from every interface, while 127.0.0.1 is local only. Any listener you cannot explain deserves investigation. Attackers run the same discovery, recorded in MITRE ATT&CK T1049, so knowing your own baseline helps. See the ss manual page for filters.

How Do You Check DNS and Web Services?

dig example.com A +short           # address records
dig example.com MX                 # mail servers
dig @1.1.1.1 example.com A         # compare with a public resolver
curl -sI https://example.com       # response headers only
curl -vI https://example.com 2>&1 | grep -i expire   # certificate expiry

If your local resolver and a public resolver give different answers for your own domain, check for stale records or tampering. The dig options are documented in the BIND 9 manual pages.

How Do You Capture Traffic Safely With tcpdump?

sudo tcpdump -i eth0 -nn port 53 -c 100           # 100 DNS packets
sudo tcpdump -i eth0 -nn host 192.0.2.10 -w case1.pcap
tcpdump -nn -r case1.pcap                          # read a saved capture

Always filter by host, port or count, and write to a file you can open later in Wireshark. Packet captures can hold passwords and personal data, so store them securely and delete them when the case closes. The tcpdump manual explains capture filters.

How Do These Commands Fit Incident Triage?

Triage stepCommands
Snapshot network stateip -br addr, ip route, sudo ss -tunap
Spot unknown listenerssudo ss -tulpn, compared with baseline
Check suspicious domainsdig, plus proxy and DNS logs
Collect evidencetcpdump -w to a protected file

Save command output with timestamps before changing anything, as NIST SP 800-61 Rev. 3 advises. In India, the CERT-In directions require reporting listed incidents within 6 hours and keeping logs for 180 days.

Capturing traffic or probing systems you do not own can break the IT Act 2000, Sections 43 and 66. Get written authorisation for any test. For more everyday commands, see the most useful Linux commands. Practice in guided labs through our Linux and network security training.

References

Frequently Asked Questions

Use ss on modern systems. It comes with iproute2, is faster on busy hosts, and shows the same listening and connection details as netstat.

ifconfig belongs to net-tools, which many distributions no longer install by default. The ip command from iproute2 replaces it for addresses and routes.

Run sudo ss -tulpn. The users column shows the process name and PID for every listening TCP and UDP socket on the host.

It means the service listens on every IPv4 interface and can be reached from the network. 127.0.0.1 means it only accepts local connections.

dig shows the exact DNS records returned. Comparing answers from different resolvers helps spot hijacked records, stale entries and typo domains.

It is legal on networks you own or manage with permission. Capturing other people’s traffic without authorisation can breach the IT Act 2000 and privacy law.

Use a capture filter for host or port, set a packet count with -c, and write to a file with -w so you can analyse it later.

Record addresses, routes, listening ports and established connections with timestamps before making changes, so evidence is preserved for the investigation.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.