How it works
First a quick introduction to
© 2018 Julia Evans, for more programming zines and comics, see wizardzines.com/
Examples in the comic included as text in our cheat sheet below for easy copy/paste.
-v option provides verbose output to stdout which is very useful for debugging
Proxy from local HTTP port to remote server:
socat -v TCP-LISTEN:1337 TCP:example.com:80
now if you go to localhost:1337 you will see a response from http://example.com
(though the Host field is incorrect, so you get a 404). A deep dive into HTTP
is outside of the scope of this socat cheat sheet, but you can test this with
curl --resolve example.com:80:localhost:1334 example.com.
In real life, most servers will require SSL, which can be added on
verify=0 won’t check the SSL cert, which is fine for most debug /
learning use cases).
socat -v TCP-LISTEN:1337 ssl:example.com:80,verify=0
Unix domain socket
expose a unix domain socket on port 1337
socat TCP-LISTEN:1337 UNIX-CONNECT:/path
How to install
Debian / Ubuntu Linux
sudo apt-get update && sudo apt-get install socat
Fedora, CentOS, RedHat
sudo yum install socat
brew install socat