Last active
February 14, 2021 18:46
-
-
Save waja/a02cea153422b99cfa1002c921444505 to your computer and use it in GitHub Desktop.
Deploy a IPv6 to IPv4 port forward, might be handy in docker environments
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 | |
if [ $(ip -6 route | grep -c ^default) -eq 0 ]; then exit; fi | |
apt install socat || exit | |
cat > /etc/systemd/system/socat\@.service <<EOF | |
[Unit] | |
Description=ipv6 to ipv4 port forwarding | |
After=network.target | |
[Service] | |
Type=simple | |
ExecStart=/usr/bin/socat TCP6-LISTEN:%i,ipv6only=1,reuseaddr,fork TCP4:127.0.0.1:%i | |
[Install] | |
WantedBy=docker.service | |
EOF | |
systemctl daemon-reload | |
for PROTO in http https; do | |
systemctl enable socat@${PROTO}.service | |
systemctl start socat@${PROTO}.service | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment