Project: A Simple Packet-Filtering Firewall
This section steps you through building a very simple firewall with netfilter using iptables. This firewall is not recommended for use as-is. You'll need to determine if this is what you need. But it does give you a good idea about how to plan and implement a simple firewall, including how to write the iptables rules. In the real world, it's just not this easy; this is only a chapter, although it deserves a book. Much of this is contrived to demonstrate rules and give you an idea what you can do.
To begin, you'll need to know something about the network from which you're connecting, and about the network to which you're connecting. The following assumptions are valid for the rest of this section: