![Linux Administration Cookbook](https://wfqqreader-1252317822.image.myqcloud.com/cover/18/36699018/b_36699018.jpg)
How it works...
When you add the -D option to SSH, or add the DynamicForward option to your SSH config file, you're telling SSH that you want to specify a port on your local side that will forward any requests received to it over your SSH connection.
Let's break down our commands:
[vagrant@centos1 ~]$ ssh -f -D9999 192.168.33.11 sleep 120
First, as we did previously, we've used -f and sleep to keep a connection open, while dropping us back to the centos1 prompt once a connection is established:
-f ... sleep 120
We've also specified our -D option, with a randomly chosen port:
-D9999
Once we're established, we use the following command to check our proxy is available for use:
[vagrant@centos1 ~]$ all_proxy="socks5://127.0.0.1:9999" curl 127.0.0.1:8888
Breaking this down into its two parts, we start with the variable we're setting for just this run:
all_proxy="socks5://127.0.0.1:9999"
cURL uses all_proxy as a way of setting the SOCKS proxy for its run.
In your browser, you may find the option to set a SOCKS server under settings, and in some other applications, SOCKS proxies can be configured when required. Gnome's network manager looks like this:
![](https://epubservercos.yuewen.com/B4003C/19470383308832706/epubprivate/OEBPS/Images/5dcbe70c-ae11-4f6b-a090-19800aa7a1a0.png?sign=1739045091-PA98XnOwJH2FTauWwwXISzszyPLeXX9k-0-8a4df9e3dcb0da508f9c195d842f37b7)
The other part of our command is curl:
curl 127.0.0.1:8888
With our all_proxy setting, cURL knows to use the SOCKS proxy on port 9999 for its connections, meaning that when we query 127.0.0.1:8888, we're sending that request over our SSH session to resolve on centos2.
Neat!