Some handy commands for checking and diagnosing servers
Shows average load at a glance.
uptime
Print system and kernal messages
# see system error and warning messages
dmesg --level=err,warn
Displays linux process and system stats.
top
# monitor specific processes
top -p{pid},{pid}
# monitor processes for a user
top -u {username}
Similar to top but with a more detailed UI.
htop
Reports processor and io statistics
iostat
# display a report every n seconds
iostat -d {seconds}
# extended report in megabytes
iostat -mx
Shows detailed processor stats
mpstat
# show details for each processor
mpstat - A
# display a report every n seconds
mpstat -A {seconds}
Per process disk read/write
iotop
# monitor processes actively doing IO
iotop -o
# monitor specific processes
top -p{pid},{pid}
# monitor processes for a user
top -u {username}
Network traffic stats for a named interface (defaults to eth0)
# monitor traffic for a specific interface
iftop -i eth0
# disable hostname resolution
iftop -n -i eth0
# show ports
iftop -P -i eth0
System metric collection.
Sysstat must be installed and enabled like so (example is for Ubuntu):
sudo apt-get install sysstat
# activate
vi /etc/defaults/sysstat
# change ENABLED="false" to ENABLED="true"
System metric reporting.
With sysstat installed and enabled (see above) sar can be used to process and display the logs generated by it.
# memory utilization
sar -r
#CPU stats
sar -t
# IO stats
sar -b
# All stats
sar -A
Stats for a process
pidstat {PID}
Note The -n flag will turn off address resolution for many of these commands.
Configure network interfaces, will also display the status of devices.
# display summary of interfaces
ifconfig
# limit to a particular interface
ifconfig eth0
# list all interfaces, including those that are down
ifconfig -a
# bring and interface up or down
ifconfig eth0 up
ifconfig eth0 down
Configure wireless network interfaces, will also display the status of devices. Note that ifconfig can still be used to perform standard configuration on wireless devices, this command covers configuration that applies to wirelss devices such as frequency, mode and channel.
# display summary of interfaces
iwconfig
# limit to a particular interface
iwconfig wlan0
# set frequency
iwconfig wlan0 freq 2.437G
Show and manipulate network routes for local traffic.
# list all static routes
route -n
# add a route via a gateway
route add {Target IP} gw {Gateway}
# delete a routes
route del {Target IP}
Network scanner/discovery tool, can display a range of information from open ports to ssl cert info and more.
# see if port is open
nmap -p 80 {IP or Hostname}
Tool for displaying a wide array of network information.
# List processes listening on ports
sudo netstat -nlp
# Limit to TCP connections
sudo netstat -tnlp
Shows raw fraffic on a network, has many filtering options for narrowing down what raw traffice is displayed.
# show all traffic for an interface
tcpdump -i eth0
# show traffic for a host
tcpdump -n host {host}
# show traffic not involving host
tcpdump -n not {host}
# show traffic for a port
tcpdump -n port {port}
# show traffic for a host and interface,
# use tee to log to a file and display at the same time
tcpdump -n -i {interface} host {host} | tee file
Tool for querying name servers.
# query a domain
nslookup {host}
# query a domain using a specific nameserver
nslookup {host} {nameserver}
More detailed DNS query tool, can be used to show detailed DNS information.
# show DNS information for a host
dig google.com
# show DNS information via a specific name server
dig google.com @216.239.38.10
# show the route for a DNS lookup
dig google.com +trace
# query specific DNS information
dig host {NS|MX|TXT
/etc/rc{0-6}.d Cotains scripts for each runlevel, 6 = reboot, 1 = single user mode. Scripts start with letters to denote when they run, S means run when switching to level, K means run when leaving level, D means disabled.
# switch to runlevel
sudo init 0-6
/etc/rcS.d Scripts to run when switching between runlevel
/etc/init.d Scripts for controlling services
/etc/init Upstart scripts (Ubuntu)
Startup control tool for upstart.
# List status of all upstart jobs
initctl list
Disk partition tool.
# list all disks and partitions
fdisk -l
Show disk space usage.
df
# See iNode usage
df -i
Can be used to show what files are taking disk space.
# show disk usage from current directory
du
# for a specific directory
du /home/terry
# show disk usage of top level directories, sorted by biggest first
du -ck -d 1 | sort -rn
View and adjust tunable file system parameters
# View details of partitions including reserve disk space
sudo tune2fs -l /dev/sda1