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

An Introduction to tmux

Have you ever felt the discomfort of having to log in twice into a server so you can run two applications simultaneously? Have you wondered if there could be an easier way? Or are you looking for an easy way to start a long process on a server, detach from it, and connect back to the same session from a different client? Well, there’s a solution for all your worries. It’s called tmux! tmux allows you split a terminal into several subsections. It also allows you start a session over ssh and log out while the session keeps running, then log in via ssh on a possibly different machine and resume your session. So, the client becomes more irrelevant. I’ll discuss how to do a few things using tmux.

How to start a new tmux session run the following

tmux new -s session-name

or run the following

tmux new

It’s recommended to use the first format as it gives your sessions more meaningful names.

To detach from a session, run the following:

Ctrl-b d

or run the following

tmux detach

To list sessions, use the command

tmux ls

Note that tmux uses Ctrl-b as a prefix for its operations by default. This can be changed though as tmux is highly configurable.

To attach to an existing session use the following:

tmux a

This attaches to the first available session. You can also use the following:

tmux a -t session-name

To attach to a named session.

When logged in to a session, you can split the window into panes.

To split the window vertically, use the following command:

Ctrl-b %

To split it horizontally use the command:

Ctrl-b "

To switch pane, use the command

Ctrl-b arrow key

To resize a pane use the following command:

Hold Ctrl-b, then hold an arrow key

To scroll up a page on OS X, press Ctrl-b then [. This will put you in scroll mode. You can then use arrow keys to go up and down. To move page by page while in scroll mode, using PageUp and PageDown keys. On a laptop without PageUp key, you can simulate it by pressing Cmd-Up Arrow. To exit scroll mode press q.

To kill or delete a session use the command:

tmux kill-session -t myname

Some helpful resources on tmux can be found at:

dayid’s screen and tmux cheat sheet. http://www.dayid.org/os/notes/tm.html

tmux Tutorial – Split Terminal Windows Easily. http://lukaszwrobel.pl/blog/tmux-tutorial-split-terminal-windows-easily

A tmux Primer. https://danielmiessler.com/study/tmux/

Breathing in during Front Crawl

Hello folks,

In my last post I discussed the lessons I learnt about breathing out in water. Today I’m going to talk about breathing in air while doing a front crawl.

When breathing in, some beginners, myself included, tend to raise our heads to take in air. This is wrong as it causes the legs to sink. You see, the body can be thought of as a see-saw. When one part goes up on water the other part tends to go down.

So, how should one breathe out while swimming with front crawl? The best way which I discovered in my last lesson is to turn sideways with the neck remaining as parallel to your trunk as possible at appropriate moments. So what’s an appropriate moment? I’ll give an example. Suppose you want to breath out to your right side. So, you push and glide in the pool, then start kicking, and then you starting making hand strokes. You wait until your left hand is stretched straight in front of you while your right hand is stretched straight backwards. This is the perfect time to tilt your head to the right and take in some air.

Also, it’s important to keep kicking while breathing in otherwise you generally begin to sink.

How to fix error of missing zip decoder in Django with Ubuntu 14.04

If installing Django on Ubuntu 14.04 and you run into an error like “IOError: decoder zip not available” solve it as follows:

Install libzip and create a symbolic link in /usr/lib using the commands:

sudo apt-get install zlib1g-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/libz.so

Next, reinstall PIL using the commands while in bosg virtual environment:

pip uninstall PIL
pip install  --no-cache-dir PIL --allow-external \
PIL --allow-unverified PIL

Finally, refresh project if on producion environment.

How to search for packages in Ubuntu

Sometimes while working in Ubuntu you may want to find a package, but not know its name. There’s a command for that. It’s called apt-cache.

apt-cache search <your package>

Source

apt – How do I search for available packages from the command-line? – Ask Ubuntu. http://askubuntu.com/questions/160897/how-do-i-search-for-available-packages-from-the-command-line

How to Send Email in Terminal

In this article I demonstrate how to send emails from the terminal of an Ubuntu machine. It’s assumed you have a Mail Transfer Agent like Exim 4 or Postfix set up.

 echo "<message goes here>" | mail \
 -s "<subject goes here>" <to email address>

Sources

How to send email from the Linux command line – Simple Help. http://www.simplehelp.net/2008/12/01/how-to-send-email-from-the-linux-command-line/