Wednesday, 2 January 2013

IP Filtering in Linux Based Firewall


IP Filtering in Linux Firewall

IP filtering is simply a mechanism that decides which types of IP datagrams will be processed normally and which will be discarded. By discarded we mean that the datagram is deleted and completely ignored, as if it had never been received. You can apply many different sorts of criteria to determine which datagrams you wish to filter; some examples of these are:
  • Protocol type: TCP, UDP, ICMP, etc.
  • Socket number (for TCP/UPD)
  • Datagram type: SYN/ACK, data, ICMP Echo Request, etc.
  • Datagram source address: where it came from
  • Datagram destination address: where it is going to
It is important to understand at this point that IP filtering is a network layer facility. This means it doesn't understand anything about the application using the network connections, only about the connections themselves. For example, you may deny users access to your internal network on the default telnet port, but if you rely on IP filtering alone, you can't stop them from using the telnet program with a port that you do allow to pass through your firewall. You can prevent this sort of problem by using proxy servers for each service that you allow across your firewall. The proxy servers understand the application they were designed to proxy and can therefore prevent abuses, such as using the telnet program to get past a firewall by using the World Wide Web port. If your firewall supports a World Wide Web proxy, their telnet connection will always be answered by the proxy and will allow only HTTP requests to pass. A large number of proxy-server programs exist. Some are free software and many others are commercial products.
The IP filtering rule set is made up of many combinations of the criteria listed previously. For example, let's imagine that you wanted to allow World Wide Web users within the Virtual Brewery network to have no access to the Internet except to use other sites' web servers. You would configure your firewall to allow forwarding of:
  • datagrams with a source address on Virtual Brewery network, a destination address of anywhere, and with a destination port of 80 (WWW)
  • datagrams with a destination address of Virtual Brewery network and a source port of 80 (WWW) from a source address of anywhere
Note that we've used two rules here. We have to allow our data to go out, but also the corresponding reply data to come back in. In practice, as we'll see shortly, Linux simplifies this and allows us to specify this in one command

Three Ways to Do IP Filtering:-

  • The IP datagram is received. 
  • The incoming IP datagram is examined to determine if it is destined for a process on this machine.
  • If the datagram is for this machine, it is processed locally.
  • If it is not destined for this machine, a search is made of the routing table for an appropriate route and the datagram is forwarded to the appropriate interface or dropped if no route can be found.
  • Datagrams from local processes are sent to the routing software for forwarding to the appropriate interface. 
  • The outgoing IP datagram is examined to determine if there is a valid route for it to take, if not, it is dropped.
  • The IP datagram is transmitted. 
In our diagram, the flow 1 3 5 represents our machine routing data between a host on our Ethernet network to a host reachable via our PPP link. The flows 1 2 and 4 5 represent the data input and output flows of a network program running on our local host. The flow 4 3 2 would represent data flow via a loopback connection. Naturally data flows both into and out of network devices. The question marks on the diagram represent the points where the IP layer makes routing decisions.
The Linux kernel IP firewall is capable of applying filtering at various stages in this process. That is, you can filter the IP datagrams that come in to your machine, filter those datagrams being forwarded across your machine, and filter those datagrams that are ready to be transmitted.
In ipfwadm and ipchains, an Input rule applies to flow 1 on the diagram, a Forwarding rule to flow 3, and an Output rule to flow 5. We'll see when we discuss netfilter later that the points of interception have changed so that an Input rule is applied at flow 2, and an Output rule is applied at flow 4. This has important implications for how you structure your rulesets, but the general principle holds true for all versions of Linux firewalling.

No comments:

Post a Comment