How to setup SSH tuntap tunnel
十二月 29, 2024 更新: 二月 25, 2025 [网络与安全] #SSH 与远程连接 #obsidian #代理与科学上网How to setup SSH tuntap tunnel
Prerequesites
Add or uncomment this line in /etc/ssh/sshd_config of remote machine
PermitTunnel yes
Remote machine setup
Setup TUN virtual interface
# ip tuntap add tun[remote interface number] mode tun
# ip link set dev tun[remote interface number] up
Set address for interface.
# ip address add [remote address] peer [local address] dev tun[remote interface number]
[remote address] – IP address with prefix that will be used for connection on remote machine, [local address] – that will be used for connection on local machine.
Setup routing
# ip route add [address network] via [remote address]
Local machine setup
Setup TUN virtual interface
# ip tuntap add tun[local interface number] mode tun
# ip link set dev tun[local interface number] up
Set address for interface
# ip address add [local address] peer [remote address] dev tun[remote interface number]
Setup routing
# ip route add [address network] via [local address]
Starting tunnel
ssh -v -N -f -p [remote machine port] \
-o Tunnel=point-to-point -o ServerAliveInterval=10 -o TCPKeepAlive=yes \
-w [local machine interface number]:[remote machine interface number] \
[remote machine IP/domain]