How to prevent execessive scraping on Website on Ubuntu Server

Add rules as follows:

iptables -A INPUT -p tcp --syn --dport 80 -m connlimit\
 --connlimit-above 15 --connlimit-mask 32 -j REJECT \
 --reject-with tcp-reset 

This will reject connections above 15 from one source IP.

iptables -A INPUT -m state --state RELATED,ESTABLISHED \
-m limit --limit 150/second --limit-burst 160 -j ACCEPT  

In this 160 new connections (packets really) are allowed before the limit of 150 NEW connections (packets) per second is applied.

Note: if your server runs UFW (Uncomplicated Firewall), then you shouldn’t run the commands directly. Instead, you need to replace INPUT with ufw-before-input in each line and put the lines in the file /etc/ufw/before.rules. Afterwards, restart UFW using the following command:

sudo service ufw restart

Source

Limit max connections per IP address and new connections per second with iptables – Unix & Linux Stack Exchange. http://unix.stackexchange.com/questions/139285/limit-max-connections-per-ip-address-and-new-connections-per-second-with-iptable

How to remove all iptables rules

Create a file /root/fw.stop with the following content:

#!/bin/sh
echo "Stopping firewall and allowing everyone..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

Make it executable and then run it on the terminal.

Source: http://www.cyberciti.biz/tips/linux-iptables-how-to-flush-all-rules.html

How to read cron jobs

From time to time you may be interested in verifying that your cron jobs run as expected. How do we do that? By reading the logs of course. I will describe how to find cron logs in this article.

By default cron jobs get logged to

/var/log/syslog

To view only cron jobs, run the following command:

 grep CRON /var/log/syslog

How to install Canon MP250 on Ubuntu 11.10

This article discusses how to install the Canon MP250 all-in-one printer on Ubuntu 11.10

1. Download the printer drivers from the Canon website. You will need to select you Linux under ‘Operating system’ and your language. I choose English in this case.

2. Extract the contents of the archives. You can do this by opening a terminal (ctrl + alt + t), changing to the directory containing the drivers archive and running the following command :
tar xf mp250\ printer\ driver\ 3.40\.tar

I assume the name of the archive is ‘mp250 printer driver 3.40.tar’

Once done, you will have 3 archives created cnijfilter-mp250series-3.40-1-deb.tar.gz, cnijfilter-mp250series-3.40-1-rpm.tar.gz, and guidemp250series-pd-3.40-1_en.tar.gz.

3. Extract the contents of cnijfilter-mp250series-3.40-1-deb.tar.gz using the command :

tar xzf cnijfilter-mp250series-3.40-1-deb.tar.gz

This will create a folder called cnijfilter-mp250series-3.40-1-deb in the same directory.

4. Change to the cnijfilter-mp250series-3.40-1-deb directory. You will find 2 folders (packages and resources) and a file (install.sh).

5. Change to the packages directory. You will see 4 archives :
cnijfilter-common_3.40-1_amd64.deb
cnijfilter-common_3.40-1_i386.deb
cnijfilter-mp250series_3.40-1_amd64.deb
cnijfilter-mp250series_3.40-1_i386.deb

The archives ending with ‘amd64.db’ are for 64-bit machines while those ending with ‘i386.db’ are for 32-bit machines. For the next steps I assume you’re using a 64-bit machine. If using a 32-bit one, do the same on the corresponding files.

6. Double-click cnijfilter-common_3.40-1_amd64.deb. This will fire up Ubuntu Software Centre and install some drivers. Once done, you will see a check mark and the word ‘installed’ for ‘IJ Printer driver for Linux’

7. Double-click cnijfilter-mp250series_3.40-1_amd64.deb. This will fire up Ubuntu Software Centre and install some drivers. Once done, you will see a check mark and the word ‘installed’ for ‘IJ Printer driver for Linux’

8. You’re done. Now test the printer by printing a test page. If all goes well, you will find it works.

Note : I tried using the install.sh file mentioned earlier to no avail, even after commenting out and updating some parts of it as recommended in some articles on the Internet, so I advise not to bother using install.sh.

How to Set Email Addresses for a Linux User

Sometimes you may receive email failure messages when your computer tries to send a mail to a linux user regarding things like errors in cron jobs, etc. and the email address is not a valid one , e.g. root@your-computer-name. To fix this, set up forwarding of emails or aliases for your linux users. Here are the steps to setting up aliases, assuming we want to do this for the user root.

  • Open the aliases file :
    $ sudo vim /etc/aliases
  • Enter the new alias you want on a new line in the following format
    root: youremail@address.com
  • Save and close the file
  • Run the newaliases command
    $ newaliases

Now that this is done, the computer will send all root’s future emails to youremail@address.com

How to Type Special Characters in Ubuntu

Here I describe a technique to type special characters in Ubuntu with the keyboard if you use a few special symbols occasionally.

  • First, learn the hexadecimal value for the character. One way to do this is to open the Character Map application, find the character and check the unicode value at the bottom of the window. Close Character Map when done. Assuming the character you want to type is é then unicode values is 00e9
  • Type Ctrl + Shift + U, then type the unicode value of the character. You may omit leading zeros. So for é that will be Ctrl + Shift + U + e9. Then press Enter. Note after pressing Ctrl + Shift + U, an underlined u will appear behind the cursor to signify you are in unicode entry mode.

How to Mount Windows Partitions on Ubuntu

This tutorial describes how to mount a Windows partition on Ubuntu if you find it isn’t mounted automatically. We will use the UUID of the partition in mounting. I will describe how to mount Windows partition whenever Ubuntu is booted.

1. Find the device you want to mount. To do this, run the following in a terminal

$ sudo fdisk -l

Windows partitions will usually be in ntfs format. Usually it is at /dev/sda2 or /dev/sda3 and you may be able to differentiate the windows partition from a windows recovery partition by comparing the sizes.

2. Find the UUID of the windows partition by running the following in the terminal:

$ sudo blkid

Find the one corresponding to the Windows partition and have it handy.

3. Back up your file systems table configuration file (fstab) by running the following the following in a terminal:

$ sudo cp /etc/fstab /etc/fstab.orig

4. Edit fstab using your favourite editor. e.g.

$ sudo gedit /etc/fstab

5. Assuming we want to set the mount point for Windows to /media/windows, add the following line to fstab

$ UUID=the-uuid /media/windows ntfs-3g defaults,user,locale=en_US.utf8 0 0

Where the-uuid is the UUID you found in step 2. Save the close the file.

6. create that directory by running :

$ sudo mkdir /media/windows/

7. Unmount the partition and remount it by running these in a terminal:


$ sudo umount /media/windows
$ sudo mount /media/windows

Reference:
MountingWindowsPartitions – Community Ubuntu Documentation https://help.ubuntu.com/community/MountingWindowsPartitions