shorewall vs iptables
Shorewall to iptables
On startup, shorewall translates its configuration into a set of iptables rules and loads them. You can see the contents of /var/lib/shorewall/.reload for the nitty-gritty details of how this done. This article tries to provide a basic overview of how shorewall configuration results in iptables chains and rules. In a follow up, we'll try to discover how you can mix a shorewall configuration with dynamicly added iptables rules.
The translation is governed by some basic principles. For instance, a separate chain is created for every transition of traffic from one zone to another or to all. By conventions, these chains are called "{zone_name}2{zone_name}", where {zone_name} may be one of the zones or "all". For instance, the chain that contains the rules for the transition from "net" to "fw" will be called "net2fw".
To show the translation from shorewall zones into iptables chains we'll use the configuration from the standalone firewall example.
A view from shorewall
Zones and interfaces
/etc/shorewall/zones
#ZONE TYPE/etc/shorewall/interfaces
fw firewall
net ipv4
#ZONE INTERFACE BROADCAST OPTIONSThis will result in a number of chains to be branched off from the standard iptables chains:
net eth0 detect dhcp,routefilter,tcpflags
- "eth0_in" chain will be branched off from INPUT for any incoming traffic on eth0
- "eth0_fwd" chain will be branched off from FORWARD for any eth0 traffic
- "fw2all" chain will branched from OUTPUT for any eth0 traffic
- "dynamic" chain for dynamic blacklisting
- "tcpflags" chain for dropping incorrect tcp packets
- an ACCEPT rule for dhcp-specific packets
/etc/shorewall/policy
#SOURCE DEST POLICY LOG/etc/shorewall/rules
fw all ACCEPT $LOG
net all DROP $LOG
all all REJECT $LOG
#ACTION SOURCE DESTINATION PROTO DEST PORT(S)Each policy will result in a separate chain, branched off from its source chain, of which the last rule makes sure that the policy is enforced.
ACCEPT net fw tcp 80
ACCEPT net fw tcp 443
ACCEPT net:86.17.10.162 fw udp
ACCEPT net:myserver.org fw udp 3306
...
- "fw2all" chain -> last line accepts all outgoing traffic
- "net2all" chain -> last line drops all incoming traffic
- "all2all" chain -> last line rejects all traffic
In this example, the rules will result in a "net2fw" chain (source = net, destination = fw) to be branched off directly from "eth0_in" (= last rule of "eth0_in"). The last rule of "net2fw" will then pass control to the "net2all" chain that enforces the general policy for incoming traffic that doesn't match any of the rules in "net2fw" (see below).
Resulting iptables
Default iptables chains
Chain INPUT (policy DROP)Before handing control to the "eth0_in" chain, a rule is included to allow all loopback traffic. The rules after "eth0_in" will have no baring on incoming traffic via eth0, since the default policy for the "net" zone is set to DROP; this causes all incoming eth0 traffic that doesn't comply with one of the rules to be dropped at the end of the "net2all" (see below).
target prot opt in out source destination
ACCEPT 0 -- lo any anywhere anywhere
eth0_in 0 -- eth0 any anywhere anywhere
...
Chain FORWARD (policy DROP)
target prot opt in out source destination
eth0_fwd 0 -- eth0 any anywhere anywhere
...
Chain OUTPUT (policy DROP)Shorewall chains for incoming traffic
target prot opt in out source destination
ACCEPT 0 -- any lo anywhere anywhere
ACCEPT udp -- any eth0 anywhere anywhere udp dpts:bootps:bootpc
fw2all 0 -- any eth0 anywhere anywhere policy match dir out pol none
...
Chain eth0_in (1 references)The "eth0_in" chain branches off to the "dynamic" (= for dynamic blacklisting) and tcpflags (= drop tcp packet with incorrect combination of flags), before passing control to "net2fw".
target prot opt source destination
dynamic 0 -- anywhere anywhere state INVALID,NEW
ACCEPT udp -- anywhere anywhere udp dpts:bootps:bootpc
tcpflags tcp -- anywhere anywhere policy match dir in pol none
net2fw 0 -- anywhere anywhere policy match dir in pol none
Chain net2fw (1 references)The "net2fw" chain governs the traffic from the "net" zone to the "fw" zone (= local machine), so this is the chain that contains all the exception rules for your configuration. After the last of these rules, it passes control to the "net2all" chain.
target prot opt source destination
ACCEPT 0 -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere multiport dports ssh,2233
ACCEPT tcp -- anywhere anywhere tcp dpt:www
ACCEPT udp -- 86.17.10.162 anywhere
ACCEPT udp -- myserver.org anywhere udp dpt:mysql
...
net2all 0 -- anywhere anywhere
Chain net2all (1 references)The "net2all" chain makes sure the default policy (DROP) is enforced for all packets that haven't already been accepted.
target prot opt source destination
ACCEPT 0 -- anywhere anywhere state RELATED,ESTABLISHED
Drop 0 -- anywhere anywhere
...
Comments