diff --git a/weave b/weave index 721a2347..b2c7e124 100755 --- a/weave +++ b/weave @@ -403,6 +403,15 @@ add_iptables_rule() { fi } +# Insert a rule in iptables, if it doesn't exist already +insert_iptables_rule() { + IPTABLES_TABLE="$1" + shift 1 + if ! run_iptables -t $IPTABLES_TABLE -C "$@" >/dev/null 2>&1 ; then + run_iptables -t $IPTABLES_TABLE -I "$@" >/dev/null + fi +} + # Delete a rule from iptables, if it exist delete_iptables_rule() { IPTABLES_TABLE="$1" @@ -1832,7 +1841,7 @@ EOF attach-bridge) if detect_bridge_type ; then attach_bridge ${1:-$DOCKER_BRIDGE} - run_iptables -t nat -I POSTROUTING -o $BRIDGE -j ACCEPT + insert_iptables_rule nat POSTROUTING -o $BRIDGE -j ACCEPT else echo "Weave bridge not found. Please run 'weave launch' and try again" >&2 exit 1