IPTables

From WBITT's Cooker!

(Difference between revisions)
Jump to: navigation, search
(What we would cover in this document?)
Line 34: Line 34:
We would also cover the basic principles to follow, to protect your computers/services/data.
We would also cover the basic principles to follow, to protect your computers/services/data.
 +
==Basic Principles for protection==
 +
When trying to achieve the goal of "Maximum Security" or "Maximum Protection" for your IT assets, remember; IPTables, or any firewall for that matter, is just one small component. In other words, any firewall (software, or hardware), is not a magic wand. Merely placing a firewall on your server, or between your users and the internet, does not guarantee that the assets you are trying to protect, are actually protected. There are other areas to pay attention, in parallel to setting up / placing a firewall. The following principles must always be a part of your IT Security Policy, to achieve the goal of "Maximum Security" or "Maximum Protection".
 +
 +
* Install the least amount of packages/software on the servers. The goal should be to only install software which is related to the service offered by this server. For example, in case of a web server serving web pages generated by PHP, on the data stored in a MySQL database, you should install the minimal OS, and Apache Web Server, PHP, and MySQL database software on top of it. As you do not expect anyone to print any documents from the web server placed half the world away, there is no sense in having CUPS (Common Unix Printing System) service running on it. It would also be totally useless to have office suite, or multimedia related packages, or desktop/window managers on this server.
 +
 +
 +
 +
This is not a definitive list, but should give you a clear idea.
==References==
==References==

Revision as of 08:15, 27 February 2011

Alternate Title: "Understanding IPTables"

Author: Muhammad Kamran Azeem [CISSP, RHCE, OCP (DBA), CCNA] (http://wbitt.com , http://techsnail.com)

E-mail: kamran at wbitt dot com

Created: 27 Feb 2011

Updated: (Please see the footer area of this document for this information.)

Category: Firewall, Security

License: Copyright (c) 2011 by Muhammad Kamran Azeem. Permission to copy, distribute (sell or give-away) and translate, provided you retain the name of the original author.

Synopsis: This paper, explains the Linux default firewall, the IPTables.

Contents

Purpose of this document

Although, several extremely good articles already exist on the topic of IPTables, there was a popular demand for a CBT on this topic. The CBT definitely needed a text to follow, and thus this article was born. It should be noted that this document is for a beginner, for whom too much of information is confusing. Therefore, this document addresses basic concepts and mechanisms. If you are looking for a detailed discussion/explanation of TCP/IP protocol stack, TCP/IP headers, in relation to various moving parts of the entire iptables/netfilter mechanism, etc; you should read the latest version of "Iptables Tutorial by Oskar Andreasson", which is one of the finest documents on IPTables till date. You should also check "Rusty's Remarkably Unreliable Guides". Rusty Russell, was the person, who actually wrote (most of the) IPChains and IPTables code.

Introduction

IPTables is the mechanism for packet "Filter"-ing, in modern Linux distributions. In addition to packet filtering, it also does other interesting things such as "NAT"-ing and "Mangle"-ing. To be more specific, IPTables (originally from the NetFileter project), is the user-land application, which is used to manage/configure various packet handling "tables" provided in the Linux kernel (Linux Kernel Firewall). Each table has certain "chains" in it, and each chain has certain "rules", against which each packet is evaluated. IPTables is the default packet handling application in 2.4 and 2.6 series kernels. In 2.2 series kernels the application was "IPChains"; and in 2.0 series kernel, it was "IPFWAdm".

In addition to looking at the source and destination IP addresses and ports, IPTables also has the ability to monitor the "state" of the packet. This makes iptables also work as a "stateful" firewall. In other words, it also does connection tracking. A stateful firewall can check context of the packet, to evaluate if it is a NEW packet, a packet related to a previous communication, or a packet from an already ESTABLISHED communication, etc. It can also inspect, and take action on, various TCP flags in a packet header, such as SYN, ACK, FIN, etc.

Note: We would be using the word "iptables" in lower case. It is same as "IPTables", or "IP Tables".

You may be encountering the term/word "NetFilter", whenever you are reading any text related to IPTables. Netfilter and iptables were initially designed together, in 1998, so there is some overlap in early history. It might also be interesting to note, that the Netfilter maintainer Patrick McHardy has proposed to replace iptables with nftables in the future. The project is currently in the alpha stage of development.

What we would cover in this document?

We would be covering two most common scenarios, which are:

  • Protecting Internet servers
  • Protecting LANs connected to the internet

We would also cover the basic principles to follow, to protect your computers/services/data.

Basic Principles for protection

When trying to achieve the goal of "Maximum Security" or "Maximum Protection" for your IT assets, remember; IPTables, or any firewall for that matter, is just one small component. In other words, any firewall (software, or hardware), is not a magic wand. Merely placing a firewall on your server, or between your users and the internet, does not guarantee that the assets you are trying to protect, are actually protected. There are other areas to pay attention, in parallel to setting up / placing a firewall. The following principles must always be a part of your IT Security Policy, to achieve the goal of "Maximum Security" or "Maximum Protection".

  • Install the least amount of packages/software on the servers. The goal should be to only install software which is related to the service offered by this server. For example, in case of a web server serving web pages generated by PHP, on the data stored in a MySQL database, you should install the minimal OS, and Apache Web Server, PHP, and MySQL database software on top of it. As you do not expect anyone to print any documents from the web server placed half the world away, there is no sense in having CUPS (Common Unix Printing System) service running on it. It would also be totally useless to have office suite, or multimedia related packages, or desktop/window managers on this server.


This is not a definitive list, but should give you a clear idea.

References

Personal tools