Redirect old domain to new domain with 301

Here are the few lines of code you can add into your .htaccess to redirect your old domain to new domain with 301 (permanent redirect) code.

Open .htaccess file in any editor and add following below lines, please replace websterz.info with your own domain.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^websterz.info [NC,OR]
RewriteCond %{HTTP_HOST} ^www.websterz.info [NC]
RewriteRule ^(.*)$ http://websterz.info/$1 [L,R=301,NC]

 

That’s all šŸ™‚

Check active connections to web server – DDOS solution

Here are few commands to check the active connection to apache or to any other web server, you can block IPs having too many connections :

Login to SSH and execute following commands with root access:

1.To see what IPs are connecting to server and how many connections exist from each IP:

netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

2.To see how many connections each IP on the server is receiving:

netstat -plan |grep :80 | awk '{print $4}' | cut -d: -f1 | sort | uniq -c | sort -n

3.Get total current active connections to Apache:

netstat -apn | grep :80 | wc -l

Get Apache status update from command line to see which domain is receiving maximum hits (cPanel/WHM server):

lynx http://localhost/whm-server-status

Read More

The mod_security plugin could not connect to the database. Please verify that MySQL is running. Error: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) – Solution

If you’re getting following error while accessing mod_sec from WHM, here is the quick solution for this.

The Mod Security plugin could not connect to the database. Please verify that MySQL is running. Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Login to your WHM with root access.
Go to Service Manager from left menu.
See if MySQL Service is enabled and being monitored.
Check the boxes if unchecked.

Now access Mod Security from WHM. It should be working fine now.

Feedback are appreciated šŸ™‚

Disable Sym links on linux WHM/cPanel

Disabling SYM links is not a tough task on WHM/cPanel based servers, however you might not found proper way to do this, here is the quick code for disabling symlinks.

Why disabling symlinks is necessary for non-root users?

Gaining access to other accounts hosted on cPanel/WHM hosting servers is done by symbolic links, hackers usually create symbolic links on an hacked account to gain access to files hosted on other accounts so other accounts can be accessible through those symbolic links. To deal with this issue system administrator should disable symbolic links creation for non-root users.

  • Login to WHM/cPanel server via SSH with root access.
  • execute following commands:
  • $ wget http://layer1.rack911.com/before_apache_make -O
  • $ /scripts/before_apache_make
  • $Ā chmod 700 /scripts/before_apache_make
  • And then recompile apache by previous saved profile:
  • $ /scripts/easyapache

That is all, you can also check for any symbolic links already created:

  • $ find /home*/*/public_html -type l

    This will output directories and files those are sym linked.

Have fun!

How to deal with hackers for web server? Sym links solution

Nowadays hacking becomes more ordinary, and most web hosting companies are being targeted and there is no proper solution to prevent or to make your server 100% secure.

As a web hosting provider, we do always try to secure our servers from the hackers sometime it works but sometimes we failed.

Today i want to describe some commands forĀ Linux WHM/cPanelĀ based servers commands to make your server secure not 100% but it works out of the box. As i am using these commands to not prevent server from hacking but these commands are very useful and does not allow hackers to do anything on the server with other accounts.

I assume, you already familiar with theĀ sym links those are auto-created on the linux based servers, they allow hackers to create link directory/files with the other accounts, so they can access other accounts those are related to other cPanel accounts on the server.

If you disableĀ sym links on the server, hackers cannot hack into your server or if they are able to hack one account, other accounts will remain safe and will not get affected.

Well, disablingĀ sym links is not the proper solution and also disturbs functionality of some scripts on the server like joomla and wordpress.

Here i would like to describe some linux commands those are used to prevent creation of new symlinks in the root directory of an account, on cPanel it isĀ public_html.

Follow the following steps to:

  • Login to your server via ssh with root access.
  • Now make a check if there areĀ sym linksĀ  already created on the server.
  • Execute following command for cPanel:
  • Ā # find /home*/*/public_html -type l
  • Above command will display all theĀ sym links for all cPanel accounts created in public_html and sub directoriesĀ if any.
  • Now, add a cron job to check forĀ sym linksĀ  and remove them if found, you can set any interval, in the below command i set it to everyĀ 5Ā minutes.
  • So the command checks and removes allĀ sym linksĀ inside theĀ public_htmlĀ directory and their sub directories.
  • Execute the following commands to add cron job:
  • # crontab -e
  • A crontab file will be opened in default text-editor.
  • Go to last line and add below command:
  • */5 * * * * find /home*/*/public_html -type l -exec rm -rfv {} \;
  • Now, save your crontab file to make it functional.
  • And you’re done, this will check forĀ sym linksĀ insideĀ public_htmlĀ directory and will remove them if found.
  • TIP: you can also change the location of your directory for other control panels, by replacing /home*/*/public_html
  • Note: Do not execute command on system directories, your server will be destroyed and will become unstable.

That is all, comments are welcome : ) if it works for you.