Created
August 18, 2020 19:32
-
Star
(102)
You must be signed in to star a gist -
Fork
(15)
You must be signed in to fork a gist
-
-
Save pedrolamas/db809a2b9112166da4a2dbf8e3a72ae9 to your computer and use it in GitHub Desktop.
Script to fix Docker iptables on Synology NAS
This file contains hidden or 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 | |
| currentAttempt=0 | |
| totalAttempts=10 | |
| delay=15 | |
| while [ $currentAttempt -lt $totalAttempts ] | |
| do | |
| currentAttempt=$(( $currentAttempt + 1 )) | |
| echo "Attempt $currentAttempt of $totalAttempts..." | |
| result=$(iptables-save) | |
| if [[ $result =~ "-A DOCKER -i docker0 -j RETURN" ]]; then | |
| echo "Docker rules found! Modifying..." | |
| iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER | |
| iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL ! --dst 127.0.0.0/8 -j DOCKER | |
| echo "Done!" | |
| break | |
| fi | |
| echo "Docker rules not found! Sleeping for $delay seconds..." | |
| sleep $delay | |
| done |
jackmaninov
commented
Jul 22, 2025
current working solution for me;
#!/bin/bash
#based on https://gist.github.com/pedrolamas/db809a2b9112166da4a2dbf8e3a72ae9
currentAttempt=0
totalAttempts=3
delay=15
sleep 60
while [ $currentAttempt -lt $totalAttempts ]
do
currentAttempt=$(( $currentAttempt + 1 ))
echo "Attempt $currentAttempt of $totalAttempts..."
result=$(iptables-save)
if [[ $result =~ "DOCKER-USER" ]]; then
echo "Docker rules found! Modifying..."
#incoming connections will use the right source ip, otherwise dockers userland proxy will do this job
iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
#outgoing connections originating on the host can reach services running inside docker containers via the host's published IP address and port without passing the routingtable
iptables -t nat -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
echo "Done!"
break
fi
echo "Docker rules not found! Sleeping for $delay seconds..."
sleep $delay
done
synology/dsm change that rules inplace with the chains DEFAULT_PREROUTING and DEFAULT_OUTPUT
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment