<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.bzflag.org/index.php?action=history&amp;feed=atom&amp;title=Iptables</id>
	<title>Iptables - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.bzflag.org/index.php?action=history&amp;feed=atom&amp;title=Iptables"/>
	<link rel="alternate" type="text/html" href="https://wiki.bzflag.org/index.php?title=Iptables&amp;action=history"/>
	<updated>2026-04-06T22:26:18Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://wiki.bzflag.org/index.php?title=Iptables&amp;diff=6995&amp;oldid=prev</id>
		<title>Blast: New page: {{InfoBox|Note|This page is still being worked on. Use at your own risk.}}  This is a collection of notes about modifying your iptables packet filter to add blocking of specific IPs and sy...</title>
		<link rel="alternate" type="text/html" href="https://wiki.bzflag.org/index.php?title=Iptables&amp;diff=6995&amp;oldid=prev"/>
		<updated>2010-03-30T11:52:02Z</updated>

		<summary type="html">&lt;p&gt;New page: {{InfoBox|Note|This page is still being worked on. Use at your own risk.}}  This is a collection of notes about modifying your iptables packet filter to add blocking of specific IPs and sy...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{InfoBox|Note|This page is still being worked on. Use at your own risk.}}&lt;br /&gt;
&lt;br /&gt;
This is a collection of notes about modifying your iptables packet filter to add blocking of specific IPs and systems on the Tor network.&lt;br /&gt;
&lt;br /&gt;
Original source: http://doc.norang.ca/iptables.html&lt;br /&gt;
Copied to wiki with permission from content author.&lt;br /&gt;
&lt;br /&gt;
==Basic Setup==&lt;br /&gt;
The following is a basic firewall script that you can load with &lt;br /&gt;
&lt;br /&gt;
 iptables-restore &amp;lt;iptables&lt;br /&gt;
&lt;br /&gt;
It allows access to&lt;br /&gt;
&lt;br /&gt;
{|{{Prettytable}}&lt;br /&gt;
| {{Hl3}} |&amp;#039;&amp;#039;&amp;#039;Port&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| {{Hl3}} |&amp;#039;&amp;#039;&amp;#039;Service&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| {{Hl3}} |&amp;#039;&amp;#039;&amp;#039;Notes&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
|-&lt;br /&gt;
|25&lt;br /&gt;
|SMTP&lt;br /&gt;
|Incoming email&lt;br /&gt;
|-&lt;br /&gt;
|110&lt;br /&gt;
|POP3&lt;br /&gt;
|POP3 service for email&lt;br /&gt;
|-&lt;br /&gt;
|53&lt;br /&gt;
|DNS&lt;br /&gt;
|Name server requests&lt;br /&gt;
|-&lt;br /&gt;
|22&lt;br /&gt;
|SSH&lt;br /&gt;
|Incoming SSH requests&lt;br /&gt;
|-&lt;br /&gt;
|80&lt;br /&gt;
|HTTP&lt;br /&gt;
|Webserver requests&lt;br /&gt;
|-&lt;br /&gt;
|443&lt;br /&gt;
|HTTPS&lt;br /&gt;
|Secure HTTP&lt;br /&gt;
|-&lt;br /&gt;
|4000:5200&lt;br /&gt;
|BZFlag Servers&lt;br /&gt;
|BZFlag server ports&lt;br /&gt;
|-&lt;br /&gt;
|6000:6200&lt;br /&gt;
|BZFlag Servers&lt;br /&gt;
|More server ports&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Anything else is logged and dropped at the firewall.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;logwatch&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; package makes nice daily summaries of the firewall logs.&lt;br /&gt;
  &lt;br /&gt;
Here is the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;iptables&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; file:&lt;br /&gt;
 # Generated by iptables-save v1.3.6 on Mon Oct 20 14:37:02 2008&lt;br /&gt;
 *filter&lt;br /&gt;
 :INPUT DROP [0:0]&lt;br /&gt;
 :FORWARD ACCEPT [0:0]&lt;br /&gt;
 :OUTPUT ACCEPT [8574312917:611260898475]&lt;br /&gt;
 -A INPUT -p tcp -m tcp --dport 25 -j ACCEPT &lt;br /&gt;
 -A INPUT -p tcp -m tcp --dport 110 -j ACCEPT &lt;br /&gt;
 -A INPUT -p udp -m udp --dport 53 -m state --state NEW -j ACCEPT &lt;br /&gt;
 -A INPUT -p tcp -m tcp --dport 53 -m state --state NEW -j ACCEPT &lt;br /&gt;
 -A INPUT -p icmp -j ACCEPT &lt;br /&gt;
 -A INPUT -i lo -j ACCEPT &lt;br /&gt;
 -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT &lt;br /&gt;
 -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -j ACCEPT &lt;br /&gt;
 -A INPUT -p tcp -m tcp --dport 80 -m state --state NEW -j ACCEPT &lt;br /&gt;
 -A INPUT -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT &lt;br /&gt;
 -A INPUT -p tcp -m tcp --dport 4000:5200 -m state --state NEW -j ACCEPT &lt;br /&gt;
 -A INPUT -p udp -m udp --dport 4000:5200 -m state --state NEW -j ACCEPT &lt;br /&gt;
 -A INPUT -p tcp -m tcp --dport 6000:6200 -m state --state NEW -j ACCEPT &lt;br /&gt;
 -A INPUT -p udp -m udp --dport 6000:6200 -m state --state NEW -j ACCEPT &lt;br /&gt;
 -A INPUT -j LOG &lt;br /&gt;
 -A INPUT -j DROP &lt;br /&gt;
 -A OUTPUT -o lo -j ACCEPT &lt;br /&gt;
 COMMIT&lt;br /&gt;
 # Completed on Mon Oct 20 14:37:02 2008&lt;br /&gt;
 # Generated by iptables-save v1.3.6 on Mon Oct 20 14:37:02 2008&lt;br /&gt;
 *mangle&lt;br /&gt;
 :PREROUTING ACCEPT [2345559699:169138998026]&lt;br /&gt;
 :INPUT ACCEPT [2345528243:169135560350]&lt;br /&gt;
 :FORWARD ACCEPT [0:0]&lt;br /&gt;
 :OUTPUT ACCEPT [9525683538:678126408324]&lt;br /&gt;
 :POSTROUTING ACCEPT [9525683538:678126408324]&lt;br /&gt;
 COMMIT&lt;br /&gt;
 # Completed on Mon Oct 20 14:37:02 2008&lt;br /&gt;
 # Generated by iptables-save v1.3.6 on Mon Oct 20 14:37:02 2008&lt;br /&gt;
 *nat&lt;br /&gt;
 :PREROUTING ACCEPT [8235419:506261976]&lt;br /&gt;
 :POSTROUTING ACCEPT [1475984:91496805]&lt;br /&gt;
 :OUTPUT ACCEPT [1475984:91496805]&lt;br /&gt;
 COMMIT&lt;br /&gt;
 # Completed on Mon Oct 20 14:37:02 2008&lt;br /&gt;
&lt;br /&gt;
===Tie the rules to the network interface===&lt;br /&gt;
In Debian you can automatically run scripts when interfaces are started and stopped. We keep the firewall rules in &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;/etc/iptables&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; and have the following lines in &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;/etc/network/interfaces&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; to save and restore the current set of rules across reboots.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;/etc/network/interfaces&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 # The loopback network interface&lt;br /&gt;
 auto lo&lt;br /&gt;
 iface lo inet loopback&lt;br /&gt;
 &lt;br /&gt;
 # The primary network interface&lt;br /&gt;
 iface eth0 inet static&lt;br /&gt;
   address 1.2.3.4&lt;br /&gt;
   netmask 255.255.255.255&lt;br /&gt;
   gateway 1.2.3.1&lt;br /&gt;
   #&lt;br /&gt;
   # iptables&lt;br /&gt;
   up /sbin/iptables-restore -c &amp;lt;/etc/iptables&lt;br /&gt;
   down /sbin/iptables-save -c &amp;gt;/etc/iptables&lt;br /&gt;
   #&lt;br /&gt;
&lt;br /&gt;
==Custom Chains==&lt;br /&gt;
&lt;br /&gt;
Add custom chains to hold your custom firewall rules. Here we use two new chains &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;TOR_BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; to keep two separate lists of IPs to be blocked at the firewall.&lt;br /&gt;
&lt;br /&gt;
===Adding Chains===&lt;br /&gt;
&lt;br /&gt;
Chains are where you keep your rules.  You can add new chains with &lt;br /&gt;
&lt;br /&gt;
 iptables -N NEWCHAIN&lt;br /&gt;
&lt;br /&gt;
==Blocking Tor Systems==&lt;br /&gt;
&lt;br /&gt;
Here we use a new chain (&amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;TOR_BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;) and a script to populate the chain. This automatically keeps the list of IPs to block from the Tor network up to date hourly.&lt;br /&gt;
&lt;br /&gt;
===Adding TOR_BLOCK chain to the INPUT chain===&lt;br /&gt;
&lt;br /&gt;
Create your new chain to hold Tor network node IPs to block with&lt;br /&gt;
&lt;br /&gt;
 iptables -N TOR_BLOCK&lt;br /&gt;
&lt;br /&gt;
and tie this chain to your input rules with&lt;br /&gt;
&lt;br /&gt;
 iptables -I INPUT -j TOR_BLOCK&lt;br /&gt;
&lt;br /&gt;
This jumps from the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;INPUT&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain to the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;TOR_BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain and then returns to the next rule in the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;INPUT&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; after hitting the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;RETURN&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; at the end of the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;TOR_BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain.&lt;br /&gt;
&lt;br /&gt;
===Populating the TOR_BLOCK chain===&lt;br /&gt;
We will populate the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;TOR_BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain automatically using the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;torblock.fw&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; script below.&lt;br /&gt;
&lt;br /&gt;
This will empty the TOR_BLOCK chain, add a RETURN to the end of the chain so we can process it like a subroutine and enter each listed Tor network IP into the list.&lt;br /&gt;
&lt;br /&gt;
You can run the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;torblock.fw&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; script manually to wipe and populate the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;TOR_BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain. After you&amp;#039;re happy with it I add a &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;crontab&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; entry that updates the list once an hour.&lt;br /&gt;
&lt;br /&gt;
====/usr/local/sbin/torblock.fw Script====&lt;br /&gt;
&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 &lt;br /&gt;
 # A simple bash script to block IP traffic from TOR exit nodes.&lt;br /&gt;
 # written by Andrew Vetlugin (antrew at gmail com)&lt;br /&gt;
 &lt;br /&gt;
 wget=&amp;#039;/usr/bin/wget&amp;#039;&lt;br /&gt;
 iptables=&amp;#039;/sbin/iptables&amp;#039;&lt;br /&gt;
 #url=&amp;#039;https://torstat.xenobite.eu/export/tor_exitnodes.csv&amp;#039;&lt;br /&gt;
 url=&amp;#039;http://torstatus.kgprog.com/ip_list_exit.php/Tor_ip_list_EXIT.csv&amp;#039;&lt;br /&gt;
 &lt;br /&gt;
 iptables_target=&amp;#039;DROP&amp;#039;&lt;br /&gt;
 #iptables_target=&amp;#039;REJECT&amp;#039;&lt;br /&gt;
 &lt;br /&gt;
 # Quick guide:&lt;br /&gt;
 &lt;br /&gt;
 # 1. add a separate chain for a list of TOR exit nodes&lt;br /&gt;
 # (this should be done by hand once)&lt;br /&gt;
 # iptables -N TOR_BLOCK&lt;br /&gt;
 &lt;br /&gt;
 # 2. add a rule to INPUT chain&lt;br /&gt;
 # Note: if you want to be able to connect to any TOR exit node yourself&lt;br /&gt;
 # (e.g., if $url is a exit node you should be able to fetch a list of exit&lt;br /&gt;
 # nodes from it) then you should add this rule AFTER accepting established&lt;br /&gt;
 # and related connections)&lt;br /&gt;
 # iptables -A INPUT -j TOR_BLOCK&lt;br /&gt;
 &lt;br /&gt;
 # 3. add this script to crontab (I think 10-20 minutes interval should be OK)&lt;br /&gt;
 &lt;br /&gt;
 # flush chain&lt;br /&gt;
 $iptables -F TOR_BLOCK&lt;br /&gt;
 &lt;br /&gt;
 # return to parent chain if the source is not TOR exit node&lt;br /&gt;
 $iptables -I TOR_BLOCK -j RETURN &lt;br /&gt;
 &lt;br /&gt;
 # add TOR exit nodes to TOR_BLOCK chain with $iptables_target rule&lt;br /&gt;
 for node in `$wget -q --no-check-certificate -O - $url | sort | uniq`; do&lt;br /&gt;
         $iptables -I TOR_BLOCK -s $node -j $iptables_target&lt;br /&gt;
 done&lt;br /&gt;
&lt;br /&gt;
===Crontab Entry===&lt;br /&gt;
&lt;br /&gt;
The following &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;crontab&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; entry runs the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;torblock.fw&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; script.  This effectively erases all the Tor network nodes and re-populates the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;TOR_BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; list hourly.&lt;br /&gt;
&lt;br /&gt;
 00 * * * * root /usr/local/sbin/torblock.fw&lt;br /&gt;
&lt;br /&gt;
==Manual Blocking Chains==&lt;br /&gt;
&lt;br /&gt;
Now to deal with other problem systems we keep a separate &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; list which we can manually add, list, and remove entries from.  The following scripts can be provided to trusted users via &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;sudo&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; so they can view and manipulate the firewall rules.&lt;br /&gt;
&lt;br /&gt;
===Add BLOCK chain===&lt;br /&gt;
&lt;br /&gt;
Add the new chain to hold the IPs to block.&lt;br /&gt;
&lt;br /&gt;
 iptables -N BLOCK&lt;br /&gt;
&lt;br /&gt;
Add a single rule to return from the end of the list to the calling chain.&lt;br /&gt;
&lt;br /&gt;
 iptables -I BLOCK -j RETURN&lt;br /&gt;
&lt;br /&gt;
and tie this chain to to your input rules.&lt;br /&gt;
&lt;br /&gt;
 iptables -I INPUT -j BLOCK&lt;br /&gt;
&lt;br /&gt;
This jumps from the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;INPUT&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain to the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain and then returns to the next rule in the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;INPUT&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain after hitting the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;RETURN&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; at the end of the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain.&lt;br /&gt;
&lt;br /&gt;
===Blocking IPs===&lt;br /&gt;
&lt;br /&gt;
Blocking IPs using the new &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain is pretty simple.&lt;br /&gt;
&lt;br /&gt;
 usage:&lt;br /&gt;
     sudo block IP&lt;br /&gt;
     sudo block IP/nn&lt;br /&gt;
     sudo block IP &amp;#039;comment goes here&amp;#039;&lt;br /&gt;
     sudo block IP/nn &amp;#039;comment goes here&amp;#039;&lt;br /&gt;
&lt;br /&gt;
     e.g.&lt;br /&gt;
     sudo block 1.2.3.4 # Adds 1.2.3.4 as the IP to block&lt;br /&gt;
     sudo block 1.2.3.4 &amp;#039;reason for block&amp;#039; # Adds 1.2.3.4 with a comment&lt;br /&gt;
     sudo block 1.2.3.4/24 &amp;#039;block subnet&amp;#039; # Blocks all ips matching 1.2.3.*&lt;br /&gt;
&lt;br /&gt;
Comments are kept in the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;iptables&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain and are displayed by the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;blocklist&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; script below.&lt;br /&gt;
&lt;br /&gt;
====Block Script - /usr/local/sbin/block====&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 INPUT=&amp;quot;$(echo $1 | sed &amp;#039;s/[^.0-9/]//g&amp;#039;)&amp;quot;&lt;br /&gt;
 COMMENT=&amp;quot;$2&amp;quot;&lt;br /&gt;
 if [ &amp;quot;x$COMMENT&amp;quot; == &amp;quot;x&amp;quot; ]&lt;br /&gt;
 then&lt;br /&gt;
         iptables -I BLOCK -s $INPUT -j DROP&lt;br /&gt;
 else&lt;br /&gt;
         iptables -I BLOCK -s $INPUT -m comment --comment &amp;quot;$COMMENT&amp;quot; -j DROP&lt;br /&gt;
 fi&lt;br /&gt;
 /usr/local/sbin/blocklist&lt;br /&gt;
&lt;br /&gt;
===Unblocking IPs===&lt;br /&gt;
&lt;br /&gt;
To unblock an IP (removing it from the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;BLOCK&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; chain) just pass the IP as parameter 1 and the comment (if any) exactly as it was entered when blocking the IP.&lt;br /&gt;
&lt;br /&gt;
 usage:&lt;br /&gt;
     sudo unblock IP&lt;br /&gt;
     sudo unblock IP &amp;#039;comment goes here&amp;#039;&lt;br /&gt;
&lt;br /&gt;
====Unblock Script - /usr/local/sbin/unblock====&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 INPUT=&amp;quot;$(echo $1 | sed &amp;#039;s/[^.0-9/]//g&amp;#039;)&amp;quot;&lt;br /&gt;
 COMMENT=&amp;quot;$2&amp;quot;&lt;br /&gt;
 if [ &amp;quot;x$COMMENT&amp;quot; == &amp;quot;x&amp;quot; ]&lt;br /&gt;
 then&lt;br /&gt;
         iptables -D BLOCK -s $INPUT -j DROP&lt;br /&gt;
 else&lt;br /&gt;
         iptables -D BLOCK -s $INPUT -m comment --comment &amp;quot;$COMMENT&amp;quot; -j DROP&lt;br /&gt;
 fi&lt;br /&gt;
 /usr/local/sbin/blocklist&lt;br /&gt;
&lt;br /&gt;
===Listing Blocked IPs===&lt;br /&gt;
The following script simply displays the entries in the blocklist.&lt;br /&gt;
&lt;br /&gt;
 Usage: &lt;br /&gt;
     sudo blocklist&lt;br /&gt;
&lt;br /&gt;
====Block List script - /usr/local/sbin/blocklist====&lt;br /&gt;
&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 iptables -L BLOCK -n&lt;br /&gt;
&lt;br /&gt;
==Rate Limiting Connections==&lt;br /&gt;
To effectively block script-kiddies that try dictionary attacks on the SSH server port I have the two following rules before the rule that accepts SSH connections&lt;br /&gt;
&lt;br /&gt;
 -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set&lt;br /&gt;
 -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 -j DROP&lt;br /&gt;
&lt;br /&gt;
This allows up to 3 connections from the same IP in a 60 second period.  Any more than that are blocked (and not logged).&lt;br /&gt;
&lt;br /&gt;
Waiting 60 seconds before retrying the connection attempt makes it work again.&lt;br /&gt;
&lt;br /&gt;
==Saving and Restoring tables==&lt;br /&gt;
&lt;br /&gt;
I save the current &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;iptables&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; firewall rules with&lt;br /&gt;
 /sbin/iptables-save -c &amp;gt;/etc/iptables&lt;br /&gt;
&lt;br /&gt;
These can be restored with the following command&lt;br /&gt;
 /sbin/iptables-restore -c &amp;lt;/etc/iptables&lt;br /&gt;
&lt;br /&gt;
These are normally added to my &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;/etc/network/interfaces&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; file on Debian when the appropriate network interface is brought up or down.&lt;br /&gt;
&lt;br /&gt;
 # Example /etc/network/interfaces entries&lt;br /&gt;
 &lt;br /&gt;
 # The primary network interface&lt;br /&gt;
 iface eth0 inet static&lt;br /&gt;
     address 1.2.3.4&lt;br /&gt;
     netmask 255.255.255.0&lt;br /&gt;
     gateway 1.2.3.1&lt;br /&gt;
     up /sbin/iptables-restore -c &amp;lt;/etc/iptables&lt;br /&gt;
     down /sbin/iptables-save -c &amp;gt;/etc/iptables&lt;/div&gt;</summary>
		<author><name>Blast</name></author>
	</entry>
</feed>