Use netstat to show IPv4 versus IPv6 traffic

http://ipv6-or-no-ipv6.blogspot.ca/2013/06/use-netstat-to-show-ipv4-versus-ipv6.html

If you wonder how much IPv6 versus IPv4 traffic your system does, there is an nice estimation: use “netstat -s” to show the amount of inbound packets. Packets is not the same as bytes, but assuming the IPv4 packets have the same mean size as IPv6 packets, you’re fine. The exact commands are:

netstat -s | grep “total packets” | awk ‘{ print $1 }’
netstat -s -6 | grep “total packets” | awk ‘{ print $1 }’

which will show the packets for IPv4 resp IPv6

Please note that the first command will only show IPv4 packets, and not the total of IP packets. See the below test for proof

sander@hapee:~$ netstat -s | grep “total packets” | awk ‘{ print $1 }’
32648268
sander@hapee:~$ netstat -s -6 | grep “total packets” | awk ‘{ print $1 }’
177887898
 
sander@hapee:~$ wget -4 http://ftp.belnet.be/ubuntu.com/ubuntu/releases/precise/ubuntu-12.04.2-desktop-i386.iso -O /dev/null
 
sander@hapee:~$ netstat -s | grep “total packets” | awk ‘{ print $1 }’
32688502
sander@hapee:~$ netstat -s -6 | grep “total packets” | awk ‘{ print $1 }’
177887937
 
sander@hapee:~$ wget -6 http://ftp.belnet.be/ubuntu.com/ubuntu/releases/precise/ubuntu-12.04.2-desktop-i386.iso -O /dev/null



sander@hapee:~$ netstat -s | grep “total packets” | awk ‘{ print $1 }’
32688526
sander@hapee:~$ netstat -s -6 | grep “total packets” | awk ‘{ print $1 }’
178028250
sander@hapee:~$


In the above output you’ll see the IPv4-download only rises the first counter (meaning it only measures IPv4), and the IPv6-download only rises the second counter (IPv6 traffic).
I’m writing a tool to put this info into MRTG graphs