How to Use UDP Over an SSH Tunnel

How to Use UDP Over an SSH Tunnel thumbnail
You can bind a local and remote port while establishing an SSH session.

You can tunnel traffic over a secure shell session, effectively using the remote SSH server as an encrypted proxy. SSH only supports tunneling TCP-protocol traffic between computers, but you can use the netcat command to convert UDP-protocol traffic to TCP for transmission. The SSH command can bind traffic on a local port to a remote port. The netcat command on the server computer can convert incoming UDP traffic on a port to TCP traffic on the bound port, where the SSH server sends it to your local computer. The netcat command on your local computer can then convert the TCP traffic back into UDP traffic.

Instructions

    • 1

      Open a terminal on the local computer.

    • 2

      Type the following command into the terminal, replacing “example.com” with the domain name or IP address of the remote computer running the SSH server and press “Enter.” You can use any port number instead of “7777”, but ensure you replace the “7777” in each subsequent command with the port you use in this command.

      ssh -L 7777:localhost:7777 example.com

    • 3

      Log in to the remote SSH server by providing your login information at the prompt.

    • 4

      Type the following command into the SSH session and press “Enter” to execute it on the remote server. This command creates a temporary object that the netcat command uses for communication.

      mkfifo /tmp/fifo

    • 5

      Type the following command into the SSH session and press “Enter” to execute it on the remote server. Replace the “computer” in the command with the IP address or domain name of your computer and replace the “#” with the number of the UDP port you want to forward traffic from.

      nc -l -p 7777 < /tmp/fifo | nc -u computer # > /tmp/fifo

    • 6

      Open a new terminal on the local computer.

    • 7

      Type the following command into the new terminal and press “Enter” to execute it on the local computer:

      mkfifo /tmp/fifo

    • 8

      Type the following command into the local terminal, replacing the “#” with the number of the UDP port you specified earlier, and press “Enter.” After you execute this command, all UDP traffic that reaches the remote SSH server on the specified port is forwarded to your local computer while the SSH session remains open.

      nc -l -u -p # < /tmp/fifo | nc localhost 7777 > /tmp/fifo

Related Searches:

References

  • Photo Credit Medioimages/Photodisc/Photodisc/Getty Images

Comments

Related Ads

Featured