Linux Administration Cookbook
上QQ阅读APP看书,第一时间看更新

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
I use 9999 through force of habit, but occasionally I mix it up a bit by using 7777, or even 6666 if I'm feeling really wild. You may use whichever port you wish (above 1024, as those below this can only be used by root.)

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:

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!