This is probably the most used of all the security layers, since turning off unneeded network services gets rid of opportunities for network breakins. To hunt down and turn off unwanted services, the lsof, chkconfig, and service system commands can be used. To display which network services are currently listening on a system, do this:
# lsof -i | grep LISTEN | awk '{print $1,$(NF-2),$(NF-1)}' | sort | uniq
To list the services that will be started by default at the current runlevel do this:
# chkconfig --list | grep `grep :initdefault: /etc/inittab | \ awk -F: '{print $2}'`:on | awk '{print $1}' | sort | column
To find services started by xinetd do this:
# chkconfig --list | awk 'NF==2&&$2==''off''{print}' | \ awk -F: '{print $1}' | sort | column
The nmap port scanning command is also useful to get a hackers-eye view of your systems. The chkconfig and service commands can be used to turn on and off system services.