Thursday, September 17, 2015

Commands to monitor network bandwidth on Linux server

This post mentions some linux command line tools that can be used to monitor the network usage. These tools monitor the traffic flowing through network interfaces and measure the speed at which data is currently being transferred. Incoming and outgoing traffic is shown separately.

Some of the commands, show the bandwidth used by individual processes. This makes it easy to detect a process that is overusing network bandwidth.

The tools have different mechanisms of generating the traffic report. Some of the tools like nload read the "/proc/net/dev" file to get traffic stats, whereas some tools use the pcap library to capture all packets and then calculate the total size to estimate the traffic load.

Here is a list of the commands, sorted by their features.

1. Overall bandwidth - nload, bmon, slurm, bwm-ng, cbm, speedometer, netload

2. Overall bandwidth (batch style output) - vnstat, ifstat, dstat, collectl

2. Bandwidth per socket connection - iftop, iptraf, tcptrack, pktstat, netwatch, trafshow

3. Bandwidth per process - nethogs


best is to install them , read man pages and use.

Tuesday, August 11, 2015

No space left on device – running out of Inodes

One of our development servers went down today. Problems started with deployment script that claimed that claimed “No space left on device”, although partition was not nearly full. If you ever run into such trouble – most likely you have too many small or 0-sized files on your disk, and while you have enough disk space, you have exhausted all available Inodes. Below is the solution for this problem.


1. check available disk space to ensure that you still have some

$ df

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/xvda             33030016  10407780  22622236  32% /
tmpfs                   368748         0    368748   0% /lib/init/rw
varrun                  368748        56    368692   1% /var/run
varlock                 368748         0    368748   0% /var/lock
udev                    368748       108    368640   1% /dev
tmpfs                   368748         0    368748   0% /dev/shm
2. check available Inodes

$ df -i

Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/xvda            2080768 2080768       0  100% /
tmpfs                  92187       3   92184    1% /lib/init/rw
varrun                 92187      38   92149    1% /var/run
varlock                92187       4   92183    1% /var/lock
udev                   92187    4404   87783    5% /dev
tmpfs                  92187       1   92186    1% /dev/shm
If you have IUse% at 100 or near, then huge number of small files is the reason for “No space left on device” errors.
3. find those little bastards

$ for i in /*; do echo $i; find $i |wc -l; done
This command will list directories and number of files in them. Once you see a directory with unusually high number of files (or command just hangs over calculation for a long time), repeat the command for that directory to see where exactly the small files are.

$ for i in /home/*; do echo $i; find $i |wc -l; done
4. once you found the suspect – just delete the files

$ sudo rm -rf /home/bad_user/directory_with_lots_of_empty_files
You’re done. Check the results with df -i command again. You should see something like this:

Filesystem            Inodes   IUsed   IFree IUse% Mounted on

/dev/xvda            2080768  284431 1796337   14% /
tmpfs                  92187       3   92184    1% /lib/init/rw
varrun                 92187      38   92149    1% /var/run
varlock                92187       4   92183    1% /var/lock
udev                   92187    4404   87783    5% /dev
tmpfs                  92187       1   92186    1% /dev/shm

CentOS 7 : How to get started with Systemd

As the Systemd now replaces SysVinit, it is time to get familiar with it and learn new commands.
Systemd is quicker because it uses fewer scripts and tries to run more tasks in parallel (Systemd calls them units).
The Systemd configuration is stored in the /etc/systemd directory.


Systemd primary task is to manage the boot process and provides informations about it.
To get the boot process duration, type:

#systemd-analyze

To get the time spent by each task during the boot process, type:
#systemd-analyze blame



Journal analysis
In addition, Systemd handles the system event log, a syslog daemon is not mandatory any more.

To get the content of the Systemd journal, type:
# journalctl


To get all the events related to the crond process in the journal, type:
# journalctl /sbin/crond
Note: You can replace /sbin/crond by `which crond`.


To get all the events since the last boot, type:
# journalctl -b


To get all the events that appeared today in the journal, type:
#journalctl --since=today


To get all the events with a syslog priority of err, type:
# journalctl -p err


To get the 10 last events and wait for any new one (like “tail -f /var/Log/messages”), type:
# journalctl -f



Control groups
Systemd organizes tasks in control groups. For example, all the processes started by an apache webserver will be in the same control group, CGI scripts included.

To get the full hierarchy of control groups, type:
# systemd-cgls

To get the list of control group ordered by CPU, memory and disk I/O load, type:
# systemd-cgtop

To kill all the processes associated with an apache server (CGI scripts included), type:
# systemctl kill httpd


To put resource limits on a service (here 500 CPUShares), type:
# systemctl set-property httpd.service CPUShares=500

Note1: The change is written into the service unit file. Use the –runtime option to avoid this behavior.
Note2: By default, each service owns 1024 CPUShares. Nothing prevents you from giving a value smaller or bigger.

To get the current CPUShares service value, type:
# systemctl show -p CPUShares httpd.service



Service management
Systemd deals with all the aspects of the service management. The systemctl command replaces the chkconfig and the service commands. The old commands are now a link to the systemctl command.

To activate the NTP service at boot, type:

# systemctl enable ntpd
Note1: You should specify ntpd.service but by default the .service suffix will be added.
Note2: If you specify a path, the .mount suffix will be added.
Note3: If you mention a device, the .device suffix will be added.

To deactivate it, start it, stop it, restart it, reload it, type:

# systemctl disable ntpd
# systemctl start ntpd
# systemctl stop ntpd
# systemctl restart ntpd
# systemctl reload ntpd

To know if the NTP service is activated at boot, type:
# systemctl is-enabled ntpd


To know if the NTP service is running, type:
# systemctl is-active ntpd


To get the status of the NTP service, type:
# systemctl status ntpd


If you change a service configuration, you will need to reload it:
# systemctl daemon-reload

To get the list of all the units (services, mount points, devices) with their status and description, type:
# systemctl

To get a more readable list, type:
# systemctl list-unit-files

To get the list of services that failed at boot, type:
# systemctl --failed



To get the status of a process (here httpd) on a remote server (here rhel7.example.com), type:
# systemctl -H arvind@centos7.example.com status httpd.service


Run levels
Systemd also deals with run levels. As everything is represented by files in Systemd, target files replace run levels.

To move to single user mode, type:
# systemctl rescue

To move to the level 3 (equivalent to the previous level 3), type:
# systemctl isolate runlevel3.target
Or:
# systemctl isolate multi-user.target


To move to the graphical level (equivalent to the previous level 5), type:
# systemctl isolate graphical.target


To set the default run level to non-graphical mode, type:
# systemctl set-default multi-user.target


To set the default run level to graphical mode, type:
# systemctl set-default graphical.target

To get the current default run level, type:
# systemctl get-default

To stop a server, type:
# systemctl poweroff


Note: You can still use the poweroff command, a link to the systemctl command has been created (the same thing is true for the halt and reboot commands).

To reboot a server, suspend it or put it into hibernation, type:

# systemctl reboot
# systemctl suspend
# systemctl hibernate

Miscellaneous
To get the server hostnames, type:
# hostnamectl

To assign the rhel7 hostname permanently to the server, type:

# hostnamectl set-hostname rhel7
Note: With this syntax all three hostnames (static, pretty, and transient) take the rhel7 value at the same time. However, it is possible to set the three hostnames separately by using the –pretty, –static, and –transient options.

To get the current locale, virtual console keymap and X11 layout, type:
#localectl


To assign the en_GB.utf8 value to the locale, type:
#localectl set-locale LANG=en_GB.utf8

To assign the en_GB value to the virtual console keymap, type:
#localectl set-keymap en_GB

To assign the en_GB value to the X11 layout, type:
#localectl set-x11-keymap en_GB

To get the current date and time, type:
#timedatectl










Monday, April 20, 2015

How to add new disk to LVM in CentOS7.1

On fresh CentOS/RHEL 7, you need to install System Storage Manager first.
sudo yum install system-storage-manager

First, let's check information about available hard drives and LVM volumes. The following command will show information about existing disk storage devices, storage pools, LVM volumes and storage snapshots. The output is from fresh CentOS 7 installation which uses LVM and XFS file system by default.

sudo ssm list 
ssm list
-------------------------------------------------------------
Device        Free       Used      Total  Pool    Mount point
-------------------------------------------------------------
/dev/sda                       200.00 GB          PARTITIONED
/dev/sda1                        3.91 GB          /boot
/dev/sda2  4.00 MB  196.08 GB  196.09 GB  centos
/dev/sdb                        16.00 GB
/dev/sdc                        30.00 GB
/dev/sdd                        40.00 GB
-------------------------------------------------------------
----------------------------------------------------
Pool    Type  Devices     Free       Used      Total
----------------------------------------------------
centos  lvm   1        4.00 MB  196.08 GB  196.09 GB
----------------------------------------------------
------------------------------------------------------------------------------------
Volume            Pool    Volume size  FS     FS size      Free  Type    Mount point
------------------------------------------------------------------------------------
/dev/centos/swap  centos      3.91 GB                            linear
/dev/centos/usr   centos     40.81 GB  ext4  40.81 GB  36.30 GB  linear  /usr
/dev/centos/root  centos     78.12 GB  ext4  78.12 GB  72.79 GB  linear  /
/dev/centos/home  centos     58.59 GB  ext4  58.59 GB  54.57 GB  linear  /home
/dev/centos/var   centos     14.65 GB  ext4  14.65 GB  13.28 GB  linear  /var
/dev/sda1                     3.91 GB  ext4   3.91 GB   3.47 GB  part    /boot
------------------------------------------------------------------------------------
 

in this example  /dev/sdb,/dev/sdc and
/dev/sdd  i added hard drive in CentOS7.1 VM in VMWare Vsphere

my pool name is centos i will add these three drive to my pool
sudo ssm add -p centos /dev/sdb /dev/sdc /dev/sdd

and now list

 ssm list
--------------------------------------------------------------
Device         Free       Used      Total  Pool    Mount point
--------------------------------------------------------------
/dev/sda                        200.00 GB          PARTITIONED
/dev/sda1                         3.91 GB          /boot
/dev/sda2   4.00 MB  196.08 GB  196.09 GB  centos
/dev/sdb   16.00 GB    0.00 KB   16.00 GB  centos
/dev/sdc   30.00 GB    0.00 KB   30.00 GB  centos
/dev/sdd   40.00 GB    0.00 KB   40.00 GB  centos
--------------------------------------------------------------
-----------------------------------------------------
Pool    Type  Devices      Free       Used      Total
-----------------------------------------------------
centos  lvm   4        85.99 GB  196.08 GB  282.07 GB
-----------------------------------------------------
------------------------------------------------------------------------------------
Volume            Pool    Volume size  FS     FS size      Free  Type    Mount point
------------------------------------------------------------------------------------
/dev/centos/swap  centos      3.91 GB                            linear
/dev/centos/usr   centos     40.81 GB  ext4  40.81 GB  36.30 GB  linear  /usr
/dev/centos/root  centos     78.12 GB  ext4  78.12 GB  72.79 GB  linear  /
/dev/centos/home  centos     58.59 GB  ext4  58.59 GB  54.57 GB  linear  /home
/dev/centos/var   centos     14.65 GB  ext4  14.65 GB  13.28 GB  linear  /var
/dev/sda1                     3.91 GB  ext4   3.91 GB   3.47 GB  part    /boot
------------------------------------------------------------------------------------
 



now we can see these three drives are part of my lVM pool centos

Now , i will increase the size of my var and list again

sudo ssm resize -s+5G /dev/centos/var

ssm list
--------------------------------------------------------------
Device         Free       Used      Total  Pool    Mount point
--------------------------------------------------------------
/dev/sda                        200.00 GB          PARTITIONED
/dev/sda1                         3.91 GB          /boot
/dev/sda2   0.00 KB  196.09 GB  196.09 GB  centos
/dev/sdb   11.00 GB    5.00 GB   16.00 GB  centos
/dev/sdc   30.00 GB    0.00 KB   30.00 GB  centos
/dev/sdd   40.00 GB    0.00 KB   40.00 GB  centos
--------------------------------------------------------------
-----------------------------------------------------
Pool    Type  Devices      Free       Used      Total
-----------------------------------------------------
centos  lvm   4        80.99 GB  201.08 GB  282.07 GB
-----------------------------------------------------
------------------------------------------------------------------------------------
Volume            Pool    Volume size  FS     FS size      Free  Type    Mount point
------------------------------------------------------------------------------------
/dev/centos/swap  centos      3.91 GB                            linear
/dev/centos/usr   centos     40.81 GB  ext4  40.81 GB  36.30 GB  linear  /usr
/dev/centos/root  centos     78.12 GB  ext4  78.12 GB  72.79 GB  linear  /
/dev/centos/home  centos     58.59 GB  ext4  58.59 GB  54.57 GB  linear  /home
/dev/centos/var   centos     19.65 GB  ext4  19.65 GB  18.00 GB  linear  /var
/dev/sda1                     3.91 GB  ext4   3.91 GB   3.47 GB  part    /boot
------------------------------------------------------------------------------------
from this output we can see /dev/sdb showing 5GB used and /dev/centos/var is now 19.65,before adding space to it it was

14.65 GB


for more use , read man page of ssm
ssm (8)              - System Storage Manager: a single tool to manage your storage
 


 


Tuesday, March 17, 2015

FREAK - (Factoring attack on RSA-EXPORT Keys) a SSL security bug

Protective monitoring signatures

NCC Group’s Cyber Defence Operations team has developed the following alpha Suricata detection signature for FREAK:

alert tcp any any <> any any (msg:"SSL EXPORT Ciphers"; flow:established,to_server; ssl_state:client_hello; content:"|00 14 00 11 00 19 00 08 00 06 00 17 00 03 00 ff|"; sid:1; rev:1;)

However, this is alpha as research, development and testing continues. To determine if a Server accepts Export Ciphers, run the following command:
openssl s_client -connect google.com:443 -cipher 'EXPORT'

The Server will respond with a message like the following if it does not support the Cipher suite:
CONNECTED(00000003)
 
3073972424:error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure:s23_clnt.c:724:
 
---
 
no peer certificate available
 
---
 
No client certificate CA names sent
 
---
 
SSL handshake has read 7 bytes and written 75 bytes
 
---
 
New, (NONE), Cipher is (NONE)
 
Secure Renegotiation IS NOT supported
 
Compression: NONE
 
Expansion: NONE





If the Server does support the Cipher suite, you will get a response similar to this:
CONNECTED(00000003)
 
depth=2 C = US, O = "VeriSign, Inc.", OU = VeriSign Trust Network, OU = "(c) 2006 VeriSign, Inc. - For authorized use only", CN = VeriSign Class 3 Public Primary Certification Authority - G5
 
verify error:num=20:unable to get local issuer certificate
 
verify return:0
 
---
 
…SNIP…
 
---
 
No client certificate CA names sent
 
---
 
SSL handshake has read 4778 bytes and written 193 bytes
 
---
 
New, TLSv1/SSLv3, Cipher is EXP-RC4-MD5
 
Server public key is 2048 bit
 
Secure Renegotiation IS supported
 
Compression: NONE
 
Expansion: NONE
 
SSL-Session:
 
    Protocol  : TLSv1
 
    Cipher    : EXP-RC4-MD5
 
    Session-ID: 1234E36E65F99D0F1234344F3F123493391560B0F123423EECF0835123467959
 
    Session-ID-ctx
 
    Master-Key: 057ED9F44171BC3AC2BAD…
 
 …SNIP…







As you can see, the Server responded using TLSv1 Cipher:

EXP-RC4-MD5 (TLS_RSA_EXPORT_WITH_RC4_40_MD5)

Looking at this request in Wireshark, we see our Client only offers the Export Cipher suites: 
So if we are being MITM’d we would have seen our ‘Client Hello’ request (using the Standard Cipher suite) leave our browser, and the Server would have responded but with the Export Cipher suite.
The Suricata signature we created specifically looks for the Export Cipher suite above. The rule is very tight (in regards to what it is looking for), and will fail if one of the Export Ciphers are not included or in they are in a different order (hence why it is an alpha signature).