Netstat commands on Linux

To see the number of concurrent DNS requests at a time through the Smoothwall:

netstat -anp | grep dnsmasq | wc -l

To see the number of sessions open through the external connection:

netstat -an | wc -l

To see the process ID ofthe windows process using netstat:

netstat -a -n -o

Duplex and Speed on Linux

To check duplex and speed on the Smoothwall:

#ethtool ethA (always recommended to set the auto-negotiate on the switch side for the interface where Smoothwall is connected)

(for example to change the MTU size on the fly for testing purposes) (Shows the network speed and information about the interface)

To change the speed, duplex and the auto-negotiate for an interface:

#ethtool -s ethX speed 100 duplex full autoneg off (to turn off the auto negotiate)


#vi /etc/actions/secondboot/9999custom

(insert the following in the file)

#! /bin/sh

/usr/sbin/ethtool -s ethC duplex full speed 100 autoneg off

(now press escape :wq! )

#chmod +x /etc/actions/secondboot/9999custom


(Finally, you need to reboot to exectute the startup script created, if required)

Speed test (speedtest) / slow speed issue

Install iperf client on windows from:


Ubuntu using:

sudo apt-get install iperf

Try the following from the client machines inside the network and/or from the Smoothwall:

(using speedtest sites through the Smoothwall are not recommended)

iperf -c

iperf -c

iperf -c

iperf -c

iperf -c

iperf -c

iperf -c

(More servers can be found here:

To see live traffic on an interface especially external interface (updates every second)

watch -n 1 /sbin/ifconfig ethC

To check the latest NIC drivers in the database for the Smoothwall’s linux kernel

#lspci -nnn (to check the ethernet controllers and the hardware detected by smoothwall)(To check the company ID and the unique hardware ID i.e. PCI-ID) (to check the ethernet controllers and the hardware detected by smoothwall)

or # lspci -nn | grep Eth

#cat /lib/modules/3.13.0-1-smp/modules.pcimap | grep 1533 | grep 8086

(you can put the kernel you are looking the drivers in instead of 3.13.0-1-smp and the current kernel can be checked using #uname -r)

CPU usage Linux scripts and commands

Script to run top command after every 5 minutes CPU utilization:


top -b -n 1 | head -17 >> /var/log/logging.txt

echo “=========” >> /var/log/logging.txt

To show CPU and process information (press q to quit):

#top (resource usage and running processes)

(uptime and the load average)

(CPU usage: us for users, sy for system and ni for nice processes)(id is idle time, wa is wait state)

(if the wa is high that means the smoothwall is busy with extensive logs or reports)

(press ‘F’ to set the fields and ‘d’ to set it)

#htop (resource usage and running processes)(same as top but better layout)

Swap usage Linux scripts and commands

Swap usage Linux scripts and commands

To see SWAP usage by processes script:


# Get current swap usage for all running processes

# Erik Ljungstrom 27/05/2011



for DIR in `find /proc/ -maxdepth 1 -type d | egrep “^/proc/[0-9]”` ; do

PID=`echo $DIR | cut -d / -f 3`

PROGNAME=`ps -p $PID -o comm –no-headers`

for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk ‘{ print $2 }’`




echo “PID=$PID – Swap used: $SUM – ($PROGNAME )”




echo “Overall swap used: $OVERALL”

./ | egrep -v “Swap used: 0” |sort -n -k 5

To see free memory and swap space:

free -hm

Top command to calculate swap usage:



Linux scripts and commands to see RAM/memory utilization

Script to run top command after every 5 minutes RAM utilization:

top -b -n 1 -o %MEM  | head -17 >> /var/log/logging.txt
echo “=========” >> /var/log/logging.txt

Change the permissions to execute,
chmod 777 script1

move the script to cronfrequently to run it after every 5 mins,
mv script1 /etc/actions/cronfrequently/

(use cronhourlybyfour directory for 15 mins execution)

To see the RAM usage by processes:

ps -eo size,pid,user,command | awk ‘{ hr=$1/1024 ; printf(“%13.6f Mb “,hr) } { for ( x=4 ; x<=NF ; x++ ) { printf(“%s “,$x) } print “” }’ | sort

top -b -n 1 -o %MEM  | head -17

To see RAM stats:


To see free memory and cached space:

free -hm

To see a specific process CPU or RAM utilization using top::

top -p `pgrep PROCESS_NAME | tr “\\n” “,” | sed ‘s/,$//’`

Script to see what processes are using  max RAM every 5 minutes:




File=RamUsage$(date +%d-%m-%y)

mkdir -p $OutDir

echo “——————————–$(date +%d-%m-%y)—–$(date +%H:%M:%S)—————————————“>> $OutDir/$File

ps -eo size,pid,user,command | awk ‘{ hr=$1/1024 ; printf(“%13.6f Mb “,hr) } { for ( x=4 ; x<=NF ; x++ ) { printf(“%s “,$x) } print “” }’ | sort | tail -n20>> $OutDir/$File

ln -s 9999monitorram /etc/actions/cronfrequently/

5 Commands to Get Public IP using Linux Terminal

Public IP are used for communication between computers over internet. A computer running with public ip is accessible all over world using internet. So we can say that it is the identity of computer on internet. Now the question is how do we know our public ip. For computers having GUI can easily get there ips using web tools like this but how we get ips of computers having terminal access only. Solution is here – use one of the following commands to find public ip of your system using Linux terminal. These are also useful to use in shell script.

Get Public IP using Linux Terminal

Command 1. Using wget

# wget -O - -q ; echo

Command 2: Using curl

# curl; echo

Command 3: Using wget

# wget -O - -q ; echo

Command 4: Using curl

# curl

Command 5: Using curl

# curl

Get Public IP in Shell Script

We can simply use following commands in our shell script get our computers public ip and store them in a variable to use anywhere in shell script.


PUBLIC_IP=`wget -O - -q ; echo`

You could use a DNS request instead of HTTP request to find out your public IP:

C:\> nslookup

It uses dns server to resolve the magical hostname to your ip address.

Unix version:

$ dig +short