-
-
Save tuxfight3r/99cb1a82449847cd5dd37d031fb48f95 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 | |
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