Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tuxfight3r/99cb1a82449847cd5dd37d031fb48f95 to your computer and use it in GitHub Desktop.
Save tuxfight3r/99cb1a82449847cd5dd37d031fb48f95 to your computer and use it in GitHub Desktop.

Revisions

  1. @drmalex07 drmalex07 revised this gist Jun 26, 2018. 2 changed files with 28 additions and 9 deletions.
    28 changes: 28 additions & 0 deletions socat-forward-tcp.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/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}
    9 changes: 0 additions & 9 deletions socat-ssh.sh
    Original file line number Diff line number Diff line change
    @@ -1,9 +0,0 @@
    #!/bin/bash

    LISTEN_ADDRESS=1.2.3.4
    LISTEN_PORT=10022

    TARGET_HOST=app.localdomain
    TARGET_PORT=22

    socat -d -d TCP4-LISTEN:${LISTEN_PORT},bind=${LISTEN_ADDRESS},su=nobody,fork,reuseaddr TCP4:${TARGET_HOST}:${TARGET_PORT}
  2. @drmalex07 drmalex07 revised this gist May 24, 2018. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions socat-ssh.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,6 @@
    #!/bin/bash

    PUBLIC_IP4_ADDRESS=1.2.3.4

    LISTEN_ADDRESS=${PUBLIC_IP4_ADDRESS}
    LISTEN_ADDRESS=1.2.3.4
    LISTEN_PORT=10022

    TARGET_HOST=app.localdomain
  3. @drmalex07 drmalex07 revised this gist May 24, 2018. No changes.
  4. @drmalex07 drmalex07 created this gist May 24, 2018.
    11 changes: 11 additions & 0 deletions socat-ssh.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #!/bin/bash

    PUBLIC_IP4_ADDRESS=1.2.3.4

    LISTEN_ADDRESS=${PUBLIC_IP4_ADDRESS}
    LISTEN_PORT=10022

    TARGET_HOST=app.localdomain
    TARGET_PORT=22

    socat -d -d TCP4-LISTEN:${LISTEN_PORT},bind=${LISTEN_ADDRESS},su=nobody,fork,reuseaddr TCP4:${TARGET_HOST}:${TARGET_PORT}