<?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>Linux, Programming, Telephony, Asterisk, Apache, Tips &#38; Tricks &#187; Iptables</title>
	<atom:link href="http://shahidz.com/category/iptables/feed/" rel="self" type="application/rss+xml" />
	<link>http://shahidz.com</link>
	<description>Passionate About Technology</description>
	<lastBuildDate>Sun, 10 Jan 2010 17:38:11 +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>ufw &#8211; Uncomplicated Firewall</title>
		<link>http://shahidz.com/ufw-uncomplicated-firewall/</link>
		<comments>http://shahidz.com/ufw-uncomplicated-firewall/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 16:12:17 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Iptables]]></category>
		<category><![CDATA[Linux Commands]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[ufw]]></category>

		<guid isPermaLink="false">http://shahidz.com/ufw-uncomplicated-firewall/</guid>
		<description><![CDATA[Description
ufw is stands for Uncomplicated Firewall, this program is for managing a Linux firewall and aims to provide an easy to use interface for the user, as well as support package integration and dynamic-detection of open ports. ufw  is not intended to provide complete firewall functionality via its command interface, but instead provides an easy [...]]]></description>
			<content:encoded><![CDATA[<h3>Description</h3>
<p align="justify">ufw is stands for Uncomplicated Firewall, this program is for managing a Linux firewall and aims to provide an easy to use interface for the user, as well as support package integration and dynamic-detection of open ports. ufw  is not intended to provide complete firewall functionality via its command interface, but instead provides an easy way to  add  or  remove simple rules. It is currently mainly used for host-based firewalls.</p>
<h3 align="justify">Installation</h3>
<pre>$ sudo apt-get install ufw</pre>
<p>For help use</p>
<pre>$ man ufw</pre>
<p>To enable firewall</p>
<pre>$ sudo ufw enable</pre>
<p>When we enable the firewall it will set firewall with default settings, it will deny ssh ports, telnet and many other services. So when we enable firewall on the remort servers we must enable ssh ports first, this can done using.</p>
<pre>$ ufw allow proto tcp from any to any port 22</pre>
<p>To disable a firewall</p>
<pre>$ sudo sfw disable</pre>
<p>Examples</p>
<p>Deny all access to port 53:</p>
<pre>$ sudo ufw deny 53</pre>
<p>Allow all access to tcp port 80:</p>
<pre>$ sudo ufw allow 80/tcp</pre>
<p>Allow all access from RFC1918 networks to this host:</p>
<pre>$ sudo ufw allow from 10.0.0.0/8
$ sudo ufw allow from 172.16.0.0/12
$ sudo ufw allow from 192.168.0.0/16</pre>
<p>Deny access to udp port 514 from host 1.2.3.4:</p>
<pre>$ sudo ufw deny proto udp from 1.2.3.4 to any port 514</pre>
<p>Allow access to udp 1.2.3.4 port 5469 from 1.2.3.5 port 5469:</p>
<pre>$ sudo ufw allow proto udp from 1.2.3.5 port 5469 to 1.2.3.4 port 5469</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Fufw-uncomplicated-firewall%2F&amp;linkname=ufw%20%26%238211%3B%20Uncomplicated%20Firewall"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/ufw-uncomplicated-firewall/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iptables port forwarding on ubuntu</title>
		<link>http://shahidz.com/iptables-port-forwarding-on-ubuntu/</link>
		<comments>http://shahidz.com/iptables-port-forwarding-on-ubuntu/#comments</comments>
		<pubDate>Sun, 27 Jul 2008 05:31:52 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Iptables]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Securities]]></category>
		<category><![CDATA[port forwarding]]></category>

		<guid isPermaLink="false">http://shahidz.com/iptables-port-forwarding-on-ubuntu/</guid>
		<description><![CDATA[What is Port Forwarding?
Port forwarding is a feature of the IPTables system.  It allows one computer to forward connections made to it so that another computer can actually process the request.  If you want a very simple metaphor you can think of it as mail forwarding.  Each computer has a number of [...]]]></description>
			<content:encoded><![CDATA[<h3>What is Port Forwarding?</h3>
<p align="justify">Port forwarding is a feature of the IPTables system.  It allows one computer to forward connections made to it so that another computer can actually process the request.  If you want a very simple metaphor you can think of it as mail forwarding.  Each computer has a number of addresses called ports, and IPTables allows connections to these ports to be sent to another computer. With port forwarders, you can redirect data connections from the Internet to  an internal, privately addressed machine behind your IP MASQ server.  This  forwarding ability includes network protocols such as TELNET, WWW, and SMTP.  Protocols such as FTP, legacy ICQ, and others require special handling via kernel modules.</p>
<h3 align="justify">Setup</h3>
<p>On Ubuntu you need to enable port forwarding. For doing this you have to be the root user.</p>
<pre>root@shahid-laptop:~# echo 1 &gt; /proc/sys/net/ipv4/ip_forward</pre>
<p>After this you need to write iptable rule.</p>
<pre>root@shahid-laptop:~# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
root@shahid-laptop:~# iptables -t nat -A PREROUTING -p tcp -i eth0 -d 192.168.0.10 --dport 555 -j DNAT --to 192.168.0.12:22
root@shahid-laptop:~# iptables -A FORWARD -p tcp -i eth0 -d 192.168.0.12 --dport 22 -j ACCEPT</pre>
<p align="justify">In this rule, when we tries to connect to the IP 192.168.0.10 through the port 555 this system redirects the connection to the IP and 192.168.0.12 and port 22.</p>
<p>To see the iptables rule use the command &#8216;iptables -L&#8217;</p>
<pre>root@shahid-laptop:~# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             192.168.0.12        tcp dpt:ssh 

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination</pre>
<h3>Saving Data</h3>
<p align="justify">When you reboot the system the iptables rules will be removed from the kernel module , so either you need to use <em>iptables-save</em> and <em>iptables-restore</em>for saving and restoring iptable rules or you need to write a script which will execut on every boot for enabling and create the iptable rule.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Fiptables-port-forwarding-on-ubuntu%2F&amp;linkname=iptables%20port%20forwarding%20on%20ubuntu"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/iptables-port-forwarding-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bandwidth Monitoring Using Iptables</title>
		<link>http://shahidz.com/bandwidth-monitoring-using-iptables/</link>
		<comments>http://shahidz.com/bandwidth-monitoring-using-iptables/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 09:56:13 +0000</pubDate>
		<dc:creator>Shahid</dc:creator>
				<category><![CDATA[Iptables]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bandwidth monitoring]]></category>

		<guid isPermaLink="false">http://shahidz.com/bandwidth-monitoring-using-iptables/</guid>
		<description><![CDATA[In Linux there has a number of useful bandwidth monitoring tools such as nload, netwatch, iftop, trafshow, bandwidthd, vnstat. If all you need is a basic overview of your total bandwidth usage, iptables is all you really need. Usually we use iptables for setting firewall and port forwardings, but iptables also provides packet and byte [...]]]></description>
			<content:encoded><![CDATA[<p>In Linux there has a number of useful bandwidth monitoring tools such as <strong>nload, netwatch, iftop, trafshow, bandwidthd, vnstat.</strong> If all you need is a basic overview of your total bandwidth usage, <a href="http://www.netfilter.org/">iptables</a> is all you really need. Usually we use iptables for setting firewall and port forwardings, but iptables also provides packet and byte counters.</p>
<h3>Writting iptables rules</h3>
<p>The IP addresses in this article are modified from the real addresses. We&#8217;ll use the private IP space 192.168.0.0/16, subnetted into smaller blocks.</p>
<p>In this example, the FORWARD chain will only provide the global counters.</p>
<pre>$ sudo iptables -N system-1</pre>
<p>The rule will match any source and any destination. Everything that is being passed through this router matches this rule and will provide the total of combined downloaded and uploaded data.</p>
<pre># System-1 Downloads
  iptables -A FORWARD -d 192.168.1.0/26 -j system-1
# System-1 Uploads
  iptables -A FORWARD -s 192.168.1.0/26 -j system-1</pre>
<p>The rules created above give us separate totals for all downloads to and uploads for system-1. This is accomplished by matching the source and destination of all traffic through the router for target-1&#8217;s specific subnet. After a rule is matched, the <code>-j</code> option invokes a jump to one of the custom chains. These custom chains can then be used to add additional rules pertaining to the subnet. For instance, rules can be created for each individual IP address in that subnet to track bandwidth on a per-host basis:</p>
<pre># Town A, Host 192.168.1.10 Download
  iptables -A town-a -d 192.168.1.10
# Town A, Host 192.168.1.10 Upload
  iptables -A town-a -s 192.168.1.10</pre>
<p>You could repeat this process for every IP address for all systems within the subnet.</p>
<h3>Bandwidth statistics</h3>
<p>Viewing the current bandwidth usage is a matter of running iptables with the <code>-L</code> and <code>-v</code> options. The <code>-L</code> outputs the statistics for a chain (or all chains if none is provided). The <code>-v</code> option provides verbose output, including the packet and byte counters that we are interested in. I recommend using the <code>-n</code> option as well to prevent DNS lookups, meaning iptables will show the IP addresses without attempting to resolve the hostnames for the IP addresses, which would put additional and unnecessary load on the router.</p>
<pre>$ sudo iptables -L -v -n
Chain INPUT (policy ACCEPT 311K packets, 48M bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 system-1   all  --  *      *       0.0.0.0/0            192.168.1.0/26
    0     0 system-1   all  --  *      *       192.168.1.0/26       0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 325K packets, 29M bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain system-1 (2 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0            all  --  *      *       0.0.0.0/0            192.168.1.10
    0     0            all  --  *      *       192.168.1.10         0.0.0.0/0</pre>
<h3>Saving data across reboots</h3>
<p>If you reboot the machine or remove the iptables kernel modules, you&#8217;ll lose all of your packet and byte counters. So you want to make backups of the running counters, and in the event of a reboot, restore the counters rather than starting from zero.</p>
<p>The iptables package comes with two programs that aid in this: <code>iptables-save</code> and <code>iptables-restore</code>. Both programs need to be told to explicitly use the packet and byte counters during backup and restore using the <code>-c</code> command line option.</p>
<p>The backup and restore process is fairly straightforward. To back up your iptables data, use</p>
<pre>$ sudo iptables-save -c &gt; iptables-backup.txt.</pre>
<p>To restore the data, after reboot, use <code></code></p>
<pre>$ sudo iptables-restore -c &lt; iptables-backup.txt.</pre>
<h3>Conclution</h3>
<p>The flexibility and power of iptables allows for more complex onitoring scenarios. You can create rules to not only track different subnets, but also to track specific ports and protocols, which lets you rack exactly how much of each customer&#8217;s traffic is Web, email, file<br />
sharing, etc.</p>
<p>In addition, these bandwidth monitoring rules can also become blocking rules. If a host has used too much bandwidth, its rule in a town&#8217;s specific chain can be modified by adding <code>-j DROP</code> to both the download and upload rules. This effectively stops traffic being routed to and from that host.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fshahidz.com%2Fbandwidth-monitoring-using-iptables%2F&amp;linkname=Bandwidth%20Monitoring%20Using%20Iptables"><img src="http://shahidz.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://shahidz.com/bandwidth-monitoring-using-iptables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
