Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup bridge0 and iptables automatically #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Commits on Aug 15, 2015

  1. Use brctl to create bridge0 if it's missing

    The brctl command (from bridge-utils) is an easier dependency than
    requiring users to setup the bridge themselves.  Following [1].
    
    [1]: https://docs.docker.com/articles/networking/#bridge-building
    wking committed Aug 15, 2015
    Configuration menu
    Copy the full SHA
    4612ad7 View commit details
    Browse the repository at this point in the history
  2. Collapse 'ip link set' commands where possible

    One 'ip link set' call can set all the values we need; there's no need
    for a separate call for each value.
    
    I've shifted the veth1 call to after the route and address, to avoid
    putting it up before it's fully configured.  We have to add the route
    after putting veth1 up though, to avoid:
    
      RTNETLINK answers: Network is unreachable
    wking committed Aug 15, 2015
    Configuration menu
    Copy the full SHA
    96bdd75 View commit details
    Browse the repository at this point in the history
  3. Automatically enable IPv4 forwarding

    One less step for the user to handle on their own.  We might want to
    log this change, since it has the potential to create unwanted
    side-effects if the user has a permissive firewall.
    
    If procps (from which we get sysctl) is too burdensome a dependency,
    we could use:
    
      echo 1 > /proc/sys/net/ipv4/ip_forward
    wking committed Aug 15, 2015
    Configuration menu
    Copy the full SHA
    65b9937 View commit details
    Browse the repository at this point in the history

Commits on Aug 16, 2015

  1. Automatically setup iptables rules

    Based on [1].  With ACCEPT policies for INPUT, FORWARD, and OUTPUT in
    the filter table, and PREROUTING, INPUT, OUTPUT, and POSTROUTING in
    the nat table, this MASQUERADE jump is all we need.
    
    With those permissive rules, external hosts can access the containers
    by adding a route like:
    
      # ip route add 10.0.0.0/24 via 192.168.0.2
    
    where 192.168.0.2 is the IP address of the Bocker host.
    
    For more restrictive networking, you could be harsher with FORWARD on
    the Bocker host and use:
    
      # iptables -t nat -A PREROUTING ! -i bridge0 -p tcp --dport 80 -j DNAT --to 10.0.0.3:80
      # iptables -I FORWARD -d 10.0.0.3 -p tcp --dport 80 -j ACCEPT
    
    to forward the Bocker host's port 80 to the 10.0.0.3 container's port
    80.
    
    [1]: https://github.com/gdm85/docker-fw/blob/d9cee19989ead67e6107740869ba9c13d4ff6096/example-iptables.txt
    wking committed Aug 16, 2015
    Configuration menu
    Copy the full SHA
    64e95c5 View commit details
    Browse the repository at this point in the history