Last active
January 8, 2025 00:36
-
-
Save maxclaus/70b564c94aeeeee182fb to your computer and use it in GitHub Desktop.
Revisions
-
maxcnunes revised this gist
Jun 25, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,4 +8,6 @@ socat -d -d TCP4-LISTEN:15432,fork UNIX-CONNECT:/srv/mongodb-27017.sock ```shell ./forward-port-to-socket.sh 15432 /srv/mongodb-27017.sock ``` [Coderwall Post](https://coderwall.com/p/c3wyzq) -
maxcnunes created this gist
Jun 25, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ ### Base Command ```shell socat -d -d TCP4-LISTEN:15432,fork UNIX-CONNECT:/srv/mongodb-27017.sock ``` ### Final Script ```shell ./forward-port-to-socket.sh 15432 /srv/mongodb-27017.sock ``` 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ #!/bin/sh -e if [ $# != 2 ]; then echo "usage: $0 <public-port> <path-private-socket>" echo "example: $0 15432 /srv/my-service.sock" exit 0 fi PUBLIC_PORT=$1 PRIVATE_SOCKET=$2 SOCAT_LOG=/tmp/socat-$PUBLIC_PORT.log echo "--> socat forwarding:\n\t- from port: $PUBLIC_PORT\n\t- to socket: $PRIVATE_SOCKET" echo "--> allowed ips:\n\t$(cat socat-allow)" echo "--> logs: $SOCAT_LOG" socat -d -d -lf $SOCAT_LOG \ TCP4-LISTEN:$PUBLIC_PORT,reuseaddr,fork,tcpwrap=socat,allow-table=socat-allow,deny-table=socat-deny \ UNIX-CONNECT:$PRIVATE_SOCKET 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ socat:<allowed-ip-here> 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ socat:all