<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Apr 28, 2017 at 1:05 AM, Ron Kelley <span dir="ltr"><<a href="mailto:rkelleyrtp@gmail.com" target="_blank">rkelleyrtp@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Thanks for the feedback, Spike. After looking around for a while, I, too, decided a small ubuntu container with a minimal firewall tool is the way to go. In my case, I used “ufw” but will also look at "firehol”.<br>
<br>
Our firewall/NAT requirements are not very large, and I finally figured out the right set of rules we need. In essence, we just need to add these to the /etc/ufw/before.rules file and restart ufw:<br>
<br></blockquote><div><br></div><div>with ONLY changes to /etc/ufw/before.rules, the NAT rules would be reapplied (resulting multiple rules on NAT table) whenever you restart ufw. No big deal if you plan to restart the container anyway on every rule change (or never plan to change the rules), but not ideal if your plan is to use "ufw reload".</div><div><br></div><div>In my case I had to separate ufw NAT rules into a new custom chain, ufw-before-prerouting: </div><div><br></div><div><br></div><div>- edit /etc/ufw/before.init (copy it from /usr/share/ufw/before.init), and make it executable (e.g. chmod 700). Snippet of edited lines:</div><div><br></div><div><div>start)</div><div> iptables -t nat -N ufw-before-prerouting || true<br></div><div> iptables -t nat -I PREROUTING -j ufw-before-prerouting || true</div><div> ;;<br></div><div>stop)</div><div> iptables -t nat -D PREROUTING -j ufw-before-prerouting || true<br></div><div> iptables -t nat -F ufw-before-prerouting || true</div><div> iptables -t nat -X ufw-before-prerouting || true</div><div> ;;<br></div></div><div><br></div><div><br></div><div><br></div><div>- add NAT lines to /etc/ufw/before.rules to look similar to this:</div><div><div><br></div><div><div># nat Table rules</div><div>*nat</div><div>:ufw-before-prerouting - [0:0]</div><div><br></div><div># DNAT example<br></div><div>-A ufw-before-prerouting -i eth0 -p tcp --dport 21122 -j DNAT --to <a href="http://10.0.3.211:22">10.0.3.211:22</a><br></div></div></div><div><br></div><div><br></div><div>-- </div><div>Fajar</div></div></div></div>