<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="et">
	<id>http://www.lambda.ee/w/index.php?action=history&amp;feed=atom&amp;title=Iptables_n%C3%A4iteskriptid_ja_infot</id>
	<title>Iptables näiteskriptid ja infot - Redigeerimiste ajalugu</title>
	<link rel="self" type="application/atom+xml" href="http://www.lambda.ee/w/index.php?action=history&amp;feed=atom&amp;title=Iptables_n%C3%A4iteskriptid_ja_infot"/>
	<link rel="alternate" type="text/html" href="http://www.lambda.ee/w/index.php?title=Iptables_n%C3%A4iteskriptid_ja_infot&amp;action=history"/>
	<updated>2026-10-28T11:51:59Z</updated>
	<subtitle>Selle lehekülje redigeerimiste ajalugu</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>http://www.lambda.ee/w/index.php?title=Iptables_n%C3%A4iteskriptid_ja_infot&amp;diff=8144&amp;oldid=prev</id>
		<title>Tammet – 9. mai 2008, kell 11:25</title>
		<link rel="alternate" type="text/html" href="http://www.lambda.ee/w/index.php?title=Iptables_n%C3%A4iteskriptid_ja_infot&amp;diff=8144&amp;oldid=prev"/>
		<updated>2008-05-09T11:25:01Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Uus lehekülg&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
---------- huge tutorial -------------------------&lt;br /&gt;
&lt;br /&gt;
see:&lt;br /&gt;
&lt;br /&gt;
http://iptables-tutorial.frozentux.net/iptables-tutorial.html&lt;br /&gt;
&lt;br /&gt;
---------------- setup --------------------------------&lt;br /&gt;
&lt;br /&gt;
kernel options must be configured:&lt;br /&gt;
&lt;br /&gt;
Networking-&amp;gt;&lt;br /&gt;
  Networking Options-&amp;gt;&lt;br /&gt;
    Network packet filtering (replaces ipchains)  ---&amp;gt; &lt;br /&gt;
      IP: Netfilter Configuration  ---&amp;gt;&lt;br /&gt;
       It is safe to enable all modules, I recommend compiling the ftp and other connection tracking modules as modules and not into the kernel so that you can verify they are loaded and functioning.&lt;br /&gt;
&lt;br /&gt;
iptables package must be installed&lt;br /&gt;
&lt;br /&gt;
run all iptables commands as root&lt;br /&gt;
&lt;br /&gt;
test results of commands: they should have immediate effect&lt;br /&gt;
&lt;br /&gt;
---------------- first example script ----------------&lt;br /&gt;
#!/bin/bash &lt;br /&gt;
set -x&lt;br /&gt;
# Load needed kernel modules&lt;br /&gt;
modprobe ip_conntrack&lt;br /&gt;
modprobe ip_conntrack_ftp&lt;br /&gt;
# Clear any existing firewall stuff before we start&lt;br /&gt;
iptables --flush&lt;br /&gt;
iptables -t nat --flush&lt;br /&gt;
iptables -t mangle --flush&lt;br /&gt;
# As the default policies, drop all incoming traffic but allow all&lt;br /&gt;
# outgoing traffic.  This will allow us to make outgoing connections&lt;br /&gt;
# from any port, but will only allow incoming connections on the ports&lt;br /&gt;
# specified below.&lt;br /&gt;
iptables --policy INPUT DROP&lt;br /&gt;
iptables --policy OUTPUT ACCEPT&lt;br /&gt;
----------------- second example script -------------&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# flush all chains&lt;br /&gt;
iptables -F&lt;br /&gt;
# set the default policy for each of the pre-defined chains&lt;br /&gt;
iptables -P INPUT ACCEPT&lt;br /&gt;
iptables -P OUTPUT ACCEPT&lt;br /&gt;
iptables -P FORWARD DROP&lt;br /&gt;
# allow establishment of connections initialised by my outgoing packets&lt;br /&gt;
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT&lt;br /&gt;
# drop everything else&lt;br /&gt;
iptables -A INPUT -i eth+ -p udp -j DROP&lt;br /&gt;
iptables -A INPUT -i eth+ -p tcp -m tcp --syn -j DROP&lt;br /&gt;
# accept anything on localhost&lt;br /&gt;
iptables -A INPUT -i lo -j ACCEPT&lt;br /&gt;
------------ third example script ---------------&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# firewall.sh - Configurable per-host firewall for workstations and&lt;br /&gt;
# servers.(c) 2003 Tero Karvinen - tero karvinen at iki fi - GPL&lt;br /&gt;
# Cleanup old rules&lt;br /&gt;
 # All the time firewall is in a secure, closed state&lt;br /&gt;
&lt;br /&gt;
iptables -P INPUT DROP&lt;br /&gt;
iptables -P FORWARD DROP&lt;br /&gt;
&lt;br /&gt;
iptables --flush        # Flush all rules, but keep policies &lt;br /&gt;
iptables --delete-chain&lt;br /&gt;
&lt;br /&gt;
## Workstation Minimal firewall ###&lt;br /&gt;
&lt;br /&gt;
iptables -P FORWARD DROP&lt;br /&gt;
iptables -P INPUT DROP&lt;br /&gt;
iptables -A INPUT -i lo --source 127.0.0.1 --destination 127.0.0.1 -j ACCEPT&lt;br /&gt;
iptables -A INPUT -m state --state &amp;quot;ESTABLISHED,RELATED&amp;quot; -j ACCEPT &lt;br /&gt;
iptables -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT&lt;br /&gt;
iptables -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT&lt;br /&gt;
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT&lt;br /&gt;
iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
####### HOLES ####### Edit holes below, then run this script again&lt;br /&gt;
#iptables -A INPUT -p tcp --dport ssh -j ACCEPT&lt;br /&gt;
#iptables -A INPUT -p tcp --dport http -j ACCEPT&lt;br /&gt;
#iptables -A INPUT -p tcp --dport https -j ACCEPT&lt;br /&gt;
##################### Edit above&lt;br /&gt;
&lt;br /&gt;
iptables -A INPUT -j LOG -m limit --limit 40/minute&lt;br /&gt;
iptables -A INPUT -j DROP&lt;br /&gt;
&lt;br /&gt;
# Save&lt;br /&gt;
iptables-save &amp;gt; /etc/sysconfig/iptables&lt;br /&gt;
echo &amp;quot;: Done.&amp;quot;&lt;br /&gt;
----------- complex example script for routing and nat: two subnets ----&lt;br /&gt;
iptables -I INPUT -s localhost -i eth0 -j DROP&lt;br /&gt;
iptables -A INPUT -m tcp -m match multiport --dport 22,21,80,443 -j ACCEPT&lt;br /&gt;
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT&lt;br /&gt;
iptables -A INPUT -i lo -j ACCEPT&lt;br /&gt;
iptables -A INPUT -i eth0 -p udp -m udp multiports --dports 57,63 -j REJECT --reject-with icmp-port-unreachable&lt;br /&gt;
iptables -A INPUT -i eth0 -p tcp -s 0/0 --sport 1024:65535 --dport 1024:65535 -m state --state ESTABLISHED,RELATED -j ACCEPT&lt;br /&gt;
iptables -A INPUT -i eth0 -p icmp -m state --state RELATED,ESTABLISHED -j ACCEPT&lt;br /&gt;
iptables -A INPUT -j LOG --log-prefix &amp;quot;[INPUT DROPPED]:&amp;quot; --log-level debug&lt;br /&gt;
iptables -I FORWARD -d 10.1.1.0/24 -i eth2 -j ACCEPT&lt;br /&gt;
iptables -A FORWARD -d 192.168.2.0/24 -i eth1 -j ACCEPT&lt;br /&gt;
iptables -A FORWARD -s 10.1.1.0/24 -i eth1 -j ACCEPT&lt;br /&gt;
iptables -A FORWARD -s 192.168.2.0/24 -i eth2 -j ACCEPT&lt;br /&gt;
iptables -A FORWARD -j LOG --log-prefix &amp;quot;[FORWARD DROPPED]:&amp;quot; --log-level debug&lt;br /&gt;
iptables -P FORWARD DROP&lt;br /&gt;
iptables -t nat -I POSTROUTING -o eth2 -j MASQUERADE&lt;br /&gt;
iptables -t nat -I POSTROUTING -o eth1 -j MASQUERADE&lt;br /&gt;
iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE&lt;br /&gt;
iptables -t nat -I PREROUTING -i eth0 -p tcp -m tcp --dport 8080 -j DNAT --to-destination 10.1.1.2&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tammet</name></author>
	</entry>
</feed>