Firewall

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 17:31, 16 May 2010 (edit)
Glenn (Talk | contribs)
(more)
← Previous diff
Current revision (16:51, 19 May 2010) (edit) (undo)
Glenn (Talk | contribs)
(DD-WRT firewall - iptables - small chg)
 
(27 intermediate revisions not shown.)
Line 1: Line 1:
-The purpose of the '''firewall''' is to moderate traffic and/or log it. Most firewall are made for moderating ip traffic and are called ip firewalls.+The purpose of the '''firewall''' is to moderate traffic and/or log it. Most firewall are made for moderating ip traffic and are called '''ip firewalls'''.
-The simplest '''ip firewall''' has two physical interfaces normally referred to as '''''inside''''' (LAN) and '''''outside''''' (WAN, the internet). It has two main access control lists e.g. named inside2outside and outside2inside.+The simplest ip firewall has two physical interfaces normally referred to as ''inside'' (LAN) and ''outside'' (WAN, the internet). It has two main access control lists (ACL) - e.g. named inside2outside and outside2inside.
===Packet filter firewall=== ===Packet filter firewall===
Line 12: Line 12:
===Statefull firewall=== ===Statefull firewall===
-The better ip firewall - a statefull firewall - can pass packet by packet - and if possible (e.g. tcp and údp) track the connection. A statefull firewall can additionally moderate trackable traffic by:+The better ip firewall - a statefull firewall - can pass packet by packet - and if possible (e.g. tcp and udp) track the connection. A statefull firewall can additionally moderate trackable traffic by:
* number of connections per (src/dst) ip address * number of connections per (src/dst) ip address
* number of connections per interface * number of connections per interface
Line 20: Line 20:
Due to IPv4 address shortage, the internet society began to use NAT, and therefore the firewall also need to be NAT aware. Due to IPv4 address shortage, the internet society began to use NAT, and therefore the firewall also need to be NAT aware.
-A real problem with NAT is when more than one inside clients (e.g. C1, C2) connect to the same outside server ip address (S) and the traffic is not tcp and udp. When an outside packet arrive at the NAT device it can not deduce which client to send it to. Here are examples of protocols that has problem:+====NAT incompatible protocols====
 +A real problem with NAT is when more than one inside clients (e.g. C1, C2) connect to the same outside server ip address (S) and the traffic is not tcp and udp. When a response outside packet later arrives at the NAT device (firewall), it can not deduce which client to send it to. Here are examples of protocols that has that problem:
*[[wikipedia:IPsec|IPsec]] (over [[wikipedia:List_of_IP_protocol_numbers|IP protocol]] 51) *[[wikipedia:IPsec|IPsec]] (over [[wikipedia:List_of_IP_protocol_numbers|IP protocol]] 51)
*[[wikipedia:PPTP|PPTP]] (over IP protocol 47) *[[wikipedia:PPTP|PPTP]] (over IP protocol 47)
*[[wikipedia:Layer 2 Tunneling Protocol|L2TP]] (over IP protocol 50) *[[wikipedia:Layer 2 Tunneling Protocol|L2TP]] (over IP protocol 50)
-Even if the traffic is unencrypted it can not be deduced where to NAT an incoming outside packet if more than one inside client uses that protocol to the same outside ip address. UDP and TCP are special because they have 65536 possible src and dst ports that can help tracking.+Even if the traffic is unencrypted it can not be deduced where to NAT a response outside packet, if more than one inside client uses the same protocol to the same outside ip address. UDP and TCP are special because they have 65536 possible src and dst ports that can help connection tracking.
-===Difficult protocols===+===Firewall difficult protocols===
-Some protocols can port jump and create connections one or both ways "at will". A firewall that can moderate that kind of traffic, need to inspect the traffic stream. To do that a firewall must have proxies.+Some protocols can in-line signal a port jump and/or create connections one or both ways "at will". A firewall that can moderate that kind of traffic, need to inspect the traffic stream. To do that a firewall must have [[wikipedia:Application_layer_firewall#Network-based_application_firewalls|transparent proxies]] and are then called an [[wikipedia:Application_layer_firewall|application firewall]].
-Some examples of protocols that can port jump and create additional connections are:+Some examples of protocols that can port jump and/or create additional connections are:
-*FTP+*FTP passive
 +*FTP active - if you enable proxy support for active FTP, you firewall can be "punctured" from the internet and is therefore almost useless.
*Media streams (Media Player, iTunes...): *Media streams (Media Player, iTunes...):
**RTSP **RTSP
Line 41: Line 43:
*Some gaming protocols *Some gaming protocols
-==DD-WRT==+==DD-WRT firewall - iptables==
-Your network device typically has more than two interfaces. DD-WRT has firewall, NAT, proxy functionality via netfilter with among others iptables.+DD-WRT has a packet filtering firewall, statefull firewall, NAT and proxy functionality.
The [[default internal device network]] has two networks (non-802.11n example!): The [[default internal device network]] has two networks (non-802.11n example!):
-*vlan0(built-in hardware switch) software-bridged with eth1(wireless access point) - LAN private ip subnet 192.168.1.0/24 and ip configurations are leased out by a DHCP server.+*vlan0(built-in hardware switch) software-bridged with eth1(wireless access point) - LAN private ip subnet 192.168.1.0/24 and ip configurations are leased to clients by a DHCP server.
-*vlan1 - WAN with some ip address normally acquired via a DHCP client.+*vlan1 - WAN with some ip configuration normally acquired via a DHCP client.
-There is a default ip firewall with NAT between vlan0 and vlan1 on non-802.11n network devices.+There is a default ip firewall with NAT between vlan0 and vlan1 (on non-802.11n) network devices.
 + 
 +See [[internal_device_network#Examples_of_changed_internal_network]] for other firewall examples.
 + 
 +===Netfilter iptables architecture===
 +*[http://www.sns.ias.edu/~jns/files/iptables_talk/x14.htm sns.ias.edu: Kernel space structure - simple packet journey through kernel]
 +**The left and right upper red arrows together, is the input and output of your network device logical [[:Category:Interfaces|network interface]]s (bridges=[[:Category:switch|switches]], - and [[wikipedia:Virtual_LAN|vlans]]). The five blue balls represent the default firewall chains hook points. The "local process" is your network device's [[wikipedia:Process (computing)|service process(es)]] - e.g. remote management ([[WEB server]], [[Telnet/SSH_and_the_Command_Line#Setting_Up|Telnet or SSH server]]), [[:Category:Samba|Samba server]], [[:Category:PPPOE|PPPoE client]], [[:Category:DHCP|DHCP server(s) or client]] and so on.
==See also== ==See also==
Line 56: Line 64:
==External links== ==External links==
*[http://blog.eukhost.com/webhosting/firewall/ Firewall] Generic and short: Purpose and processes. *[http://blog.eukhost.com/webhosting/firewall/ Firewall] Generic and short: Purpose and processes.
-*[http://www.sns.ias.edu/~jns/wp/category/linux/unix-security/iptables/ sns.ias.edu: Iptables]+*[http://www.sns.ias.edu/~jns/wp/category/linux/unix-security/iptables/ sns.ias.edu, James Stephens: Iptables]
-**[http://www.sns.ias.edu/~jns/files/iptables_talk/t1.htm IPTABLES - An Overview]+**[http://www.sns.ias.edu/~jns/files/iptables_talk/t1.htm IPTABLES - An Overview] - short and good - overheads.
-***[http://www.sns.ias.edu/~jns/files/iptables_talk/x14.htm Kernel space structure - simple packet journey through kernel] - Please note that the left and right upper red arrows together, is the input and output of your router box physical or logical [[:Category:Interfaces|network interface]] (bridge=[[:Category:switch|switch]] - or port). The local interface packet might be [[wikipedia:Virtual_LAN|vlan]] tagged. The five blue balls represent the default firewall chains hook points. The "local process" is in your router box - e.g. remote management ([[WEB server]], [[Telnet/SSH_and_the_Command_Line#Setting_Up|Telnet or SSH server]]), [[:Category:Samba|Samba server]], [[:Category:PPPOE|PPPoE client]], [[:Category:DHCP|DHCP server(s) or client]] and so on.+***[http://www.sns.ias.edu/~jns/files/iptables_talk/x14.htm Kernel space structure - simple packet journey through kernel] - Please note that the left and right upper red arrows together, is the input and output of your network device logical [[:Category:Interfaces|network interface]]s.
 +**Comprehensive and well documented NAT-less iptable and startup script:
 +***[http://www.sns.ias.edu/~jns/files/iptables_ruleset Iptables example ruleset]
 +***[http://www.sns.ias.edu/~jns/files/iptables_startup_script A simple accompanying startup script]
 +***[http://www.sns.ias.edu/~jns/files/iptables_ruleset_updated The updated ruleset may be downloaded]
*[[wikipedia:Netfilter]] *[[wikipedia:Netfilter]]
**[http://www.netfilter.org/documentation/ netfilter.org: Documentation about the netfilter/iptables project], [http://lists.netfilter.org/pipermail/netfilter/ lists] **[http://www.netfilter.org/documentation/ netfilter.org: Documentation about the netfilter/iptables project], [http://lists.netfilter.org/pipermail/netfilter/ lists]

Current revision

The purpose of the firewall is to moderate traffic and/or log it. Most firewall are made for moderating ip traffic and are called ip firewalls.

The simplest ip firewall has two physical interfaces normally referred to as inside (LAN) and outside (WAN, the internet). It has two main access control lists (ACL) - e.g. named inside2outside and outside2inside.

Contents

[edit] Packet filter firewall

The simplest ip firewall - a packet filter firewall - can pass packet by packet or drop them based on:

  • source ip address
  • destination ip address
  • If tcp or udp:
    • source tcp/udp port
    • destination tcp/udp port

[edit] Statefull firewall

The better ip firewall - a statefull firewall - can pass packet by packet - and if possible (e.g. tcp and udp) track the connection. A statefull firewall can additionally moderate trackable traffic by:

  • number of connections per (src/dst) ip address
  • number of connections per interface
  • number of connections attempt - "SYN"-attacks, packet storms

[edit] NAT - Network address Translation

Due to IPv4 address shortage, the internet society began to use NAT, and therefore the firewall also need to be NAT aware.

[edit] NAT incompatible protocols

A real problem with NAT is when more than one inside clients (e.g. C1, C2) connect to the same outside server ip address (S) and the traffic is not tcp and udp. When a response outside packet later arrives at the NAT device (firewall), it can not deduce which client to send it to. Here are examples of protocols that has that problem:

Even if the traffic is unencrypted it can not be deduced where to NAT a response outside packet, if more than one inside client uses the same protocol to the same outside ip address. UDP and TCP are special because they have 65536 possible src and dst ports that can help connection tracking.

[edit] Firewall difficult protocols

Some protocols can in-line signal a port jump and/or create connections one or both ways "at will". A firewall that can moderate that kind of traffic, need to inspect the traffic stream. To do that a firewall must have transparent proxies and are then called an application firewall.

Some examples of protocols that can port jump and/or create additional connections are:

  • FTP passive
  • FTP active - if you enable proxy support for active FTP, you firewall can be "punctured" from the internet and is therefore almost useless.
  • Media streams (Media Player, iTunes...):
    • RTSP
    • Realmedia
    • Conferencing
    • VoIP, IP telephony:
      • H323
      • SIP
  • Some gaming protocols

[edit] DD-WRT firewall - iptables

DD-WRT has a packet filtering firewall, statefull firewall, NAT and proxy functionality.

The default internal device network has two networks (non-802.11n example!):

  • vlan0(built-in hardware switch) software-bridged with eth1(wireless access point) - LAN private ip subnet 192.168.1.0/24 and ip configurations are leased to clients by a DHCP server.
  • vlan1 - WAN with some ip configuration normally acquired via a DHCP client.

There is a default ip firewall with NAT between vlan0 and vlan1 (on non-802.11n) network devices.

See internal_device_network#Examples_of_changed_internal_network for other firewall examples.

[edit] Netfilter iptables architecture

[edit] See also

[edit] External links