<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="it">
	<id>http://www.lumacaonline.org/kiwi/index.php?action=history&amp;feed=atom&amp;title=Iptables</id>
	<title>Iptables - Cronologia</title>
	<link rel="self" type="application/atom+xml" href="http://www.lumacaonline.org/kiwi/index.php?action=history&amp;feed=atom&amp;title=Iptables"/>
	<link rel="alternate" type="text/html" href="http://www.lumacaonline.org/kiwi/index.php?title=Iptables&amp;action=history"/>
	<updated>2026-06-07T05:41:08Z</updated>
	<subtitle>Cronologia della pagina su questo sito</subtitle>
	<generator>MediaWiki 1.39.1</generator>
	<entry>
		<id>http://www.lumacaonline.org/kiwi/index.php?title=Iptables&amp;diff=25&amp;oldid=prev</id>
		<title>Award: Creata pagina con &quot;http://www.cyberciti.biz/tips/linux-iptables-examples.html    == Linux: 20 Iptables Examples For New SysAdmins ==   by NIX Craft on December 13, 2011 · 64 comments· LAST...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.lumacaonline.org/kiwi/index.php?title=Iptables&amp;diff=25&amp;oldid=prev"/>
		<updated>2017-08-16T22:33:12Z</updated>

		<summary type="html">&lt;p&gt;Creata pagina con &amp;quot;&lt;a href=&quot;/kiwi/index.php?title=Http://www.cyberciti.biz/tips/linux-iptables-examples.html&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Http://www.cyberciti.biz/tips/linux-iptables-examples.html (la pagina non esiste)&quot;&gt;http://www.cyberciti.biz/tips/linux-iptables-examples.html&lt;/a&gt;    == Linux: 20 Iptables Examples For New SysAdmins ==   by NIX Craft on December 13, 2011 · 64 comments· LAST...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nuova pagina&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[http://www.cyberciti.biz/tips/linux-iptables-examples.html]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Linux: 20 Iptables Examples For New SysAdmins ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
by NIX Craft on December 13, 2011 · 64 comments· LAST UPDATED March 20, 2012&lt;br /&gt;
&lt;br /&gt;
in Iptables, Linux, Linux distribution&lt;br /&gt;
&lt;br /&gt;
Linux comes with a host based firewall called Netfilter. According to the official project site:&lt;br /&gt;
netfilter is a set of hooks inside the Linux kernel that allows kernel modules to register callback functions with the network stack.&lt;br /&gt;
&lt;br /&gt;
A registered callback function is then called back for every packet that traverses the respective hook within the network stack.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This Linux based firewall is controlled by the program called iptables to handles filtering for IPv4, and ip6tables handles filtering for IPv6. &lt;br /&gt;
&lt;br /&gt;
I strongly recommend that you first read our quick tutorial that explains how to configure a host-based firewall called Netfilter (iptables) &lt;br /&gt;
&lt;br /&gt;
under CentOS / RHEL / Fedora / Redhat Enterprise Linux. This post list most common iptables solutions required by a new Linux user to secure his or her Linux operating system from intruders.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''IPTABLES Rules Example'''&lt;br /&gt;
&lt;br /&gt;
Most of the actions listed in this post are written with the assumption that they will be executed by the root user running the bash or any other modern shell. Do not type commands on remote system as it will disconnect your access.&lt;br /&gt;
For demonstration purpose I've used RHEL 6.x, but the following command should work with any modern Linux distro.&lt;br /&gt;
This is NOT a tutorial on how to set iptables. See tutorial here. It is a quick cheat sheet to common iptables commands.&lt;br /&gt;
&lt;br /&gt;
 #1: Displaying the Status of Your Firewall&lt;br /&gt;
 &lt;br /&gt;
 Type the following command as root:&lt;br /&gt;
 # iptables -L -n -v&lt;br /&gt;
&lt;br /&gt;
 Sample outputs:&lt;br /&gt;
 &lt;br /&gt;
 Chain INPUT (policy ACCEPT 0 packets, 0 bytes)&lt;br /&gt;
  pkts bytes target     prot opt in     out     source               destination&lt;br /&gt;
 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)&lt;br /&gt;
  pkts bytes target     prot opt in     out     source               destination&lt;br /&gt;
 Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)&lt;br /&gt;
  pkts bytes target     prot opt in     out     source               destination&lt;br /&gt;
&lt;br /&gt;
Above output indicates that the firewall is not active. The following sample shows an active firewall:&lt;br /&gt;
&lt;br /&gt;
 # iptables -L -n -v&lt;br /&gt;
 Sample outputs:&lt;br /&gt;
 &lt;br /&gt;
 Chain INPUT (policy DROP 0 packets, 0 bytes)&lt;br /&gt;
  pkts bytes target     prot opt in     out     source               destination&lt;br /&gt;
     0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID&lt;br /&gt;
   394 43586 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED&lt;br /&gt;
    93 17292 ACCEPT     all  --  br0    *       0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
     1   142 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
 Chain FORWARD (policy DROP 0 packets, 0 bytes)&lt;br /&gt;
  pkts bytes target     prot opt in     out     source               destination&lt;br /&gt;
     0     0 ACCEPT     all  --  br0    br0     0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
     0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID&lt;br /&gt;
     0     0 TCPMSS     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x02 TCPMSS clamp to PMTU&lt;br /&gt;
     0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED&lt;br /&gt;
     0     0 wanin      all  --  vlan2  *       0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
     0     0 wanout     all  --  *      vlan2   0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
     0     0 ACCEPT     all  --  br0    *       0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
 Chain OUTPUT (policy ACCEPT 425 packets, 113K bytes)&lt;br /&gt;
  pkts bytes target     prot opt in     out     source               destination&lt;br /&gt;
 Chain wanin (1 references)&lt;br /&gt;
  pkts bytes target     prot opt in     out     source               destination&lt;br /&gt;
 Chain wanout (1 references)&lt;br /&gt;
  pkts bytes target     prot opt in     out     source               destination&lt;br /&gt;
&lt;br /&gt;
Where,&lt;br /&gt;
&lt;br /&gt;
    -L : List rules.&lt;br /&gt;
    -v : Display detailed information. This option makes the list command show the interface name, the rule options, and the TOS masks. &lt;br /&gt;
The packet and byte counters are also listed, with the suffix 'K', 'M' or 'G' for 1000, 1,000,000 and 1,000,000,000 multipliers respectively.&lt;br /&gt;
    -n : Display IP address and port in numeric format. Do not use DNS to resolve names. This will speed up listing.&lt;br /&gt;
&lt;br /&gt;
''#1.1: To inspect firewall with line numbers, enter:''&lt;br /&gt;
&lt;br /&gt;
 # iptables -n -L -v --line-numbers&lt;br /&gt;
 &lt;br /&gt;
 Sample outputs:&lt;br /&gt;
 &lt;br /&gt;
 Chain INPUT (policy DROP)&lt;br /&gt;
 num  target     prot opt source               destination&lt;br /&gt;
 1    DROP       all  --  0.0.0.0/0            0.0.0.0/0           state INVALID&lt;br /&gt;
 2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED&lt;br /&gt;
 3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
 4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
 Chain FORWARD (policy DROP)&lt;br /&gt;
 num  target     prot opt source               destination&lt;br /&gt;
 1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
 2    DROP       all  --  0.0.0.0/0            0.0.0.0/0           state INVALID&lt;br /&gt;
 3    TCPMSS     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x02 TCPMSS clamp to PMTU&lt;br /&gt;
 4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED&lt;br /&gt;
 5    wanin      all  --  0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
 6    wanout     all  --  0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
 7    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0&lt;br /&gt;
 Chain OUTPUT (policy ACCEPT)&lt;br /&gt;
 num  target     prot opt source               destination&lt;br /&gt;
 Chain wanin (1 references)&lt;br /&gt;
 num  target     prot opt source               destination&lt;br /&gt;
 Chain wanout (1 references)&lt;br /&gt;
 num  target     prot opt source               destination&lt;br /&gt;
&lt;br /&gt;
You can use line numbers to delete or insert new rules into the firewall.&lt;br /&gt;
&lt;br /&gt;
''#1.2: To display INPUT or OUTPUT chain rules, enter:''&lt;br /&gt;
&lt;br /&gt;
 # iptables -L INPUT -n -v&lt;br /&gt;
 # iptables -L OUTPUT -n -v --line-numbers&lt;br /&gt;
 #2: Stop / Start / Restart the Firewall&lt;br /&gt;
 &lt;br /&gt;
If you are using CentOS / RHEL / Fedora Linux, enter:&lt;br /&gt;
 &lt;br /&gt;
 # service iptables stop&lt;br /&gt;
 # service iptables start&lt;br /&gt;
 # service iptables restart&lt;br /&gt;
&lt;br /&gt;
You can use the iptables command itself to stop the firewall and delete all rules:&lt;br /&gt;
&lt;br /&gt;
 # iptables -F&lt;br /&gt;
 # iptables -X&lt;br /&gt;
 # iptables -t nat -F&lt;br /&gt;
 # iptables -t nat -X&lt;br /&gt;
 # iptables -t mangle -F&lt;br /&gt;
 # iptables -t mangle -X&lt;br /&gt;
 # iptables -P INPUT ACCEPT&lt;br /&gt;
 # iptables -P OUTPUT ACCEPT&lt;br /&gt;
 # iptables -P FORWARD ACCEPT&lt;br /&gt;
&lt;br /&gt;
Where,&lt;br /&gt;
    -F : Deleting (flushing) all the rules.&lt;br /&gt;
    -X : Delete chain.&lt;br /&gt;
    -t table_name : Select table (called nat or mangle) and delete/flush rules.&lt;br /&gt;
    -P : Set the default policy (such as DROP, REJECT, or ACCEPT).&lt;br /&gt;
&lt;br /&gt;
#3: Delete Firewall Rules&lt;br /&gt;
&lt;br /&gt;
To display line number along with other information for existing rules, enter:&lt;br /&gt;
# iptables -L INPUT -n --line-numbers&lt;br /&gt;
# iptables -L OUTPUT -n --line-numbers&lt;br /&gt;
# iptables -L OUTPUT -n --line-numbers | less&lt;br /&gt;
# iptables -L OUTPUT -n --line-numbers | grep 202.54.1.1&lt;br /&gt;
You will get the list of IP. Look at the number on the left, then use number to delete it. For example delete line number 4, enter:&lt;br /&gt;
# iptables -D INPUT 4&lt;br /&gt;
OR find source IP 202.54.1.1 and delete from rule:&lt;br /&gt;
# iptables -D INPUT -s 202.54.1.1 -j DROP&lt;br /&gt;
Where,&lt;br /&gt;
&lt;br /&gt;
    -D : Delete one or more rules from the selected chain&lt;br /&gt;
&lt;br /&gt;
#4: Insert Firewall Rules&lt;br /&gt;
&lt;br /&gt;
To insert one or more rules in the selected chain as the given rule number use the following syntax. First find out line numbers, enter:&lt;br /&gt;
# iptables -L INPUT -n --line-numbers&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
Chain INPUT (policy DROP)&lt;br /&gt;
num  target     prot opt source               destination&lt;br /&gt;
1    DROP       all  --  202.54.1.1           0.0.0.0/0&lt;br /&gt;
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state NEW,ESTABLISHED &lt;br /&gt;
&lt;br /&gt;
To insert rule between 1 and 2, enter:&lt;br /&gt;
# iptables -I INPUT 2 -s 202.54.1.2 -j DROP&lt;br /&gt;
To view updated rules, enter:&lt;br /&gt;
# iptables -L INPUT -n --line-numbers&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
Chain INPUT (policy DROP)&lt;br /&gt;
num  target     prot opt source               destination&lt;br /&gt;
1    DROP       all  --  202.54.1.1           0.0.0.0/0&lt;br /&gt;
2    DROP       all  --  202.54.1.2           0.0.0.0/0&lt;br /&gt;
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state NEW,ESTABLISHED&lt;br /&gt;
&lt;br /&gt;
#5: Save Firewall Rules&lt;br /&gt;
&lt;br /&gt;
To save firewall rules under CentOS / RHEL / Fedora Linux, enter:&lt;br /&gt;
# service iptables save&lt;br /&gt;
In this example, drop an IP and save firewall rules:&lt;br /&gt;
# iptables -A INPUT -s 202.5.4.1 -j DROP&lt;br /&gt;
# service iptables save&lt;br /&gt;
For all other distros use the iptables-save command:&lt;br /&gt;
# iptables-save &amp;gt; /root/my.active.firewall.rules&lt;br /&gt;
# cat /root/my.active.firewall.rules&lt;br /&gt;
#6: Restore Firewall Rules&lt;br /&gt;
&lt;br /&gt;
To restore firewall rules form a file called /root/my.active.firewall.rules, enter:&lt;br /&gt;
# iptables-restore &amp;lt; /root/my.active.firewall.rules&lt;br /&gt;
To restore firewall rules under CentOS / RHEL / Fedora Linux, enter:&lt;br /&gt;
# service iptables restart&lt;br /&gt;
#7: Set the Default Firewall Policies&lt;br /&gt;
&lt;br /&gt;
To drop all traffic:&lt;br /&gt;
# iptables -P INPUT DROP&lt;br /&gt;
# iptables -P OUTPUT DROP&lt;br /&gt;
# iptables -P FORWARD DROP&lt;br /&gt;
# iptables -L -v -n&lt;br /&gt;
#### you will not able to connect anywhere as all traffic is dropped ###&lt;br /&gt;
# ping cyberciti.biz&lt;br /&gt;
# wget http://www.kernel.org/pub/linux/kernel/v3.0/testing/linux-3.2-rc5.tar.bz2&lt;br /&gt;
#7.1: Only Block Incoming Traffic&lt;br /&gt;
&lt;br /&gt;
To drop all incoming / forwarded packets, but allow outgoing traffic, enter:&lt;br /&gt;
# iptables -P INPUT DROP&lt;br /&gt;
# iptables -P FORWARD DROP&lt;br /&gt;
# iptables -P OUTPUT ACCEPT&lt;br /&gt;
# iptables -A INPUT -m state --state NEW,ESTABLISHED -j ACCEPT&lt;br /&gt;
# iptables -L -v -n&lt;br /&gt;
### *** now ping and wget should work *** ###&lt;br /&gt;
# ping cyberciti.biz&lt;br /&gt;
# wget http://www.kernel.org/pub/linux/kernel/v3.0/testing/linux-3.2-rc5.tar.bz2&lt;br /&gt;
#8:Drop Private Network Address On Public Interface&lt;br /&gt;
&lt;br /&gt;
IP spoofing is nothing but to stop the following IPv4 address ranges for private networks on your public interfaces. Packets with non-routable source addresses should be rejected using the following syntax:&lt;br /&gt;
# iptables -A INPUT -i eth1 -s 192.168.0.0/24 -j DROP&lt;br /&gt;
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP&lt;br /&gt;
#8.1: IPv4 Address Ranges For Private Networks (make sure you block them on public interface)&lt;br /&gt;
&lt;br /&gt;
    10.0.0.0/8 -j (A)&lt;br /&gt;
    172.16.0.0/12 (B)&lt;br /&gt;
    192.168.0.0/16 (C)&lt;br /&gt;
    224.0.0.0/4 (MULTICAST D)&lt;br /&gt;
    240.0.0.0/5 (E)&lt;br /&gt;
    127.0.0.0/8 (LOOPBACK)&lt;br /&gt;
&lt;br /&gt;
#9: Blocking an IP Address (BLOCK IP)&lt;br /&gt;
&lt;br /&gt;
To block an attackers ip address called 1.2.3.4, enter:&lt;br /&gt;
# iptables -A INPUT -s 1.2.3.4 -j DROP&lt;br /&gt;
# iptables -A INPUT -s 192.168.0.0/24 -j DROP&lt;br /&gt;
#10: Block Incoming Port Requests (BLOCK PORT)&lt;br /&gt;
&lt;br /&gt;
To block all service requests on port 80, enter:&lt;br /&gt;
# iptables -A INPUT -p tcp --dport 80 -j DROP&lt;br /&gt;
# iptables -A INPUT -i eth1 -p tcp --dport 80 -j DROP&lt;br /&gt;
&lt;br /&gt;
To block port 80 only for an ip address 1.2.3.4, enter:&lt;br /&gt;
# iptables -A INPUT -p tcp -s 1.2.3.4 --dport 80 -j DROP&lt;br /&gt;
# iptables -A INPUT -i eth1 -p tcp -s 192.168.1.0/24 --dport 80 -j DROP&lt;br /&gt;
#11: Block Outgoing IP Address&lt;br /&gt;
&lt;br /&gt;
To block outgoing traffic to a particular host or domain such as cyberciti.biz, enter:&lt;br /&gt;
# host -t a cyberciti.biz&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
cyberciti.biz has address 75.126.153.206&lt;br /&gt;
&lt;br /&gt;
Note down its ip address and type the following to block all outgoing traffic to 75.126.153.206:&lt;br /&gt;
# iptables -A OUTPUT -d 75.126.153.206 -j DROP&lt;br /&gt;
You can use a subnet as follows:&lt;br /&gt;
# iptables -A OUTPUT -d 192.168.1.0/24 -j DROP&lt;br /&gt;
# iptables -A OUTPUT -o eth1 -d 192.168.1.0/24 -j DROP&lt;br /&gt;
#11.1: Example - Block Facebook.com Domain&lt;br /&gt;
&lt;br /&gt;
First, find out all ip address of facebook.com, enter:&lt;br /&gt;
# host -t a www.facebook.com&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
www.facebook.com has address 69.171.228.40&lt;br /&gt;
&lt;br /&gt;
Find CIDR for 69.171.228.40, enter:&lt;br /&gt;
# whois 69.171.228.40 | grep CIDR&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
CIDR:           69.171.224.0/19&lt;br /&gt;
&lt;br /&gt;
To prevent outgoing access to www.facebook.com, enter:&lt;br /&gt;
# iptables -A OUTPUT -p tcp -d 69.171.224.0/19 -j DROP&lt;br /&gt;
You can also use domain name, enter:&lt;br /&gt;
# iptables -A OUTPUT -p tcp -d www.facebook.com -j DROP&lt;br /&gt;
# iptables -A OUTPUT -p tcp -d facebook.com -j DROP&lt;br /&gt;
&lt;br /&gt;
From the iptables man page:&lt;br /&gt;
&lt;br /&gt;
    ... specifying any name to be resolved with a remote query such as DNS (e.g., facebook.com is a really bad idea), a network IP address (with /mask), or a plain IP address ...&lt;br /&gt;
&lt;br /&gt;
#12: Log and Drop Packets&lt;br /&gt;
&lt;br /&gt;
Type the following to log and block IP spoofing on public interface called eth1&lt;br /&gt;
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j LOG --log-prefix &amp;quot;IP_SPOOF A: &amp;quot;&lt;br /&gt;
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP&lt;br /&gt;
By default everything is logged to /var/log/messages file.&lt;br /&gt;
# tail -f /var/log/messages&lt;br /&gt;
# grep --color 'IP SPOOF' /var/log/messages&lt;br /&gt;
#13: Log and Drop Packets with Limited Number of Log Entries&lt;br /&gt;
&lt;br /&gt;
The -m limit module can limit the number of log entries created per time. This is used to prevent flooding your log file. To log and drop spoofing per 5 minutes, in bursts of at most 7 entries .&lt;br /&gt;
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -m limit --limit 5/m --limit-burst 7 -j LOG --log-prefix &amp;quot;IP_SPOOF A: &amp;quot;&lt;br /&gt;
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP&lt;br /&gt;
#14: Drop or Accept Traffic From Mac Address&lt;br /&gt;
&lt;br /&gt;
Use the following syntax:&lt;br /&gt;
# iptables -A INPUT -m mac --mac-source 00:0F:EA:91:04:08 -j DROP&lt;br /&gt;
## *only accept traffic for TCP port # 8080 from mac 00:0F:EA:91:04:07 * ##&lt;br /&gt;
# iptables -A INPUT -p tcp --destination-port 22 -m mac --mac-source 00:0F:EA:91:04:07 -j ACCEPT&lt;br /&gt;
#15: Block or Allow ICMP Ping Request&lt;br /&gt;
&lt;br /&gt;
Type the following command to block ICMP ping requests:&lt;br /&gt;
# iptables -A INPUT -p icmp --icmp-type echo-request -j DROP&lt;br /&gt;
# iptables -A INPUT -i eth1 -p icmp --icmp-type echo-request -j DROP&lt;br /&gt;
Ping responses can also be limited to certain networks or hosts:&lt;br /&gt;
# iptables -A INPUT -s 192.168.1.0/24 -p icmp --icmp-type echo-request -j ACCEPT&lt;br /&gt;
The following only accepts limited type of ICMP requests:&lt;br /&gt;
### ** assumed that default INPUT policy set to DROP ** #############&lt;br /&gt;
iptables -A INPUT -p icmp --icmp-type echo-reply -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;
## ** all our server to respond to pings ** ##&lt;br /&gt;
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT&lt;br /&gt;
#16: Open Range of Ports&lt;br /&gt;
&lt;br /&gt;
Use the following syntax to open a range of ports:&lt;br /&gt;
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 7000:7010 -j ACCEPT&lt;br /&gt;
#17: Open Range of IP Addresses&lt;br /&gt;
&lt;br /&gt;
Use the following syntax to open a range of IP address:&lt;br /&gt;
## only accept connection to tcp port 80 (Apache) if ip is between 192.168.1.100 and 192.168.1.200 ##&lt;br /&gt;
iptables -A INPUT -p tcp --destination-port 80 -m iprange --src-range 192.168.1.100-192.168.1.200 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
## nat example ##&lt;br /&gt;
iptables -t nat -A POSTROUTING -j SNAT --to-source 192.168.1.20-192.168.1.25&lt;br /&gt;
#18: Established Connections and Restaring The Firewall&lt;br /&gt;
&lt;br /&gt;
When you restart the iptables service it will drop established connections as it unload modules from the system under RHEL / Fedora / CentOS Linux. Edit, /etc/sysconfig/iptables-config and set IPTABLES_MODULES_UNLOAD as follows:&lt;br /&gt;
&lt;br /&gt;
IPTABLES_MODULES_UNLOAD = no&lt;br /&gt;
&lt;br /&gt;
#19: Help Iptables Flooding My Server Screen&lt;br /&gt;
&lt;br /&gt;
Use the crit log level to send messages to a log file instead of console:&lt;br /&gt;
iptables -A INPUT -s 1.2.3.4 -p tcp --destination-port 80 -j LOG --log-level crit&lt;br /&gt;
#20: Block or Open Common Ports&lt;br /&gt;
&lt;br /&gt;
The following shows syntax for opening and closing common TCP and UDP ports:&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
Replace ACCEPT with DROP to block port:&lt;br /&gt;
## open port ssh tcp port 22 ##&lt;br /&gt;
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT&lt;br /&gt;
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
## open cups (printing service) udp/tcp port 631 for LAN users ##&lt;br /&gt;
iptables -A INPUT -s 192.168.1.0/24 -p udp -m udp --dport 631 -j ACCEPT&lt;br /&gt;
iptables -A INPUT -s 192.168.1.0/24 -p tcp -m tcp --dport 631 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
## allow time sync via NTP for lan users (open udp port 123) ##&lt;br /&gt;
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p udp --dport 123 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
## open tcp port 25 (smtp) for all ##&lt;br /&gt;
iptables -A INPUT -m state --state NEW -p tcp --dport 25 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
# open dns server ports for all ##&lt;br /&gt;
iptables -A INPUT -m state --state NEW -p udp --dport 53 -j ACCEPT&lt;br /&gt;
iptables -A INPUT -m state --state NEW -p tcp --dport 53 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
## open http/https (Apache) server port to all ##&lt;br /&gt;
iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT&lt;br /&gt;
iptables -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
## open tcp port 110 (pop3) for all ##&lt;br /&gt;
iptables -A INPUT -m state --state NEW -p tcp --dport 110 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
## open tcp port 143 (imap) for all ##&lt;br /&gt;
iptables -A INPUT -m state --state NEW -p tcp --dport 143 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
## open access to Samba file server for lan users only ##&lt;br /&gt;
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 137 -j ACCEPT&lt;br /&gt;
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 138 -j ACCEPT&lt;br /&gt;
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 139 -j ACCEPT&lt;br /&gt;
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 445 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
## open access to proxy server for lan users only ##&lt;br /&gt;
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 3128 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
## open access to mysql server for lan users only ##&lt;br /&gt;
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
#21: Restrict the Number of Parallel Connections To a Server Per Client IP&lt;br /&gt;
&lt;br /&gt;
You can use connlimit module to put such restrictions. To allow 3 ssh connections per client host, enter:&lt;br /&gt;
# iptables -A INPUT -p tcp --syn --dport 22 -m connlimit --connlimit-above 3 -j REJECT&lt;br /&gt;
&lt;br /&gt;
Set HTTP requests to 20:&lt;br /&gt;
# iptables -p tcp --syn --dport 80 -m connlimit --connlimit-above 20 --connlimit-mask 24 -j DROP&lt;br /&gt;
Where,&lt;br /&gt;
&lt;br /&gt;
    --connlimit-above 3 : Match if the number of existing connections is above 3.&lt;br /&gt;
    --connlimit-mask 24 : Group hosts using the prefix length. For IPv4, this must be a number between (including) 0 and 32.&lt;br /&gt;
&lt;br /&gt;
#22: HowTO: Use iptables Like a Pro&lt;br /&gt;
&lt;br /&gt;
For more information about iptables, please see the manual page by typing man iptables from the command line:&lt;br /&gt;
$ man iptables&lt;br /&gt;
You can see the help using the following syntax too:&lt;br /&gt;
# iptables -h&lt;br /&gt;
To see help with specific commands and targets, enter:&lt;br /&gt;
# iptables -j DROP -h&lt;br /&gt;
#22.1: Testing Your Firewall&lt;br /&gt;
&lt;br /&gt;
Find out if ports are open or not, enter:&lt;br /&gt;
# netstat -tulpn&lt;br /&gt;
Find out if tcp port 80 open or not, enter:&lt;br /&gt;
# netstat -tulpn | grep :80&lt;br /&gt;
If port 80 is not open, start the Apache, enter:&lt;br /&gt;
# service httpd start&lt;br /&gt;
Make sure iptables allowing access to the port 80:&lt;br /&gt;
# iptables -L INPUT -v -n | grep 80&lt;br /&gt;
Otherwise open port 80 using the iptables for all users:&lt;br /&gt;
# iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT&lt;br /&gt;
# service iptables save&lt;br /&gt;
Use the telnet command to see if firewall allows to connect to port 80:&lt;br /&gt;
$ telnet www.cyberciti.biz 80&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
Trying 75.126.153.206...&lt;br /&gt;
Connected to www.cyberciti.biz.&lt;br /&gt;
Escape character is '^]'.&lt;br /&gt;
^]&lt;br /&gt;
telnet&amp;gt; quit&lt;br /&gt;
Connection closed.&lt;br /&gt;
&lt;br /&gt;
You can use nmap to probe your own server using the following syntax:&lt;br /&gt;
$ nmap -sS -p 80 www.cyberciti.biz&lt;br /&gt;
Sample outputs:&lt;br /&gt;
&lt;br /&gt;
Starting Nmap 5.00 ( http://nmap.org ) at 2011-12-13 13:19 IST&lt;br /&gt;
Interesting ports on www.cyberciti.biz (75.126.153.206):&lt;br /&gt;
PORT   STATE SERVICE&lt;br /&gt;
80/tcp open  http&lt;br /&gt;
Nmap done: 1 IP address (1 host up) scanned in 1.00 seconds&lt;br /&gt;
&lt;br /&gt;
I also recommend you install and use sniffer such as tcpdupm and ngrep to test your firewall settings.&lt;/div&gt;</summary>
		<author><name>Award</name></author>
	</entry>
</feed>