Skip to content

Instantly share code, notes, and snippets.

@waja
Last active February 14, 2021 18:46
Show Gist options
  • Save waja/a02cea153422b99cfa1002c921444505 to your computer and use it in GitHub Desktop.
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
#!/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