<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>My Geek Finds &#187; iptables</title>
	<atom:link href="http://www.mygeekfinds.com/tag/iptables/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mygeekfinds.com</link>
	<description>Tech notes, Virtualization, Networking</description>
	<lastBuildDate>Tue, 23 Feb 2010 13:43:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Handy Linux iptables script</title>
		<link>http://www.mygeekfinds.com/2009/04/handy-linux-iptables-script/</link>
		<comments>http://www.mygeekfinds.com/2009/04/handy-linux-iptables-script/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 13:18:06 +0000</pubDate>
		<dc:creator>Hersey</dc:creator>
				<category><![CDATA[My Notes]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[localhost]]></category>

		<guid isPermaLink="false">http://www.mygeekfinds.com/?p=208</guid>
		<description><![CDATA[Here is a script I put together some years ago to create a simple Iptables firewall on my linux webserver.  Some of the code was borrowed from a linux security book but I do not remember which one.  Anyway it is a pretty handy script to give you some control and protection.
First create [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a script I put together some years ago to create a simple Iptables firewall on my linux webserver.  Some of the code was borrowed from a linux security book but I do not remember which one.  Anyway it is a pretty handy script to give you some control and protection.</p>
<p>First create three files in /usr/local/etc:</p>
<p>ipblack.lst &#8211; this file contains a list of ip addresses you want to blacklist.  One ip or subnet per line.</p>
<p>Example:</p>
<blockquote><p>
94.178.222.17<br />
87.0.0.0/8
</p></blockquote>
<p>ipwhite.lst &#8211; this file contains a list of ip addresses that you allow unrestricted access (Be careful with this).  One ip or subnet per line.  Make sure you add localhost to this file.</p>
<p>Example:</p>
<blockquote><p>
localhost<br />
10.10.1.1 #Home IP Address
</p></blockquote>
<p>ports.lst &#8211; this file contains a list of ports you allow.</p>
<p>Example:</p>
<blockquote><p>
22   #SSH<br />
25   #SMTP<br />
53   #DNS/Domain<br />
80   #HTTPD<br />
443   #HTTPS
</p></blockquote>
<p>Add this iptables.sh script to /usr/local/sbin</p>
<blockquote><p>
#!/bin/sh</p>
<p>#Iptables for webserver</p>
<p>IPTABLES=/sbin/iptables<br />
WHITELIST=/usr/local/etc/ipwhite.lst<br />
BLACKLIST=/usr/local/etc/ipblack.lst<br />
PORTSLIST=/usr/local/etc/ports.lst</p>
<p>#&#8212;-Flood Variables&#8212;&#8211;#</p>
<p># Overall Limit for TCP-SYN-Flood detection<br />
TCPSYNLIMIT=&#8221;5/s&#8221;<br />
# Burst Limit for TCP-SYN-Flood detection<br />
TCPSYNLIMITBURST=&#8221;10&#8243;</p>
<p># Overall Limit for Loggging in Logging-Chains<br />
LOGLIMIT=&#8221;2/s&#8221;<br />
# Burst Limit for Logging in Logging-Chains<br />
LOGLIMITBURST=&#8221;10&#8243;</p>
<p># Overall Limit for Ping-Flood-Detection<br />
PINGLIMIT=&#8221;5/s&#8221;</p>
<p># Burst Limit for Ping-Flood-Detection<br />
PINGLIMITBURST=&#8221;10&#8243;</p>
<p>#Clear  any current filters<br />
$IPTABLES -F</p>
<p>#Process Whitelist<br />
for x in `grep -v ^# $WHITELIST | awk &#8216;{print $1}&#8217;`; do<br />
echo &#8220;Permitting $x&#8230;&#8221;<br />
$IPTABLES -A INPUT -t filter -s $x -j ACCEPT<br />
done</p>
<p>#Process Blacklist<br />
for x in  `grep -v ^# $BLACKLIST | awk &#8216;{print $1}&#8217;`; do<br />
echo &#8220;Blocking $x&#8230;&#8221;<br />
#$IPTABLES -A INPUT -t filter -s $x -j LOG<br />
$IPTABLES -A INPUT -t filter -s $x -j DROP<br />
done</p>
<p>#Allow Ports list<br />
for port in  `grep -v ^# $PORTSLIST | awk &#8216;{print $1}&#8217;`; do<br />
echo &#8220;Accepting port $port&#8230;&#8221;<br />
$IPTABLES -A INPUT -t filter -p tcp &#8211;dport $port -j ACCEPT<br />
done</p>
<p>$IPTABLES -A INPUT -t filter -p tcp &#8211;syn -j DROP</p>
<p>#ICMP TIMESTAMP REQUEST AND REPLY<br />
$IPTABLES -A INPUT -p icmp &#8211;icmp-type timestamp-request -j DROP<br />
$IPTABLES -A FORWARD -p icmp &#8211;icmp-type timestamp-request -j DROP</p>
<p>#Logging of possible TCP-SYN-Floods<br />
$IPTABLES -N LSYNFLOOD<br />
$IPTABLES -A LSYNFLOOD -m limit &#8211;limit $LOGLIMIT &#8211;limit-burst $LOGLIMITBURST -j LOG &#8211;log-prefix &#8220;fp=SYNFLOOD:1 a=DROP &#8221;<br />
$IPTABLES -A LSYNFLOOD -j DROP</p>
<p>#INVALID SYN packets<br />
$IPTABLES -A INPUT -i eth0 -p tcp &#8211;tcp-flags ALL ACK,RST,SYN,FIN -j DROP<br />
$IPTABLES -A INPUT -i eth0 -p tcp &#8211;tcp-flags SYN,FIN SYN,FIN -j DROP<br />
$IPTABLES -A INPUT -i eth0 -p tcp &#8211;tcp-flags SYN,RST SYN,RST -j DROP</p>
<p>#Logging of possible Ping-Floods<br />
$IPTABLES -N LPINGFLOOD<br />
$IPTABLES -A LPINGFLOOD -m limit &#8211;limit $LOGLIMIT &#8211;limit-burst $LOGLIMITBURST -j LOG &#8211;log-prefix &#8220;fp=PINGFLOOD:1 a=DROP &#8221;<br />
$IPTABLES -A LPINGFLOOD -j DROP</p>
</blockquote>
<p>Add /usr/local/sbin/iptables.sh to rc.local so that it runs when the machine starts up.</p>
<p>Anytime you make changes to the ipblack.lst, ipwhite.lst, or ports.lst files rerun the iptables.sh script to apply the rules.</p>
<p>The script also applies iptable rules to help protect against <a href="http://en.wikipedia.org/wiki/Ping_flood">ping floods</a>, <a href="http://en.wikipedia.org/wiki/SYN_flood">SYN flood</a>, and invalid SYN packets.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mygeekfinds.com/2009/04/handy-linux-iptables-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
