Last active
July 18, 2019 17:49
-
-
Save clems4ever/55888f04ef78d519554add110aab126a to your computer and use it in GitHub Desktop.
docker-swarm iptables FORWARD custom chain enforcement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Public filter enforcement Service | |
[Service] | |
Type=simple | |
ExecStart=/home/user/custom-chain-enforcement.sh | |
KillMode=mixed | |
TimeoutStartSec=0 | |
RestartSec=0 | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target | |
Alias=public-filter.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CUSTOM_CHAIN=PUBLIC_FILTER | |
DELAY=10 | |
while [ True ]; | |
do | |
custom_chain_position=`iptables-save | grep -e "-A FORWARD" | grep --line-number -e "-A FORWARD -j ${CUSTOM_CHAIN}" | sed 's/\([0-9]\+\):.*/\1/g'` | |
if [[ -z "$custom_chain_position" ]] | |
then | |
echo "`date`: Insert custom chain." | |
iptables -I FORWARD -j ${CUSTOM_CHAIN} | |
elif [[ "$custom_chain_position" -ne "1" ]] | |
then | |
echo "`date`: Enforce the priority of custom chain." | |
iptables -D FORWARD ${custom_chain_position} | |
iptables -I FORWARD -j ${CUSTOM_CHAIN} | |
fi | |
sleep $DELAY | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment