{"id":4719,"date":"2022-12-20T18:36:49","date_gmt":"2022-12-20T21:36:49","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/shorewallnesting-man5\/"},"modified":"2022-12-20T18:36:49","modified_gmt":"2022-12-20T21:36:49","slug":"shorewallnesting-man5","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/shorewallnesting-man5\/","title":{"rendered":"SHOREWALL&minus;NESTING (man5)"},"content":{"rendered":"<h1 align=\"center\">SHOREWALL\u2212NESTING<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#EXAMPLE\">EXAMPLE<\/a><br \/> <a href=\"#FILES\">FILES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">nesting \u2212 Shorewall Nested Zones<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"63%\">\n<p style=\"margin-top: 1em\"><i>child\u2212zone<\/i>[:<i>parent\u2212zone<\/i>[,<i>parent\u2212zone<\/i>]&#8230;]<\/p>\n<\/td>\n<td width=\"26%\"> <\/td>\n<\/tr>\n<\/table>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">In <b><font color=\"#0000FF\">shorewall\u2212zones<\/font><\/b> <small><font color=\"#000000\">[1]<\/font><\/small> <font color=\"#000000\">(5), a zone may be declared to be a sub\u2212zone of one or more other zones using the above syntax. The <i>child\u2212zone<\/i> may be neither the firewall zone nor a vserver zone. The firewall zone may not appear as a parent zone, although all vserver zones are handled as sub\u2212zones of the firewall zone.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Where zones are nested, the CONTINUE policy in<\/font> <b><font color=\"#0000FF\">shorewall\u2212policy<\/font><\/b> <small><font color=\"#000000\">[2]<\/font><\/small> <font color=\"#000000\">(5) allows hosts that are within multiple zones to be managed under the rules of all of these zones.<\/font><\/p>\n<h2>EXAMPLE <a name=\"EXAMPLE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/zones:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#ZONE TYPE OPTION <br \/> fw firewall <br \/> net ipv4 <br \/> sam:net ipv4 <br \/> loc ipv4<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/interfaces:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#ZONE INTERFACE BROADCAST OPTIONS <br \/> \u2212 eth0 detect dhcp,norfc1918 <br \/> loc eth1 detect<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/hosts:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#ZONE HOST(S) OPTIONS <br \/> net eth0:0.0.0.0\/0 <br \/> sam eth0:206.191.149.197<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/policy:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#SOURCE DEST POLICY LOG LEVEL <br \/> loc net ACCEPT <br \/> sam all CONTINUE <br \/> net all DROP info <br \/> all all REJECT info<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The second entry above says that when Sam is the client, connection requests should first be processed under rules where the source zone is sam and if there is no match then the connection request should be treated under rules where the source zone is net. It is important that this policy be listed BEFORE the next policy (net to all). You can have this policy generated for you automatically by using the IMPLICIT_CONTINUE option in<\/font> <b><font color=\"#0000FF\">shorewall.conf<\/font><\/b> <small><font color=\"#000000\">[3]<\/font><\/small> <font color=\"#000000\">(5).<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Partial \/etc\/shorewall\/rules:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#ACTION SOURCE DEST PROTO DPORT <br \/> &#8230; <br \/> DNAT sam loc:192.168.1.3 tcp ssh <br \/> DNAT net loc:192.168.1.5 tcp www <br \/> &#8230;<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Given these two rules, Sam can connect to the firewall&#8217;s internet interface with ssh and the connection request will be forwarded to 192.168.1.3. Like all hosts in the net zone, Sam can connect to the firewall&#8217;s internet interface on TCP port 80 and the connection request will be forwarded to 192.168.1.5. The order of the rules is not significant. Sometimes it is necessary to suppress port forwarding for a sub\u2212zone. For example, suppose that all hosts can SSH to the firewall and be forwarded to 192.168.1.5 EXCEPT Sam. When Sam connects to the firewall&#8217;s external IP, he should be connected to the firewall itself. Because of the way that Netfilter is constructed, this requires two rules as follows:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#ACTION SOURCE DEST PROTO DPORT <br \/> &#8230; <br \/> ACCEPT+ sam $FW tcp ssh <br \/> DNAT net loc:192.168.1.3 tcp ssh <br \/> &#8230;<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The first rule allows Sam SSH access to the firewall. The second rule says that any clients from the net zone with the exception of those in the \u201csam\u201d zone should have their connection port forwarded to 192.168.1.3. If you need to exclude more than one zone, simply use multiple ACCEPT+ rules. This technique also may be used when the ACTION is REDIRECT.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Care must be taken when nesting occurs as a result of the use of wildcard interfaces (interface names ends in &#8216;+&#8217;).<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Here&#8217;s an example. \/etc\/shorewall\/zones:<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/interfaces:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#ZONE INTERFACE BROADCAST OPTIONS <br \/> net ppp0 <br \/> loc eth1 <br \/> loc ppp+ <br \/> dmz eth2<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Because the net zone is declared before the loc zone, net is an implicit sub\u2212zone of loc and in the absence of a net\u2212>&#8230; CONTINUE policy, traffic from the net zone will not be passed through loc\u2212>&#8230; rules. But DNAT and REDIRECT rules are an exception!<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 DNAT and REDIRECT rules generate two Netfilter rules: a &#8216;nat&#8217; table rule that rewrites the destination IP address and\/or port number, and a &#8216;filter&#8217; table rule that ACCEPTs the rewritten connection.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 Policies only affect the &#8216;filter&#8217; table.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">As a consequence, the following rules will have unexpected behavior:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#ACTION SOURCE DEST PROTO DPORT <br \/> ACCEPT net dmz tcp 80 <br \/> REDIRECT loc 3128 tcp 80<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The second rule is intended to redirect local web requests to a proxy running on the firewall and listening on TCP port 3128. But the &#8216;nat&#8217; part of that rule will cause all connection requests for TCP port 80 arriving on interface ppp+ (including ppp0!) to have their destination port rewritten to 3128. Hence, the web server running in the DMZ will be inaccessible from the web.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The above problem can be corrected in several ways.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The preferred way is to use the <b>ifname<\/b> pppd option to change the &#8216;net&#8217; interface to something other than ppp0. That way, it won&#8217;t match ppp+.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If you are running Shorewall version 4.1.4 or later, a second way is to simply make the nested zones explicit:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#ZONE TYPE OPTION <br \/> fw firewall <br \/> loc ipv4 <br \/> net:loc ipv4 <br \/> dmz ipv4<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If you take this approach, be sure to set IMPLICIT_CONTINUE=No in shorewall.conf.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">When using other Shorewall versions, another way is to rewrite the DNAT rule (assume that the local zone is entirely within 192.168.2.0\/23):<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#ACTION SOURCE DEST PROTO DPORT <br \/> ACCEPT net dmz tcp 80 <br \/> REDIRECT loc:192.168.2.0\/23 3128 tcp 80<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Another way is to restrict the definition of the loc zone:<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/interfaces:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#ZONE INTERFACE BROADCAST OPTIONS <br \/> net ppp0 <br \/> loc eth1 <br \/> \u2212 ppp+ <br \/> dmz eth2<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/hosts:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">#ZONE HOST(S) OPTIONS <br \/> loc ppp+:192.168.2.0\/23<\/font><\/p>\n<h2>FILES <a name=\"FILES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/zones<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/interfaces<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/hosts<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/policy<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall\/rules<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall6\/zones<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall6\/interfaces<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall6\/hosts<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall6\/policy<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">\/etc\/shorewall6\/rules<\/font><\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">shorewall(8), shorewall\u2212accounting(5), shorewall\u2212actions(5), shorewall\u2212blacklist(5), shorewall\u2212hosts(5), shorewall_interfaces(5), shorewall\u2212ipsets(5), shorewall\u2212maclist(5), shorewall\u2212masq(5), shorewall\u2212nat(5), shorewall\u2212netmap(5), shorewall\u2212params(5), shorewall\u2212policy(5), shorewall\u2212providers(5), shorewall\u2212proxyarp(5), shorewall\u2212rtrules(5), shorewall\u2212routestopped(5), shorewall\u2212rules(5), shorewall.conf(5), shorewall\u2212secmarks(5), shorewall\u2212tcclasses(5), shorewall\u2212tcdevices(5), shorewall\u2212mangle(5), shorewall\u2212tos(5), shorewall\u2212tunnels(5), shorewall\u2212zones(5)<\/font><\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">1.<\/font><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"23%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">shorewall-zones<\/font><\/p>\n<\/td>\n<td width=\"60%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">https:\/\/shorewall.org\/manpages\/shorewall-zones.html<\/font><\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">2.<\/font><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"25%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">shorewall-policy<\/font><\/p>\n<\/td>\n<td width=\"58%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">https:\/\/shorewall.org\/manpages\/shorewall-policy.html<\/font><\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">3.<\/font><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"21%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">shorewall.conf<\/font><\/p>\n<\/td>\n<td width=\"62%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">https:\/\/shorewall.org\/manpages\/shorewall.conf.html<\/font><\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  nesting \u2212 Shorewall Nested Zones <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[959],"tags":[961,1291,1642],"class_list":["post-4719","post","type-post","status-publish","format-standard","hentry","category-5-formatos-de-ficheros","tag-961","tag-man5","tag-shorewall-nesting"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4719"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4719\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}