Last active
October 22, 2021 06:40
-
-
Save superbrothers/d59ad9c059a4f003eb029b767263cef2 to your computer and use it in GitHub Desktop.
This is a strongSwan updown script that allows Docker containers to be accessed through IPSec VPN on the host.
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
#!/usr/bin/env bash | |
# This is a strongSwan updown script that allows Docker containers to be | |
# accessed through IPSec VPN on the host. | |
set -e -o pipefail; [[ -n "$DEBUG" ]] && set -x | |
docker_addr_pools=( $(docker system info -f "{{range .DefaultAddressPools}}{{.Base}} {{end}}") ) | |
case "$PLUTO_VERB" in | |
up-client) | |
for addr_pool in "${docker_addr_pools[@]}"; do | |
sudo iptables -t nat -I POSTROUTING 1 -o "$PLUTO_INTERFACE" -d "$PLUTO_PEER_CLIENT" -s "$addr_pool" -j SNAT --to "$PLUTO_MY_SOURCEIP" | |
done | |
;; | |
down-client) | |
for addr_pool in "${docker_addr_pools[@]}"; do | |
sudo iptables -t nat -D POSTROUTING -o "$PLUTO_INTERFACE" -d "$PLUTO_PEER_CLIENT" -s "$addr_pool" -j SNAT --to "$PLUTO_MY_SOURCEIP" | |
done | |
;; | |
esac | |
# vim: ai ts=2 sw=2 et sts=2 ft=sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download the script and move it to
/etc/ipsec.d/
.Modify
/etc/ipsec.conf
.