Skip to content

Instantly share code, notes, and snippets.

@JrCs
Created February 19, 2016 11:09
Show Gist options
  • Save JrCs/9625c1a21b0762fd8320 to your computer and use it in GitHub Desktop.
Save JrCs/9625c1a21b0762fd8320 to your computer and use it in GitHub Desktop.
Create Posteio container network
#!/bin/bash
docker network create posteio &>/dev/null
id=$(docker network inspect --format "{{.ID}}" posteio 2>/dev/null | cut -c1-12)
[[ -z "$id" ]] && exit 1
MASQUERADE=$(iptables -S -t nat | egrep "POSTROUTING.*br-$id.*MASQUERADE")
[[ -z "$MASQUERADE" ]] && exit 0
source /etc/environment
[[ -z "$POSTEIO_PUBLIC_IPV4" ]] && exit 1
iptables -t nat $(echo "$MASQUERADE" | sed -n "s/^-A/-I/;s/MASQUERADE/SNAT --to-source $POSTEIO_PUBLIC_IPV4/p")
iptables -t nat $(echo "$MASQUERADE" | sed -n "s/^-A/-D/p")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment