Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can I view the source code of netstat on my Linux machine?

share|improve this question
up vote 10 down vote accepted

Yes you can. Download it.

But as you don't say what flavor of linux re you using here is couple of examples:

Debian/Ubuntu related:

# What package is the netstat executable in?
apt-file search /usr/bin/netstat
# Now download the source of that package
apt-get source net-tools

CentOS/Red Hat:

yumdownloader --source net-tools
share|improve this answer
I thought that in Linux are some standard places where I can view source code of various commands without need of downloading. – xralf Sep 27 '11 at 9:23
apt-get ends with this message Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to find a source package for netstat – xralf Sep 27 '11 at 9:24
Then you'll need to enable the src repos. Go to /etc/apt/sources.list and uncomment the deb-src lines. – hmontoliu Sep 27 '11 at 9:28
apt-get with net-tools seems to download it, but where is it saved? – xralf Sep 27 '11 at 9:30
@xralf: you need to explicitly download the source code because most of the distros and users consider it as a waste of space since they trust the build process from the distro. – hmontoliu Sep 27 '11 at 9:30

netstat is part of the net-tools suite. The project home page is here: https://sourceforge.net/projects/net-tools/

You can browse the netstat source here: http://sourceforge.net/p/net-tools/code/ci/master/tree/ or view the netstat.c file.

share|improve this answer

Probably you need this: http://www.tazenda.demon.co.uk/phil/net-tools/. If you need more precise answer - use your local package manager to get info about package containing netstat utility.

share|improve this answer

The answers from jasonwryan and gelraen both point to dead links for the source code. The net-tools project is now hosted at sourceforge per this announcement.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.