Ssh – How to verify that the port forwarding is established by checking the sockets

netstatsocketssh

After I run

$ ssh -L 9000:google.com:80 testme@localhost

how can I verify that the port forwarding is established by checking the sockets (internet and unix domain sockets)?

Thanks.

Best Answer

Once the SSH connection is established, you’ll see a listening socket on port 9000:

$ ss -o state listening 'sport = 9000'
Netid Recv-Q Send-Q         Local Address:Port                          Peer Address:Port
tcp   0      128                127.0.0.1:9000                                     *:*
tcp   0      128                      ::1:9000                                    :::*

You won’t see a connection to google.com until a connection is established to port 9000; run

$ nc localhost 9000

then in another terminal you’ll see something like

$ ss -o state established 'dport = 80'
Netid Recv-Q Send-Q         Local Address:Port                          Peer Address:Port
tcp   0      0                 10.10.10.2:34948                       216.58.204.142:http

with a peer address belonging to Google.

Related Question