The much known word to most of the developer when they deal with firewall is IpTables. It allows a system administrator to configure the tables provided by the Linux kernel firewall which is implemented by different Netfilter modules and the chains and rules it stores. Netfilter is a set of hooks inside the Linux kernel that allows kernel modules to register callback functions with the network stack. Different kernel modules and programs are currently used for different protocols; iptables applies to IPv4, ip6tables to IPv6, arptables to ARP, and for special Ethernet frames used ebtables. It is normally a user space application program with integrated full featured Ip control.
Iptables is a generic table arrangement for the definition of rulesets. Each rule within an IP table consists of a number of classifiers (iptables matches) and one linked action (iptables target). Iptables has widespread documentation that can be accessed online or by typing man iptables
at the command line. Yet despite the depth of the documentation available for iptables, its density can be mysterious.
Here I am recommend you to use some tools by using those you can create your own suited IpTables so easily.
FireHOL it allows you to configure iptables through its abstract, extensible configuration language, enabling you to write your configuration in something approaching a fourth-generation programming language.
You can download from SourceForge.
Guarddog is a GUI-based iptables configurator for KDE. Like FireHOL, Guarddog is application- and protocol-based, but unlike FireHOL Guarddog provides extensive guidance on which protocols to allow and disallow both through its documentation and through the GUI itself.
Easy Firewall Generator Easy Firewall generator works through a simple Web-based interface to generate a basic firewall script for iptables.
There are many iptables configuration tools you can find on web by those you can apply your own logic and preferences in that configuration