- Linux Administration Cookbook
- Adam K. Dean
- 104字
- 2025-04-04 15:16:16
On the command line
Run the following from centos1:
[vagrant@centos1 ~]$ ssh -f -L 9999:127.0.0.1:8888 192.168.33.11 sleep 120
You may be prompted for your password (depending on what you've done in terms of key setup) and then be dropped back to the centos1 prompt.
Our SSH connection will stay up for two minutes.
Now, we run a curl, checking that our forwarding is working:
[vagrant@centos1 ~]$ curl 127.0.0.1:9999
<!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! Here, we're curling the localhost IP address of centos1 on our forwarded port and we're getting the directory listing from centos2!