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)

OR

#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

#/etc/actions/secondboot/9999custom

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

Advertisement

Speed test (speedtest) / slow speed issue

Install iperf client on windows from:

https://iperf.fr/

or

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.securityinspection.com

iperf -c iperf.saratov.ertelecom.ru

iperf -c st2.nn.ertelecom.ru

iperf -c iperf.ips.versatel.de

iperf -c iperf.testdebit.info

iperf -c iperf.cds.com

iperf -c iperf.lan.kth.se

(More servers can be found here: http://en.wikipedia.org/wiki/Iperf)

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:

#!/bin/sh

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:

#!/bin/sh

# Get current swap usage for all running processes

# Erik Ljungstrom 27/05/2011

SUM=0

OVERALL=0

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 }’`

do

let SUM=$SUM+$SWAP

done

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

let OVERALL=$OVERALL+$SUM

SUM=0

done

echo “Overall swap used: $OVERALL”

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

To see free memory and swap space:

free -hm

Top command to calculate swap usage:

top

(SWAP = VIRT – RES)

Linux scripts and commands to see RAM/memory utilization

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

#!/bin/sh
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:

vmstat

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/,$//’`
(e.g. datastore.pl)

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

/var/log/9999monitorram

#!/bin/sh

OutDir=/var/log/monitoring

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 http://ipecho.net/plain -O - -q ; echo

Command 2: Using curl

# curl ipecho.net/plain; echo

Command 3: Using wget

# wget http://observebox.com/ip -O - -q ; echo

Command 4: Using curl

# curl icanhazip.com

Command 5: Using curl

# curl ifconfig.me

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.

#!/bin/bash

PUBLIC_IP=`wget http://ipecho.net/plain -O - -q ; echo`
echo $PUBLIC_IP

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

C:\> nslookup myip.opendns.com resolver1.opendns.com

It uses resolver1.opendns.com dns server to resolve the magical myip.opendns.com hostname to your ip address.

Unix version:

$ dig +short myip.opendns.com @resolver1.opendns.com