<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Nosebit Engineering - Medium]]></title>
        <description><![CDATA[Nosebit Engineering - Medium]]></description>
        <link>https://medium.com/nosebit-engineering?source=rss----f1ffc1389d97---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Nosebit Engineering - Medium</title>
            <link>https://medium.com/nosebit-engineering?source=rss----f1ffc1389d97---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 06:24:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/nosebit-engineering" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Docker, Firewall and DNS]]></title>
            <link>https://medium.com/nosebit-engineering/docker-firewall-and-dns-1a7ccfc21be?source=rss----f1ffc1389d97---4</link>
            <guid isPermaLink="false">https://medium.com/p/1a7ccfc21be</guid>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[firewall]]></category>
            <dc:creator><![CDATA[Bruno Fonseca]]></dc:creator>
            <pubDate>Tue, 09 Oct 2018 02:36:28 GMT</pubDate>
            <atom:updated>2018-10-09T02:36:27.838Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4_7WXWVaBOG3NPTTj6m57A.png" /></figure><p>Howdy folks! Recently i started to build a new cluster to accommodate the micro-services for Bank27 dev environment and walked through some interesting stuff regarding containers, firewalls and DNS that i’m excited to share with you :)</p><p>Due to budget limitations right now we decied to use a very cheap VPS provider named <a href="https://contabo.com/">Contabo</a> instead of any famous cloud providers like Google Cloud, AWS, Digital Ocean, etc. We bought 3 VPS machines (12Gb RAM, 4 core processor) from Contaboo for only €8.99 per month per machine (!!!) and have to setup firewall protection by hand. Each VPS runs Ubuntu 16 and going to hold a bunch of docker containers managed by Nomad scheduler and discoverable via Consul (yes, we love HashiCorp).</p><p>We started our journey creating an admin user in each server, disabling root user access and forcing all logins to be made trough ssh key instead of username/password. Then we installed ufw, a tool that makes it easy to manage firewall without the harsles of playing with iptables directly [<a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-14-04">link</a>]. First we disabled all incoming connections and enabled all outcoming connections running:</p><pre>sudo ufw deny incoming<br>sudo ufw allow outcoming</pre><p>and then we started to allow specific incoming connections like (1) allowing ssh connection from any external server and (2) allowing all incoming connections from our other servers in our cluster (which PUBLIC_IP we know):</p><pre>sudo ufw allow ssh     # (1)<br>sudo ufw allow from PUBLIC_IP # (2)</pre><p>After that we came into a very inetersting problem on how Docker manages host networking to allow port bindings for containers. To summarize: Docker directly modifies host’s iptablese to allow incoming traffic towards container binded ports and therfore it bypass ufw protection. In other others, no matter we blocked all incoming connections using ufw, for container ports this rule will simply not apply [<a href="https://www.techrepublic.com/article/how-to-fix-the-docker-and-ufw-security-flaw/">link</a>]. A solution to this problem consist in instruct docker to don’t do that automatically for us adding the following key-value to /etc/docker/daemon.json (create this files if not already there):</p><pre>{<br>  &quot;iptables&quot;: false<br>}</pre><p>and then restarting docker to apply this new config:</p><pre># for those using systemd<br>sudo systemctl restart docker</pre><pre># for those using upstart<br>sudo service docker restart</pre><p>Then we move to set Consul service discovery for our microsservices and more specifically the DNS server that Consul provide out-of-the-box. As explained in docs [<a href="https://www.consul.io/docs/guides/forwarding.html">link</a>] DNS is served from port 53 by default, but most operating system required sudo privileges to bind to this special port. Instead of running Consul as administrator it’s recommended to let Consul DSN running on unprivileged port (8600 by default) and set some DNS proxy running on port 53 to forward specific requests to Consul. We chose dnsmasq as such “proxier” and created the following /etc/dnsmasq.d/consul config file to set the behavior:</p><pre># Enable forward lookup of the &#39;consul&#39; domain:<br>server=/consul/127.0.0.1#8600<br>interface=docker0<br>bind-interfaces</pre><p>The server line instruct dnsmasq to proxy all request ending in consul (like user.service.consul) to Consul DNS running on 127.0.0.1 and port 8600. The second line states the interface which dnsmasq should bind (listen for requests) and we choose docker0 interface here to serve as the bridge interface between containers and host but we could chose other interface like en0 as well or even a specific IP s the host private or public ip setting listen-address=IP . Last but not least we specify bind-interfaces to disable the default behavior of dnsmasq binding to wildcard addresses [<a href="http://oss.segetech.com/intra/srv/dnsmasq.conf">link</a>]. After saving the file, restart dnsmasq running:</p><pre>sudo systemctl restart dnsmasq</pre><p>At this point we were very excited to test if everything was working properly and to do so we started a test container based on alpine linux to check dns requests:</p><pre>docker run -it --dns 172.17.0.1 alpine:edge sh</pre><p>where 172.17.0.1 is the IP address for docker0 interface where dnsmasq is listen. Then inside the container we tried to reach our consul dns server doing:</p><pre>nslookup consul.service.consul</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a7ccfc21be" width="1" height="1" alt=""><hr><p><a href="https://medium.com/nosebit-engineering/docker-firewall-and-dns-1a7ccfc21be">Docker, Firewall and DNS</a> was originally published in <a href="https://medium.com/nosebit-engineering">Nosebit Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>