By Paul Tero CHAPTER 8
to display all the networking information about your server. Add -tlpn
to the command to make it show only TCP connections that it is listening
for, along with the numeric port and the program they belong to. On some
systems the p option requires super user access, so the commands below
also do a sudo.
$ netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:53 0.0.0.0: LISTEN 4290/named
tcp 0 0 127.0.0.1:5432 0.0.0.0: LISTEN 3507/postmaster
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 7117/mysqld...
This shows only an abbreviated output. It normally shows all the ports
which the server is listening to, and there can be between 10 and 100 of
them. When running any command, you can whittle down its output
using the grep command. grep filters the output and only shows lines
containing a word or phrase you have specified. The vertical bar | makes
a pipe, piping the output of one command (netstat) into the input of
another (grep). Try this instead:
netstat -tlpn | grep :80
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 22885/java
This runs netstat and shows only results containing :80. This server has a
java process listening to port 8005 but no Web server running.
Which Web Server
When a Linux server starts up it looks in the directory /etc/init.d and
runs the scripts there to launch its software. This varies among Linux
distributions, and on other UNIX flavors like BSD this might be /etc/rc.d
or /etc/rc.d/init.d. This is similar to the Startup menu folder in Windows.