Last active
November 7, 2024 09:40
-
-
Save drmalex07/1b8160f6c1761028dfff6c68d1d38156 to your computer and use it in GitHub Desktop.
Tunnel TCP traffic via socat. #socat
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 | |
| # Forward to an IPv6 address | |
| PUBLIC_IP4_IFACE=eth2 | |
| LISTEN_IFACE=${PUBLIC_IP4_IFACE} | |
| listen_address=$(ip -f inet addr show dev ${LISTEN_IFACE} | grep -Po 'inet \K[\d.]+') | |
| listen_port=${1} | |
| target_host=${2} | |
| target_port=${3} | |
| if [ -z "${listen_port}" ]; then | |
| echo "${0} <listen-port> <target-host> <target-port>" && exit 1; | |
| fi | |
| if [ -z "${target_host}" ]; then | |
| echo "${0} <listen-port> <target-host> <target-port>" && exit 1; | |
| fi | |
| if [ -z "${target_port}" ]; then | |
| echo "${0} <listen-port> <target-host> <target-port>" && exit 1; | |
| fi | |
| # Test that ports is actually numbers | |
| [[ ${listen_port} -eq ${listen_port} ]] | |
| [[ ${target_port} -eq ${target_port} ]] | |
| echo " == Forwarding ${listen_address}:${listen_port} -> ${target_host}:${target_port} == " | |
| # Socat | |
| socat -d -d TCP4-LISTEN:${listen_port},bind=${listen_address},su=nobody,fork,reuseaddr TCP6:[${target_host}]:${target_port} |
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 | |
| PUBLIC_IP4_IFACE=eth2 | |
| LISTEN_IFACE=${PUBLIC_IP4_IFACE} | |
| listen_address=$(ip -f inet addr show dev ${LISTEN_IFACE} | grep -Po 'inet \K[\d.]+') | |
| listen_port=${1} | |
| target_host=${2} | |
| target_port=${3} | |
| if [ -z "${listen_port}" ]; then | |
| echo "${0} <listen-port> <target-host> <target-port>" && exit 1; | |
| fi | |
| if [ -z "${target_host}" ]; then | |
| echo "${0} <listen-port> <target-host> <target-port>" && exit 1; | |
| fi | |
| if [ -z "${target_port}" ]; then | |
| echo "${0} <listen-port> <target-host> <target-port>" && exit 1; | |
| fi | |
| # Test that ports is actually numbers | |
| [[ ${listen_port} -eq ${listen_port} ]] | |
| [[ ${target_port} -eq ${target_port} ]] | |
| echo " == Forwarding ${listen_address}:${listen_port} -> ${target_host}:${target_port} == " | |
| # Socat | |
| socat -d -d TCP4-LISTEN:${listen_port},bind=${listen_address},su=nobody,fork,reuseaddr TCP4:${target_host}:${target_port} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment