How to check the number of active connections on the Linux server

With the help of the commands below, you can check active connections on Linux server on different ports:-

   netstat -ntu | grep ':143' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort
   netstat -ntu | grep ':110' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort
   netstat -ntu | grep ':25' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort
   netstat -ntu | grep ':80' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort

Manoj | Wednesday 28 May 2014 - 08:29 am | | Default | No comments

A powerful Linux firewall: iptables

Linux has an extremely powerful built-in firewall, referred to as iptables. It works on IP addresses, protocols (tcp, udp, icmp) and ports. Iptables places rules into predefined chains (INPUT, OUTPUT and FORWARD) which are checked against the netowrk traffic and then as per the rule the traffic is accepted/blocked to/from the system.

1) You can list the iptables rules on the command prompt using the command below:-

iptables -nL

2) In case you would like to flush/remove the inbuilt iptable rules:-

iptbales -F

After this, save the iptables rules to their file as below:-

/etc/init.d/iptables save

3) Writing a basic rule to iptables for the INPUT chain in order to block SSH on port 22:

iptables -A INPUT -p tcp --dport 22 -j ACCEPT

Similarily for the SMTP port 25:-

iptables -A INPUT -p tcp --dport 25 -j ACCEPT

After this, remember to save the rules as below:-

/etc/init.d/iptables save

If we don't save the changes, then after restarting iptables or the system the rules will be gone.

That's all.

Sachin | Saturday 24 May 2014 - 7:03 pm | | Default | No comments

Installing the mcrypt extension to PHP on Plesk 11.x

We have found that many users need the PHP mcrypt extension for the payment gateway or security reasons, however this doesn't come by default on Plesk or on the Linux server (CentOS to be specific).

Installing the mcrypt extension on PHP is a bit risky as it doesn't come with the CentOS server base repository and we need to install it with a third party repository such as EPEL.

Step 1: So you need to first check the PHP version installed on the server.

php -V

PHP 5.3.3 (cli) (built: Dec 11 2013 03:29:57)

or

rpm -qa | grep php

php-5.3.3-27.el6_5.x86_64

So, here we know that the server has the PHP 5.3.3 version installed and we must install the exact version of php-mcrypt otherwise an upgrade will happen to the running PHP version which will conflict things and may crash the running Plesk.

Step 2: Now, either first install the EPEL repository or directly download the RPM of php-mcrypt-5.3.3-x on the server and install it. So, here I have the direct link which I can share with you. So follow the steps below:-

cd /usr/local/src/
wget http://epel.mirror.net.in/epel/6/x86_64/php-mcrypt-5.3.3-3.el6.x86_64.rpm
yum localinstall php-mcrypt-5.3.3-3.el6.x86_64.rpm

Step 3: Then just restart the httpd service using the link below:-

/etc/init.d/httpd restart

and that's it. Check the php-mcrypt extension status using the phpinfo file on the server.

Have fun :).

Sachin | Friday 16 May 2014 - 2:10 pm | | Default | No comments

Allowing direct root login using SSH on Ubuntu

By default, both root login and the root account are usually locked on the server due to security concerns. However, sometimes it may be necessary to have the root user account enabled and the ablility to directly login onto the server. For that, follow the steps below:-

Step 1: By default, the root account password is locked in Ubuntu. So unlock it first:-

sudo -i

sudo passwd root

Step 2: Change the SSH config details as follows:-

PermitRootLogin no
PermitRootLogin yes

Step 3: Specify Which Accounts Can Use SSH

Find out if the sshd_config file has an entry as below and if there is such an entry then remove the root user from below

DenyUsers root user1 user2

Or

If there is no DenyUsers entry then place in it an entry like below:-

AllowUsers root

Save the file and restart SSH service using the command below:-

/etc/init.d/ssh restart

That's it. After this, you will be able to login directly using root credentials.

Sachin | Wednesday 14 May 2014 - 6:08 pm | | Default | No comments

Previewing a website before a DNS update in Plesk

If you want to view your website before changing the DNS of the domain in the Plesk control panel, then below are the steps to follow:- 

Step 1: Upload the files using FTP for a new account in the domain.
Step 2: Log into the Plesk control panel and click on the "Website & Domains" option.
Step 3: At the bottom of the page you can see your domain name and on the very right side in the same domain row there are some icons, in which the first option is for "Preview the website in your browser" which you can see once you just move the mouse on it.
Step 4: Click on that icon and it'll open a new window in which you'll be able to see your site preview.

That's it.

Sachin | Wednesday 14 May 2014 - 10:31 am | | Default | No comments