Skip to content

Instantly share code, notes, and snippets.

@aleskxyz
Last active December 22, 2023 20:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleskxyz/5af71f11ed99f2ea79df880c1c8b882e to your computer and use it in GitHub Desktop.
Save aleskxyz/5af71f11ed99f2ea79df880c1c8b882e to your computer and use it in GitHub Desktop.
Tunnel over SSH
You can setup a tunnel over SSH with -w option as below.
Try it at home, not server!
Server side
===========
ip tuntap add mode tun dev tun0
ip addr add 192.168.16.1/30 dev tun0
ip link set tun0 up
iptables -I FORWARD -o tun0 -i <public-interface> -j ACCEPT
iptables -I FORWARD -i tun0 -o <public-interface> -j ACCEPT
iptables -t nat -I POSTROUTING -o <public-interface> -j MASQUERADE
Client Side
===========
ip tuntap add mode tun dev tun0
ip addr add 192.168.16.2/30 dev tun0
ip link set tun0 up
ssh -NTf -w 0:0 <username>@<server-ip>
ip route add <server-ip>/32 via <default-gw>
ip route add default via 192.168.16.1 metric 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment