Skip to main content
LPIC-2 Exam 201

Using netstat, iptables and lsof to determine network performance

LPIC-2-201For the LPIC-2 exam 117-201 from November 2013 you will be expected to know ho to determine performance and resource usage on your Linux System. For this tutorial we are using CentOS 6.5 and looking at the commands netstat, iptables and lsof and perhaps some more obcsure options to show the information that we want. Starting with netstat we can list ports that we are listening on, often important on a server:

netstat -antl

For TCP ports, and:

netstat -aunl

For UDP ports. Similarly we can also use lsof, (list open files), these sockets are feally open files:

lsof -i

And we can select IPv4 only with

lsof -i 4

And IPv6 with

lsof -i 6

The command iptables is often associated with firewalls but even without any firewall rules in place we can use iptables as the root use to display how much traffic visits the machine as well as using it to display traffic that meets firewall rules when set, simple use:

iptables -nvL INPUT

You can reset counters with :

iptables -Z

Back with netsat we can use

netstat -i

To display receive and transmit data on a per interface basis. We also see errors here that can be useful in diagnosing faulty network hardware. The final command we look at is:

netstat -s

To display per protocol statics and how much has be sent and received.