Check Raid Controller on Linux and Monitor RAID

How to check the raid controller on Linux:

# lspci | grep -i raid
01:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2208 [Thunderbolt] (rev 05)

Monitoring Tools

You should get to know /proc/mdstat, looking at it often. This will tell you the state of your arrays, and very importantly it will tell you whether any drives have failed, and whether any arrays are degraded. Check, and check regularly!

xosview is a venerable utility, and one of the author’s favourites. It is capable of displaying the state of raid arrays, but unfortunately currently the code is broken – it reads mdstat, and doesn’t understand the current output. It is currently (2016) being updated to read the status directly from /sys, and should hopefully soon be able to display raid status correctly. The author leaves xosview running permanently on his desktop to provide an overview of system performance.

mdadm –monitor –scan –mail
This will fire up mdadm to keep an eye on your arrays. It will daemonize and run in the background, sending an email to the specified address if it detects any problems related to a disk failure. This is good for remote monitoring BUT. It won’t tell you if anything goes wrong with the monitoring! You cannot assume – even if you put this in your boot-up sequence as you should – that you will be notified about important events. It’s not unknown for the daemon to fail.

Don’t rely on this! Check regularly on a manual basis!

This tool tells you all sorts of information about your drives. When you read the “When things go wrogn” section, you will see that smartctl is a very important diagnostic tool, but it also provides a lot of proactive information to help you anticipate a drive failure.

There are various S.M.A.R.T. stats that can be looked at which will provide clues:

Attribute | Description |
SMART 5 | Reallocated Sectors Count |
SMART 187 | Reported Uncorrectable Errors |
SMART 188 | Command Timeout |
SMART 197 | Current Pending Sector Timeout |
SMART 198 | Uncorrectable Sector Count | (who run huge raid arrays) have a lot of interesting information on their site. They point out that maybe a quarter of their drives fail when all these statistics are 0, so a healthy SMART report does not necessarily mean a healthy drive, but almost none of their drives survive having errors on all five counts.

smartctl also reports on things like drive temperature, how long the drive has been powered on, how many times it has been started and shut down etc. It’s no surprise that drives that get too hot or are otherwise stressed beyond normal limits tend to fail early.

Smartmontools for RAID

Check Mail Port Connections with netstat

A good way to check the connectons to mail ports is to use netstat:

# netstat -anp | grep :25
tcp        0      0    *               LISTEN      2170/master
tcp6       0      0 :::25                   :::*                    LISTEN      2170/master
# netstat -anp | grep :465
tcp        0      0   *               LISTEN      2170/master
tcp6       0      0 :::465                  :::*                    LISTEN      2170/master
# netstat -anp | grep :587
tcp        0      0   *               LISTEN      2170/master
tcp6       0      0 :::587                  :::*                    LISTEN      2170/master

Let’s Encrypt for Windows Server 2012 R2

I recently added MailEnable to a Windows server and wanted to add SSL. I checked and there is an application that you can use to add the Let’s Encrypt SSL.

Quick Start
Download from and install it.
Click ‘New Certificate’, choose your IIS site (which must have 1 or more hostname bindings set). Save your settings and click ‘Request Certificate’
All done!

How to Whitelist or Block IPs in your Firewall on Linux – iptables, firewalld, ufw

Knowing how to Whitelist and Blacklist IPs in your firewall can be very important when you want to allow or deny connection to your server, based on an IP address. Below we will cover how to allow and deny connections from IPs in IP Tables, Firewalld, and UFW.

Allowing or Denying connections from IPs in IP Tables is quite simple. To accept the connection, or whitelist the IP, you would use the following command (where is the IP you want to allow through the Firewall):

# sudo iptables -A INPUT -s -j ACCEPT

Denying the IP is very similar, just changing ACCEPT to DROP:

# sudo iptables -A INPUT -s -j DROP

You can also change DROP or REJECT if you want your server to respond back to the request with a Rejection instead of just dropping the traffic all together.

To whitelist IPs on Firewall-CMD, we’ll want to use the –add-source flag. We can whitelist an IP or an IP Subnets via the following commands:

# firewall-cmd --permanent --zone=public --add-source=


# firewall-cmd --permanent --zone=public --add-source=

Blocking an IP is a bit difficult, as it requires a more complex command. The command that you would want to use to block traffic from an IP would be:

# firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address= reject"


# firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address= reject"

We can also view all of the whitelisted IPs in our zone via:

# firewall-cmd --permanent --zone=public --list-sources

Allowing and blocking IPs in UFW is very simple and straight forward. We can allow connections from a specific IP via the following command:

# sudo ufw allow from

Blocking and IP is just as simple, with the following command:

# sudo ufw deny from

How To Set Up a Firewall with UFW on Ubuntu 14.04

UFW is installed by default on Ubuntu. If it has been uninstalled for some reason, yYou can install it with apt-get:

# sudo apt-get install ufw

Check the Status

# sudo ufw status verbose

By default, UFW is disabled so you should see something like this:


# Status: inactive

If UFW is active, the output will say that it’s active, and it will list any rules that are set. For example, if the firewall is set to allow SSH (port 22) connections from anywhere, the output might look something like this:


Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW IN    Anywhere

Let’s set your UFW rules back to the defaults so we can be sure that you’ll be able to follow along with this tutorial. To set the defaults used by UFW, use these commands:

# sudo ufw default deny incoming
# sudo ufw default allow outgoing

As you might have guessed, these commands set the defaults to deny incoming and allow outgoing connections. These firewall defaults, by themselves, might suffice for a personal computer but servers typically need to respond to incoming requests from outside users. We’ll look into that next.

Allow SSH Connections

To configure your server to allow incoming SSH connections, you can use this UFW command:

# sudo ufw allow ssh

this command works the same as the one above:

# sudo ufw allow 22
# sudo ufw allow 2222

Now that your firewall is configured to allow incoming SSH connections, we can enable it

# sudo ufw enable

HTTP—port 80
HTTP connections, which is what unencrypted web servers use, can be allowed with this command:

# sudo ufw allow http

If you’d rather use the port number, 80, use this command:

# sudo ufw allow 80

HTTPS—port 443
HTTPS connections, which is what encrypted web servers use, can be allowed with this command:

# sudo ufw allow https

If you’d rather use the port number, 443, use this command:

# sudo ufw allow 443

FTP—port 21
FTP connections, which is used for unencrypted file transfers (which you probably shouldn’t use anyway), can be allowed with this command:

# sudo ufw allow ftp

If you’d rather use the port number, 21, use this command:

# sudo ufw allow 21/tcp

Allow Specific Port Ranges
You can specify port ranges with UFW. Some applications use multiple ports, instead of a single port.

For example, to allow X11 connections, which use ports 6000-6007, use these commands:

# sudo ufw allow 6000:6007/tcp
# sudo ufw allow 6000:6007/udp

When specifying port ranges with UFW, you must specify the protocol (tcp or udp) that the rules should apply to. We haven’t mentioned this before because not specifying the protocol simply allows both protocols, which is OK in most cases.

Allow Specific IP Addresses
When working with UFW, you can also specify IP addresses. For example, if you want to allow connections from a specific IP address, such as a work or home IP address of, you need to specify “from” then the IP address:

# sudo ufw allow from

You can also specify a specific port that the IP address is allowed to connect to by adding “to any port” followed by the port number. For example, If you want to allow to connect to port 22 (SSH), use this command:

# sudo ufw allow from to any port 22

Allow Subnets
If you want to allow a subnet of IP addresses, you can do so using CIDR notation to specify a netmask. For example, if you want to allow all of the IP addresses ranging from to you could use this command:

# sudo ufw allow from

Likewise, you may also specify the destination port that the subnet is allowed to connect to. Again, we’ll use port 22 (SSH) as an example:

# sudo ufw allow from to any port 22

Allow Connections to a Specific Network Interface
If you want to create a firewall rule that only applies to a specific network interface, you can do so by specifying “allow in on” followed by the name of the network interface.

You may want to look up your network interfaces before continuing. To do so, use this command:

ip addr
Output Excerpt:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default 

The highlighted output indicates the network interface names. They are typically named something like “eth0” or “eth1”. So, if your server has a public network interface called eth0, you could allow HTTP traffic (port 80) to it with this command:

# sudo ufw allow in on eth0 to any port 80

Doing so would allow your server to receive HTTP requests from the public Internet.

Or, if you want your MySQL database server (port 3306) to listen for connections on the private network interface eth1, for example, you could use this command:

# sudo ufw allow in on eth1 to any port 3306

This would allow other servers on your private network to connect to your MySQL database.

Deny Connections
If you haven’t changed the default policy for incoming connections, UFW is configured to deny all incoming connections. Generally, this simplifies the process of creating a secure firewall policy by requiring you to create rules that explicitly allow specific ports and IP addresses through.

To write deny rules, you can use the commands that we described above except you need to replace “allow” with “deny”.

For example to deny HTTP connections, you could use this command:

# sudo ufw deny http

Or if you want to deny all connections from you could use this command:

# sudo ufw deny from

If you need help writing any other deny rules, just look at the previous allow rules and update them accordingly.

Now let’s take a look at how to delete rules.

Delete Rules
Knowing how to delete firewall rules is just as important as knowing how to create them. There are two different ways specify which rules to delete: by rule number or by the actual rule (similar to how the rules were specified when they were created). We’ll start with the delete by rule number method because it is easier, compared to writing the actual rules to delete, if you’re new to UFW.

By Rule Number
If you’re using the rule number to delete firewall rules, the first thing you’ll want to do is get a list of your firewall rules. The UFW status command has an option to display numbers next to each rule, as demonstrated here:

# sudo ufw status numbered
Numbered Output:
Status: active

     To                         Action      From
     --                         ------      ----
[ 1] 22                         ALLOW IN
[ 2] 80                         ALLOW IN    Anywhere

If we decide that we want to delete rule 2, the one that allows port 80 (HTTP) connections, we can specify it in a UFW delete command like this:

# sudo ufw delete 2

This would show a confirmation prompt then delete rule 2, which allows HTTP connections. Note that if you have IPv6 enabled, you would want to delete the corresponding IPv6 rule as well.

By Actual Rule
The alternative to rule numbers is to specify the actual rule to delete. For example, if you want to remove the “allow http” rule, you could write it like this:

# sudo ufw delete allow http

You could also specify the rule by “allow 80”, instead of by service name:

# sudo ufw delete allow 80

This method will delete both IPv4 and IPv6 rules, if they exist.

How To Disable UFW (optional)
If you decide you don’t want to use UFW for whatever reason, you can disable it with this command:

# sudo ufw disable

Any rules that you created with UFW will no longer be active. You can always run sudo ufw enable if you need to activate it later.

Reset UFW Rules (optional)
If you already have UFW rules configured but you decide that you want to start over, you can use the reset command:

# sudo ufw reset

This will disable UFW and delete any rules that were previously defined. Keep in mind that the default policies won’t change to their original settings, if you modified them at any point. This should give you a fresh start with UFW.

Connect to Azure Database with Mysql with mysql command line

Azure Mysql database in encrypted by default. The mysql connection fails when trying to login:

ERROR 9002 (28000): SSL connection is required. Please specify SSL options and retry.

Azure Database for MySQL supports connecting your Azure Database for MySQL server to client applications using Secure Sockets Layer (SSL). Enforcing SSL connections between your database server and your client applications helps protect against “man in the middle” attacks by encrypting the data stream between the server and your application.

Here is how to set up the connection to use SSL.

Download the certificate needed to communicate over SSL with your Azure Database for MySQL server from and save the certificate file to your local drive.

Connecting to server using the MySQL CLI over SSL

# mysql -h -u Username@mydemoserver -p --ssl-ca=BaltimoreCyberTrustRoot.crt.pem

Using SED in Linux to Edit Large Files

Recently I encountered a server that had an Apache configuration file that was over 500,000 lines. Changes needed to make were to comment out the CustomLog line for each domain in /etc/httpd/httpd.conf. For this command, I used SED.

sed – stream editor for filtering and transforming text

sed [OPTION]… {script-only-if-no-other-script} [input-file]…


Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sed’s ability to filter text in a pipeline which particularly distinguishes it from other types of editors.

Change directory to the log file location. Use below to see what the command will do before doing it.

# sed -n 's|CustomLog|#CustomLog|gp' /etc/apache2/conf/httpd.conf

Use this to alter the file directly.

# sed -i 's|CustomLog|#CustomLog|g' /etc/apache2/conf/httpd.conf

Linux mount CIFS Windows Share

CIFS stands for Common Internet File System. This is application-level network protocol mainly used to provide shared access to files, printers, serial ports, and miscellaneous communications between nodes. You can access CIFS share from Linux and mount them as a regular filesystem. This is handy if there is a backup service like Infrascale where you set up a windows computer to be backed up. As there is no linux application for infrascale.

The following example values will be used in this example:

IP address for the server:
Share name on Windows Server: C:\backuptemp
User name: testuser
Domain: testdomain
Mount point on Linux Server: /mnt/winmount

The environment is a Windows Domain with Active Directory. There is a file share set up as C:\backuptemp

Make the local mount point on the linux server:

# mkdir mnt/winmount

To mount the network share, use the following command and enter the password of the user:

# mount -t cifs // /mnt/winmount -o user=testuser