分类 Linux 下的文章

查询占用端口的程序
sudo netstat -nlp | grep :80
sudo lsof -n -i :80 | grep LISTEN

本地转发:

ssh -L [LOCAL_IP:]LOCAL_PORT:DESTINATION:DESTINATION_PORT [USER@]SSH_SERVER
  • [LOCAL_IP:]LOCAL_PORT - The local machine IP address and port number. When LOCAL_IP is omitted, the ssh client binds on the localhost.
  • DESTINATION:DESTINATION_PORT - The IP or hostname and the port of the destination machine.
  • [USER@]SERVER_IP - The remote SSH user and server IP address.
ssh -L 5901:127.0.0.1:5901 -N -f user@remote.host

The -f option tells the ssh command to run in the background and -N not to execute a remote command. We are using localhost because the VNC and the SSH server are running on the same host.

远程转发:

ssh -R [REMOTE:]REMOTE_PORT:DESTINATION:DESTINATION_PORT [USER@]SSH_SERVER
  • [REMOTE:]REMOTE_PORT - The IP and the port number on the remote SSH server. An empty REMOTE means that the remote SSH server will bind on all interfaces.
  • DESTINATION:DESTINATION_PORT - The IP or hostname and the port of the destination machine.
  • [USER@]SERVER_IP - The remote SSH user and server IP address.
GatewayPorts yes

允许从外部访问远程主机转发端口

ssh -R 8080:127.0.0.1:3000 -N -f user@remote.host

The command above will make the ssh server listen on port 8080, and tunnel all traffic from this port to your local machine on port 3000.

https://linuxize.com/post/how-to-setup-ssh-tunneling/