forward port ssh code example

Example 1: port forwarding linux

echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
# ENABLES IP FORWARDING TEMPORARILY

Example 2: how to enable the port mapping to the SSH port windos

ssh -R remote_port:localhost:local_port ssh_server_hostname

Example 3: list of created ssh port forwarding

% sudo lsof -i -n | egrep '\<sshd\>'
sshd  15767  root  3u  IPv4 147401205   TCP x.x.x.x:22->y.y.y.y:27479 (ESTABLISHED)
sshd  15842  user  3u  IPv4 147401205   TCP x.x.x.x:22->y.y.y.y:27479 (ESTABLISHED)
sshd  15842  user  9u  IPv4 148002889   TCP 127.0.0.1:33999->127.0.0.1:www (ESTABLISHED)
sshd  1396   user  9u  IPv4 148056581   TCP 127.0.0.1:5000 (LISTEN)
sshd  25936  root  3u  IPv4 143971728   TCP *:22 (LISTEN)

Example 4: list of created ssh port forwarding

% sudo lsof -i -n | egrep '\<ssh\>'
ssh  19749  user  3u  IPv4 148088244   TCP x.x.x.x:39689->y.y.y.y:22 (ESTABLISHED)
ssh  19749  user  4u  IPv6 148088282   TCP [::1]:9090 (LISTEN)
ssh  19749  user  5u  IPv4 148088283   TCP 127.0.0.1:9090 (LISTEN)

Example 5: ssh tunnel port

ssh -L 80:intra.example.com:80 gw.example.com