nstat, lnstat, ifstat, rtmon, routel, rdma, dcb (1/2)
nstat, lnstat, ifstat, rtmon, routel and rdma are small iproute2 helpers that read the Linux kernel's network counters, live interface rates and route changes. They answer questions like "are we retransmitting?", "is the conntrack table full?" and "when did the default route disappear?".
58.1 What they do, where they run
| Tool | Reads / does | Where |
|---|---|---|
| nstat | SNMP counters (/proc/net/snmp, netstat): delta since last run | Linux, iproute2 |
| lnstat | /proc/net/stat files (nf_conntrack, rt_cache, arp_cache) | Linux, iproute2 |
| ifstat | KB/s in/out per interface from /proc/net/dev | Linux, classic ifstat package |
| rtmon | Logs link/address/route changes from netlink to a file | Linux, iproute2 |
| routel | Prints ip route output as a table | Linux, iproute2 (Python script) |
| rdma | Manages RDMA devices (InfiniBand, RoCE, iWARP) | Linux, needs RDMA hardware + kernel support |
58.2 How nstat works
- The kernel keeps SNMP counters for IP, ICMP, TCP, UDP.
- nstat saves the counters in a history file; each run shows only the difference since the previous run.
- So nstat -n (save, no output) -> do something -> nstat shows exactly what that action changed.
- Step 1
1.PC 192.168.78.10 runs nstat -n: current counters saved to history
- Step 2
2.PC pings the server 192.168.78.20 five times through the Docker bridge
- Step 3
3.Server replies; the kernel updates its SNMP counters
- Step 4
4.nstat again prints only the difference
- Step 5
5.IcmpOutEchos 5, IcmpInEchoReps 5, IpExtOutOctets 420
58.3 nstat in practice
nstat -nping -c 5 -q 192.168.78.20 >/dev/nullnstat$ nstat#kernelIpInReceives 5 0.0IpOutRequests 5 0.0IcmpInMsgs 5 0.0IcmpInEchoReps 5 0.0IcmpOutMsgs 5 0.0IcmpOutEchos 5 0.0IpExtInOctets 420 0.0IpExtOutOctets 420 0.0nstat -niperf3 -c 192.168.78.20 -t 2 >/dev/nullnstat "Tcp*"nstat -az "Udp*" | head -8nstat -a -j -p "IcmpOut*"$ nstat "Tcp*"#kernelTcpActiveOpens 2 0.0TcpInSegs 14679 0.0TcpOutSegs 755664 0.0TcpRetransSegs 3050 0.0TcpExtTCPFastRetrans 3050 0.0TcpExtTCPLossProbes 6 0.0$ nstat -az "Udp*" | head -8#kernelUdpInDatagrams 8 0.0UdpNoPorts 0 0.0UdpInErrors 0 0.0UdpOutDatagrams 8 0.0UdpRcvbufErrors 0 0.0$ nstat -a -j -p "IcmpOut*"{ "kernel": { "IcmpOutMsgs": 5, "IcmpOutEchos": 5 }}- The "Tcp*" pattern shows only TCP counters; TcpRetransSegs ~3050 during iperf3 = loss or congestion.
- -a shows absolute values, -z includes zero counters, -j -p gives pretty JSON.
nstat delta since last runnstat 'Tcp*' 'Udp*' pattern (? and *)-h -? --help help-V --version version-z --zeros zero counters too-r --reset reset history-n --nooutput only save history-a --ignore absolute values-s --noupdate don't update history-j --json JSON output-j -p --pretty pretty JSON-d 10 --scan daemon, every 10 s-t 30 --interval rate average (60 s)rtacct route realm countersrtacct -a 10 20 only realms 10 and 20- -r resets the history; -s does not update it; -d is daemon mode; -t sets the rate averaging interval.
- rtacct shows route realm counters; the lab has no realm, so only the header came.
58.4 lnstat
lnstat -dfor i in 1 2 3 4 5 6 7 8; do nc -z -w1 192.168.78.20 8080; sleep 0.4done >/dev/null 2>&1 &lnstat -f nf_conntrack \ -k entries,found,insert,invalid \ -i 1 -c 5$ lnstat -d/proc/net/stat/nf_conntrack: 1: entries 2: clashres 3: found ... 17: search_restart/proc/net/stat/rt_cache: 1: entries 2: in_hit ... 17: out_hlist_search$ lnstat -f nf_conntrack -k entries,found,insert,invalid -i 1 -c 5nf_connt|nf_connt|nf_connt|nf_connt| entries| found| insert| invalid| 4| 0| 0| 0| 7| 0| 0| 0| 9| 0| 0| 0| 12| 0| 0| 0| 12| 0| 0| 0|- -d lists which /proc/net/stat files exist (here only nf_conntrack and rt_cache) and their keys.
- -f file, -k keys, -i interval, -c count.
- entries rose from 4 to 12 with 8 background connections; found and insert stay 0 because new kernels no longer update them.
lnstat -s 0 -f nf_conntrack \ -k entries,insert -w 8,8 -c 2 -i 1lnstat -j -f nf_conntrack \ -k entries,insert -c 1lnstat -f rt_cache \ -k entries,in_hit,in_slow_tot,\in_no_route,out_slow_tot -c 2 -i 1$ lnstat -s 0 -f nf_conntrack -k entries,insert -w 8,8 -c 2 -i 1 12| 0| 12| 0|$ lnstat -j -f nf_conntrack -k entries,insert -c 1{"entries":11,"insert":0}$ lnstat -f rt_cache -k entries,in_hit,in_slow_tot,in_no_route,out_slow_tot -c 2 -i 1rt_cache|rt_cache|rt_cache|rt_cache|rt_cache| entries| in_hit|in_slow_|in_no_ro|out_slow| | | tot| ute| _tot| 125| 0| 3273579| 3266095| 7430| 125| 0| 0| 0| 0|- -s 0 prints no header, -w sets column width, -j gives JSON for scripts.
- For rt_cache the first line is the total and the second the difference over one second.
lnstat all files, every interval-h --help options summary-V --version version (6.9.0)-c 10 --count 10 lines (-1 = forever)-d --dump list files and keys-f nf_conntrack -f rt_cache file(s)-i 10 --interval 10 s interval-j --json JSON output-k arp_cache:entries,rt_cache:in_hit file:key, only these keys-s 0 never print a header-s 1 header only at start-s 2 every 20 lines (default)-w 10,8 --width column width58.5 lnstat files and keys
ls /proc/net/statlnstat -f arp_cache -c 1ip -s ntable show name arp_cache \ | grep -A4 statsping -c 3 -W 1 192.168.78.99 | tail -2ip -s ntable show name arp_cache \ | grep -A4 stats$ ls /proc/net/statnf_conntrackrt_cache$ lnstat -f arp_cache -c 1 [exit 1]$ ip -s ntable show name arp_cache | grep -A4 stats stats allocs 1867 destroys 1848 hash_grows 4 res_failed 113 lookups 8741142 hits 842050 rcv_probes_mcast 0 rcv_probes_ucast 0 periodic_gc_runs 12209 forced_gc_runs 0 table_fulls 0$ ping -c 3 -W 1 192.168.78.99 | tail -23 packets transmitted, 0 received, 100% packet loss, time 2055ms$ ip -s ntable show name arp_cache | grep -A4 stats stats allocs 1868 destroys 1848 hash_grows 4 res_failed 114 lookups 8741157 hits 842056 periodic_gc_runs 12210 forced_gc_runs 0 table_fulls 0- No arp_cache file here: it exists only in the host's main namespace, which Docker Desktop cannot reach.
- ip -s ntable gives the same counters; a ping to the non-existent 192.168.78.99 raised res_failed from 113 to 114.
arp_cache (IPv4) | ndisc_cache (IPv6)entries allocs destroys hash_growslookups hits res_failedperiodic_gc_runs forced_gc_runsunresolved_discards table_fullsrcv_probes_mcast/_ucast IPv6 NS only-- nf_conntrack (ip_conntrack = old name) --entries connections right nowsearched found lookups, successfulnew insert insert_failed addedinvalid icmp_error could not be trackedignore already tracked packetsdelete delete_list removeddrop early_drop table full = dropexpect_new/_create/_delete search_restart- drop and early_drop are the key conntrack counters: rising = table full, new connections are being dropped.
entries routing cache entriesin_slow_tot out_slow_tot entries addedin_slow_mc out_slow_mc multicastin_no_route no route foundin_brd broadcast inputin_martian_dst in_martian_src martian-- deprecated: always 0 --in_hit out_hitgc_total gc_ignored gc_goal_missgc_dst_overflowin_hlist_search out_hlist_search- in_no_route counts packets with no route; martian = impossible source/destination addresses.
- The route cache is gone from the kernel, so the deprecated keys always stay 0.
58.6 ifstat: interface rates
iperf3 -c 192.168.78.20 -t 25 -b 20M &ifstat -i eth0 1 3ifstat -t -b -i eth0 1 2ifstat -l -T 1 2$ ifstat -i eth0 1 3 eth0 KB/s in KB/s out 1.52 2432.26 1.35 2432.25 1.68 2434.84$ ifstat -t -b -i eth0 1 2 Time eth0HH:MM:SS Kbps in Kbps out19:15:54 12.33 19407.7419:15:55 12.35 19446.52$ ifstat -l -T 1 2 lo eth0 Total KB/s in KB/s out KB/s in KB/s out KB/s in KB/s out 0.00 0.00 1.42 2432.32 1.42 2432.32 0.00 0.00 1.42 2561.16 1.42 2561.16- A 20 Mbit/s iperf3 stream shows ~2432 KB/s out on eth0 (19400 Kbps with -b).
- -t adds a timestamp, -l loopback, -T a total column.
ifstat up non-loopback, KB/s-l loopback too -a all interfaces-z hide interfaces with null counters-i eth0,eth1 only these interfaces-s public@192.168.1.1 SNMP shortcut-h help -v version + drivers-n header repeat off -q quiet-t timestamp -T total column-A index cache off (snmp/ifmib)-w fixed width -W wrap (implies -w)-S update on the same line-b kbits/s instead of KB/s5 delay 5 s (min 0.1)0.5/10 first delay / the rest1 10 delay 1, count 10-d proc Linux /proc/net/dev-d snmp:192.168.1.1 SNMP poll (remote switch)ifstat -v: Compiled-in drivers: proc, snmp- Default delay is 1 s; without a count ifstat keeps running.
- iproute2 also ships a different tool named ifstat with completely different options.
58.7 rtmon: log route changes
- Step 1
1.rtmon -4 file /tmp/rt.log address route & listens on netlink
- Step 2
2.ip addr add 192.168.78.50/24: address change logged
- Step 3
3.ip route del default: pings stop leaving the PC; Deleted default logged
- Step 4
4.ip route add default via 192.168.78.1: pings reach the internet again; logged
- Step 5
5.ip monitor file /tmp/rt.log replays every change with a timestamp
rtmon -4 file /tmp/rt.log address route &ip addr add 192.168.78.50/24 dev eth0ip route del defaultip route add default via 192.168.78.1pkill rtmonip monitor file /tmp/rt.log$ ip monitor file /tmp/rt.logTimestamp: Sun Nov 8 19:16:27 2026 151746 us1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default...Timestamp: Sun Nov 8 19:16:28 2026 153422 us9: eth0 inet 192.168.78.50/24 scope global secondary eth0Timestamp: Sun Nov 8 19:16:28 2026 162560 usDeleted default via 192.168.78.1 dev eth0Timestamp: Sun Nov 8 19:16:28 2026 661036 usdefault via 192.168.78.1 dev eth0rtmon file FILE log all + snapshotrtmon file FILE all all objects... link device changes... address IP address changes... route routing table changes-family inet | -4 IPv4 only-family inet6 | -6 IPv6 only-family link | -0 link layer only-family help family usage-Version version (6.9.0)help usageip monitor file FILE replay the log-- routel ---f inet | -4 IPv4 routes--family inet6 | -6 IPv6 routes58.8 routel: routes as a table
routelroutel -4 mainroutel localroutel main dev eth0routel -h$ routelDst Gateway Prefsrc Protocol Scope Dev Tabledefault 192.168.78.1 eth0192.168.78.0/24 192.168.78.10 kernel link eth0127.0.0.0/8 127.0.0.1 kernel host lo local127.255.255.255 127.0.0.1 kernel link lo local192.168.78.10 192.168.78.10 kernel host eth0 local192.168.78.50 192.168.78.10 kernel host eth0 local$ routel -4 mainDst Gateway Prefsrc Protocol Scope Dev Tabledefault 192.168.78.1 eth0192.168.78.0/24 192.168.78.10 kernel link eth0$ routel main dev eth0Dst Gateway Prefsrc Protocol Scope Dev Tabledefault 192.168.78.1192.168.78.0/24 192.168.78.10 kernel link$ routel -hUsage: /sbin/routel [tablenr [raw ip args...]]- Plain routel shows both the main and local tables; routel -4 main only IPv4 main.
- Selectors like dev eth0 can follow the table name.
58.9 rdma
rdma -Vrdma dev showrdma link showrdma -j -p sys showls /sys/class/infiniband$ rdma -Vrdma utility, iproute2-7.3.0$ rdma dev showFailed to open NETLINK_RDMA socket$ rdma link showFailed to open NETLINK_RDMA socket$ rdma -j -p sys showFailed to open NETLINK_RDMA socket$ ls /sys/class/infinibandls: /sys/class/infiniband: No such file or directory- RDMA cards (InfiniBand, RoCE, iWARP) bypass the CPU and move data memory to memory.
- The WSL2 kernel has no RDMA support, so only -V works; on a server with RDMA these commands list devices and ports.
-V -Version version-b cmds.txt -batch commands from a file-force -batch cmds.txt don't stop on error-d dev show details-d -d resource show + driver details-r resource show qp raw format-j dev show JSON-j -p link show pretty JSON-- objects --dev show | help RDMA deviceslink show | help ports and stateresource show | help resource usagesystem (sys) show | help subsystemstatistic (stat, s) show | helprdma dev no command = default show58.10 Common mistakes
- Thinking nstat shows totals: by default it is the delta since the previous run, so two back-to-back runs give an almost empty second run.
- Use nstat -a for totals and nstat -r to reset the history for a fresh start.
- Mixing up the classic ifstat (KB/s) with iproute2's ifstat (different options).
- Trusting lnstat found/insert counters on a new kernel: they stay 0.
58.11 Interview tips
- Check TCP retransmissions: nstat -n, wait, then nstat 'Tcp*'; rising TcpRetransSegs = loss or congestion.
- UdpRcvbufErrors rising = the app is not reading its socket buffer in time.
- New connections failing on a firewall/NAT box: lnstat -f nf_conntrack -k entries,early_drop; rising early_drop = conntrack table full.
- Interface rate: ifstat; route flaps: rtmon + ip monitor file.