tech:tunnel_ssh_udp_forward
Différences
Ci-dessous, les différences entre deux révisions de la page.
| tech:tunnel_ssh_udp_forward [2025/03/24 15:06] – créée - modification externe 127.0.0.1 | tech:tunnel_ssh_udp_forward [2026/05/30 21:48] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Tunnel SSH UDP forward | ||
| + | |||
| + | |||
| + | Source : | ||
| + | http:// | ||
| + | |||
| + | Je me suis servi de cette astuce pour synchro le temps / heure / ntp sur une machine qui ne pouvait pas sortir sur internet | ||
| + | |||
| + | -------- | ||
| + | |||
| + | Performing UDP tunneling through an SSH connection | ||
| + | Intro | ||
| + | |||
| + | The Swiss ISP Bluewin sucks. Their DNS are often down. A friend even received advice from Bluewin technicians to not use their own DNS!... But then, it is quite hard to gain access to another DNS for free, if you don't have access to a co hosted machine. | ||
| + | |||
| + | In this document, we'll access another machine' | ||
| + | Step by step | ||
| + | Open a TCP forward port with your SSH connection | ||
| + | |||
| + | On your local machine (local), connect to the distant machine (server) by SSH, with the additional -L option so that SSH will TCP port-forward: | ||
| + | |||
| + | ~~~ | ||
| + | local# ssh -L 6667: | ||
| + | ~~~ | ||
| + | |||
| + | This will allow TCP connections on the port number 6667 of your local machine to be forwarded to the port number 6667 on server through the secure channel. | ||
| + | Setup the TCP to UDP forward on the server | ||
| + | |||
| + | On the server, we open a listener on the TCP port 6667 which will forward data to UDP port 53 of a specified IP. If you want to do DNS forwarding like me, you can take the first nameserver' | ||
| + | |||
| + | ~~~ | ||
| + | server# mkfifo /tmp/fifo | ||
| + | server# nc -l -p 6667 < /tmp/fifo | nc -u 192.168.1.1 53 > /tmp/fifo | ||
| + | ~~~ | ||
| + | |||
| + | This will allow TCP traffic on server' | ||
| + | Setup the UDP to TCP forward on your machine | ||
| + | |||
| + | Now, we need to do the opposite of what was done upper on the local machine. You need priviledged access to bind the UDP port 53. | ||
| + | |||
| + | ~~~ | ||
| + | local# mkfifo /tmp/fifo | ||
| + | local# sudo nc -l -u -p 53 < /tmp/fifo | nc localhost 6667 > /tmp/fifo | ||
| + | ~~~ | ||
| + | | ||
| + | |||
| + | This will allow UDP traffic on local machine' | ||
| + | Enjoy your local DNS server :) | ||
| + | |||
| + | As you've probably guessed it now, when a DNS query will be performed on the local machine, e.g. on local UDP port 53, it will be forwarded to local TCP port 6667, then to server' | ||
| + | |||
| + | ~~~ | ||
| + | host m6.fr 127.0.0.1 | ||
| + | ~~~ | ||
| + | |||
| + | If the address is resolved, you can put the following line in your / | ||
| + | |||
| + | ~~~ | ||
| + | nameserver 127.0.0.1 | ||
| + | ~~~ | ||
| + | |||
| + | Alternative solution with socat | ||
| + | |||
| + | Brian Marshall and Zakaria have an alternative solution using socat. It eliminates the fifo file requirement. Here's how to do: | ||
| + | |||
| + | Server side: | ||
| + | ~~~bash | ||
| + | socat tcp4-listen: | ||
| + | ~~~ | ||
| + | |||
| + | Client side: | ||
| + | ~~~bash | ||
| + | socat -T15 udp4-recvfrom: | ||
| + | ~~~ | ||
