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

There's more...

It's not just SSH that this can be used with. In the same way, we can forward ports from the remote session to our local machine  we have a wealth of options available to us.

Let's start and background a simple web server on centos1:

[vagrant@centos1 ~]$ python -m SimpleHTTPServer 8888 &
[1] 6010

Now, let's SSH to centos2, while stating that any requests made on the remote machine to 127.0.0.1:7777 are passed back along the established SSH session to centos1:

[vagrant@centos1 ~]$ ssh -R 7777:127.0.0.1:8888 192.168.33.11

On centos2, we should now be able to curl 127.0.0.1:7777 and see the contents of Vagrant's home directory on centos1:

[vagrant@centos2 ~]$ curl 127.0.0.1:7777
127.0.0.1 - - [09/Aug/2018 12:56:43] "GET / HTTP/1.1" 200 -
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html>
<title>Directory listing for /</title>
<body>
<h2>Directory listing for /</h2>
<hr>
<ul>
<li><a href=".bash_history">.bash_history</a>
<li><a href=".bash_logout">.bash_logout</a>
<li><a href=".bash_profile">.bash_profile</a>
<li><a href=".bashrc">.bashrc</a>
<li><a href=".ssh/">.ssh/</a>
</ul>
<hr>
</body>
</html>

Success!