Configure iptables for Docker manually and allow Internet access for containersftp tls firewalled :(FsockOpen problem with Iptables inside OpenVZ VMHelp With IPTables: Traffic Forced To Specific NIC?Why does a valid set of iptables rules slow my server to a crawl?Trying to make iptables stateless is causing unforeseen filteringRHEL 6 Having issues forwarding port 80 to port 8080Configuring iptables on dd-wrt routerFirewall rules for ssh, ftp and webappsCentos 7 , Master-slave replication iptables?IPtables blocking SSH only if using conntrack

Do flight schools typically have dress codes or expectations?

Do French speakers not use the subjunctive informally?

How to / is it possible to straighten a bent seatstay/chainstay on a steel frame? At home or inexpensively by a professional

Would a two-seat light aircaft with a landing speed of 20 knots and a top speed of 180 knots be technically possible?

Should I tell my insurance company I'm making payments on my new car?

Is there a way to scan someone's memories while they sleep without them knowing?

Why do some games show lights shine through walls?

Did Karl Marx ever use any example that involved cotton and dollars to illustrate the way capital and surplus value were generated?

Why is C++ initial allocation so much larger than C's?

Why is there no havdallah when going from Yom Tov into Shabbat?

Can White Castle? #2

How risky is real estate?

What sort of mathematical problems are there in AI that people are working on?

Intuitively, why does putting capacitors in series decrease the equivalent capacitance?

Change the boot order with no option in UEFI settings

Why do textbooks often include the solutions to odd or even numbered problems but not both?

What happens when your group is victim of a surprise attack but you can't be surprised?

Is there vegetarian astronaut?

Using “sparkling” as a diminutive of “spark” in a poem

Is my Rep in Stack-Exchange Form?

Does Marvel have an equivalent of the Green Lantern?

How to get cool night-vision without lame drawbacks?

In the Marvel universe, can a human have a baby with any non-human?

STM Microcontroller burns every time



Configure iptables for Docker manually and allow Internet access for containers


ftp tls firewalled :(FsockOpen problem with Iptables inside OpenVZ VMHelp With IPTables: Traffic Forced To Specific NIC?Why does a valid set of iptables rules slow my server to a crawl?Trying to make iptables stateless is causing unforeseen filteringRHEL 6 Having issues forwarding port 80 to port 8080Configuring iptables on dd-wrt routerFirewall rules for ssh, ftp and webappsCentos 7 , Master-slave replication iptables?IPtables blocking SSH only if using conntrack






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I was really unhappy with Docker's behavior regarding modifying my firewall rules because it just opens all ports on my server.

So I have installed iptables-persistent and set up some firewall rules that block all incoming traffic except for port 22, 80 and 443 and I ensured that Docker stops messing with these rules by creating /etc/systemd/system/docker.service.d/noiptables.conf with the following content:



[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --iptables=false -H "fd://"


and then rebooted the server.



Now my problem is that my Docker containers can't access the Internet (interface: ens3) anymore.



These are my rules:



*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o ens3 -j MASQUERADE
COMMIT

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]

# Allow localhost
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT

# ICMP
-A INPUT -p icmp -j ACCEPT

# Docker
-A FORWARD -i docker0 -o ens3 -j ACCEPT
-A FORWARD -i ens3 -o docker0 -j ACCEPT


# Incoming
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -j DROP

# Outgoing
-A OUTPUT -j ACCEPT

# Routing
-A FORWARD -j DROP


COMMIT


I stored them in /etc/iptables/rules.v4 and /etc/iptables/rules.v6 and made sure they are loaded by running sudo netfilter-persistent reload.



According to this guide: https://blog.daknob.net/debian-firewall-docker/
The *nat section would do the job, but it doesn't.



My system:



$ sudo iptables --version
iptables v1.6.1

$ uname -r
4.11.0-1-amd64

$ sudo lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux testing (buster)
Release: testing
Codename: buster









share|improve this question






















  • Could you paste the dns configuration of your containters? If you are using the host as dns server, you need to add a INPUT rule for 53/udp

    – Simone Zabberoni
    Aug 19 '17 at 21:08


















1















I was really unhappy with Docker's behavior regarding modifying my firewall rules because it just opens all ports on my server.

So I have installed iptables-persistent and set up some firewall rules that block all incoming traffic except for port 22, 80 and 443 and I ensured that Docker stops messing with these rules by creating /etc/systemd/system/docker.service.d/noiptables.conf with the following content:



[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --iptables=false -H "fd://"


and then rebooted the server.



Now my problem is that my Docker containers can't access the Internet (interface: ens3) anymore.



These are my rules:



*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o ens3 -j MASQUERADE
COMMIT

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]

# Allow localhost
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT

# ICMP
-A INPUT -p icmp -j ACCEPT

# Docker
-A FORWARD -i docker0 -o ens3 -j ACCEPT
-A FORWARD -i ens3 -o docker0 -j ACCEPT


# Incoming
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -j DROP

# Outgoing
-A OUTPUT -j ACCEPT

# Routing
-A FORWARD -j DROP


COMMIT


I stored them in /etc/iptables/rules.v4 and /etc/iptables/rules.v6 and made sure they are loaded by running sudo netfilter-persistent reload.



According to this guide: https://blog.daknob.net/debian-firewall-docker/
The *nat section would do the job, but it doesn't.



My system:



$ sudo iptables --version
iptables v1.6.1

$ uname -r
4.11.0-1-amd64

$ sudo lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux testing (buster)
Release: testing
Codename: buster









share|improve this question






















  • Could you paste the dns configuration of your containters? If you are using the host as dns server, you need to add a INPUT rule for 53/udp

    – Simone Zabberoni
    Aug 19 '17 at 21:08














1












1








1








I was really unhappy with Docker's behavior regarding modifying my firewall rules because it just opens all ports on my server.

So I have installed iptables-persistent and set up some firewall rules that block all incoming traffic except for port 22, 80 and 443 and I ensured that Docker stops messing with these rules by creating /etc/systemd/system/docker.service.d/noiptables.conf with the following content:



[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --iptables=false -H "fd://"


and then rebooted the server.



Now my problem is that my Docker containers can't access the Internet (interface: ens3) anymore.



These are my rules:



*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o ens3 -j MASQUERADE
COMMIT

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]

# Allow localhost
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT

# ICMP
-A INPUT -p icmp -j ACCEPT

# Docker
-A FORWARD -i docker0 -o ens3 -j ACCEPT
-A FORWARD -i ens3 -o docker0 -j ACCEPT


# Incoming
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -j DROP

# Outgoing
-A OUTPUT -j ACCEPT

# Routing
-A FORWARD -j DROP


COMMIT


I stored them in /etc/iptables/rules.v4 and /etc/iptables/rules.v6 and made sure they are loaded by running sudo netfilter-persistent reload.



According to this guide: https://blog.daknob.net/debian-firewall-docker/
The *nat section would do the job, but it doesn't.



My system:



$ sudo iptables --version
iptables v1.6.1

$ uname -r
4.11.0-1-amd64

$ sudo lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux testing (buster)
Release: testing
Codename: buster









share|improve this question














I was really unhappy with Docker's behavior regarding modifying my firewall rules because it just opens all ports on my server.

So I have installed iptables-persistent and set up some firewall rules that block all incoming traffic except for port 22, 80 and 443 and I ensured that Docker stops messing with these rules by creating /etc/systemd/system/docker.service.d/noiptables.conf with the following content:



[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --iptables=false -H "fd://"


and then rebooted the server.



Now my problem is that my Docker containers can't access the Internet (interface: ens3) anymore.



These are my rules:



*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o ens3 -j MASQUERADE
COMMIT

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]

# Allow localhost
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT

# ICMP
-A INPUT -p icmp -j ACCEPT

# Docker
-A FORWARD -i docker0 -o ens3 -j ACCEPT
-A FORWARD -i ens3 -o docker0 -j ACCEPT


# Incoming
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -j DROP

# Outgoing
-A OUTPUT -j ACCEPT

# Routing
-A FORWARD -j DROP


COMMIT


I stored them in /etc/iptables/rules.v4 and /etc/iptables/rules.v6 and made sure they are loaded by running sudo netfilter-persistent reload.



According to this guide: https://blog.daknob.net/debian-firewall-docker/
The *nat section would do the job, but it doesn't.



My system:



$ sudo iptables --version
iptables v1.6.1

$ uname -r
4.11.0-1-amd64

$ sudo lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux testing (buster)
Release: testing
Codename: buster






debian iptables firewall






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 16 '17 at 10:24









ForivinForivin

589 bronze badges




589 bronze badges












  • Could you paste the dns configuration of your containters? If you are using the host as dns server, you need to add a INPUT rule for 53/udp

    – Simone Zabberoni
    Aug 19 '17 at 21:08


















  • Could you paste the dns configuration of your containters? If you are using the host as dns server, you need to add a INPUT rule for 53/udp

    – Simone Zabberoni
    Aug 19 '17 at 21:08

















Could you paste the dns configuration of your containters? If you are using the host as dns server, you need to add a INPUT rule for 53/udp

– Simone Zabberoni
Aug 19 '17 at 21:08






Could you paste the dns configuration of your containters? If you are using the host as dns server, you need to add a INPUT rule for 53/udp

– Simone Zabberoni
Aug 19 '17 at 21:08











1 Answer
1






active

oldest

votes


















1














First, you have never mentioned net.ipv4.ip_forward net.ipv4.ip_forward. Enable that if you haven't.



Ensure that you can access the internet. curl httpbin.org/ip is a nice and easy way to check that.



If you did, ensure that your rules are active by checking the output of iptables-save



If they are, debug it, here are the pseudo-steps:



  1. Inside the docker, ping an external IP, say 8.8.8.8 and ensure that you do not receive any reply. Do not use a hostname. Let's keep DNS problems out of our scenario. Keep it running for the next step.


  2. Inside the container, check all interfaces one by one with tcpdump and look for packages destined to 8.8.8.8. This must be docker0 according to the rules you've pasted to your question.


  3. Check your host's routing table and ensure that the default route, 0.0.0.0 is on the interface ens3


You should get enough information to solve the problem.






share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "2"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f868926%2fconfigure-iptables-for-docker-manually-and-allow-internet-access-for-containers%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    First, you have never mentioned net.ipv4.ip_forward net.ipv4.ip_forward. Enable that if you haven't.



    Ensure that you can access the internet. curl httpbin.org/ip is a nice and easy way to check that.



    If you did, ensure that your rules are active by checking the output of iptables-save



    If they are, debug it, here are the pseudo-steps:



    1. Inside the docker, ping an external IP, say 8.8.8.8 and ensure that you do not receive any reply. Do not use a hostname. Let's keep DNS problems out of our scenario. Keep it running for the next step.


    2. Inside the container, check all interfaces one by one with tcpdump and look for packages destined to 8.8.8.8. This must be docker0 according to the rules you've pasted to your question.


    3. Check your host's routing table and ensure that the default route, 0.0.0.0 is on the interface ens3


    You should get enough information to solve the problem.






    share|improve this answer



























      1














      First, you have never mentioned net.ipv4.ip_forward net.ipv4.ip_forward. Enable that if you haven't.



      Ensure that you can access the internet. curl httpbin.org/ip is a nice and easy way to check that.



      If you did, ensure that your rules are active by checking the output of iptables-save



      If they are, debug it, here are the pseudo-steps:



      1. Inside the docker, ping an external IP, say 8.8.8.8 and ensure that you do not receive any reply. Do not use a hostname. Let's keep DNS problems out of our scenario. Keep it running for the next step.


      2. Inside the container, check all interfaces one by one with tcpdump and look for packages destined to 8.8.8.8. This must be docker0 according to the rules you've pasted to your question.


      3. Check your host's routing table and ensure that the default route, 0.0.0.0 is on the interface ens3


      You should get enough information to solve the problem.






      share|improve this answer

























        1












        1








        1







        First, you have never mentioned net.ipv4.ip_forward net.ipv4.ip_forward. Enable that if you haven't.



        Ensure that you can access the internet. curl httpbin.org/ip is a nice and easy way to check that.



        If you did, ensure that your rules are active by checking the output of iptables-save



        If they are, debug it, here are the pseudo-steps:



        1. Inside the docker, ping an external IP, say 8.8.8.8 and ensure that you do not receive any reply. Do not use a hostname. Let's keep DNS problems out of our scenario. Keep it running for the next step.


        2. Inside the container, check all interfaces one by one with tcpdump and look for packages destined to 8.8.8.8. This must be docker0 according to the rules you've pasted to your question.


        3. Check your host's routing table and ensure that the default route, 0.0.0.0 is on the interface ens3


        You should get enough information to solve the problem.






        share|improve this answer













        First, you have never mentioned net.ipv4.ip_forward net.ipv4.ip_forward. Enable that if you haven't.



        Ensure that you can access the internet. curl httpbin.org/ip is a nice and easy way to check that.



        If you did, ensure that your rules are active by checking the output of iptables-save



        If they are, debug it, here are the pseudo-steps:



        1. Inside the docker, ping an external IP, say 8.8.8.8 and ensure that you do not receive any reply. Do not use a hostname. Let's keep DNS problems out of our scenario. Keep it running for the next step.


        2. Inside the container, check all interfaces one by one with tcpdump and look for packages destined to 8.8.8.8. This must be docker0 according to the rules you've pasted to your question.


        3. Check your host's routing table and ensure that the default route, 0.0.0.0 is on the interface ens3


        You should get enough information to solve the problem.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Aug 24 '17 at 11:39









        Can Burak ÇilingirCan Burak Çilingir

        2662 silver badges7 bronze badges




        2662 silver badges7 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Server Fault!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f868926%2fconfigure-iptables-for-docker-manually-and-allow-internet-access-for-containers%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

            What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

            Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos