From a9eb227755dc289497687e87bbb1626fd8ddab3f Mon Sep 17 00:00:00 2001 From: Frantzcy Paisible Date: Mon, 17 Aug 2015 07:13:50 -0400 Subject: [PATCH] Fixed the "iptables: Chain already exists" error --- README.md | 4 ++++ csfpost.sh | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 7f99c71..916d466 100644 --- a/README.md +++ b/README.md @@ -1 +1,5 @@ # ConfigServer Security & Firewall (CSF) - Docker + +Install: + +cp csfpost.sh /usr/local/csf/bin/csfpost.sh diff --git a/csfpost.sh b/csfpost.sh index 839be05..c7640c2 100644 --- a/csfpost.sh +++ b/csfpost.sh @@ -1,8 +1,23 @@ #!/bin/bash +chain_exists() +{ + [ $# -lt 1 -o $# -gt 2 ] && { + echo "Usage: chain_exists [table]" >&2 + return 1 + } + local chain_name="$1" ; shift + [ $# -eq 1 ] && local table="--table $1" + iptables $table -n --list "$chain_name" >/dev/null 2>&1 +} + DOCKER_INT="docker0" DOCKER_NETWORK="172.17.0.0/16" +iptables-save | grep -v -- '-j DOCKER' | iptables-restore +chain_exists DOCKER && iptables -X DOCKER +chain_exists DOCKER nat && iptables -t nat -X DOCKER + iptables -N DOCKER iptables -t nat -N DOCKER