Performing UDP tunneling through an SSH connection
Intro
The Swiss ISP 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's network internal DNS services (UDP port 53) with only SSH access to it. We will forward local UDP/53 traffic to TCP, then TCP traffic with the port-forwarding mechanism of SSH to the other machine, then TCP to UDP/53 on the other end. Typically, you can do it with . But here, we'll do it with simpler tools, only and .
[@more@]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:localhost:6667 server
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's IP you will find in /etc/resolv.conf - in this example, this is 192.168.1.1. But first, we need to create a fifo. The fifo is necessary to have two-way communication between the two channels. A simple shell pipe would only communicate left process' standard output to right process' standard input.
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's port 6667 to be forwarded to UDP traffic on 192.168.1.1's port 53, and responses to come back.
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's port 53 to be forwarded to TCP traffic on local machine's port 6667.
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's TCP port 6667, then to server's DNS server, UDP port 53 of 192.168.1.1. To test DNS service on your local machine, use host:
# host m6.fr 127.0.0.1
If the address is resolved, you can put the following line in your /etc/resolv.conf so that your first nameserver is actually you own machine:
nameserver 127.0.0.1
Alternative solution with socat
Brian Marshall has an alternative solution using . It eliminates the fifo file requirement. Here's how to do:
Server side: socat tcp4-listen:5353,reuseaddr,fork UDP:nameserver:53
Client side: socat udp4-listen:53,reuseaddr,fork tcp:localhost:5353
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/653579/viewspace-1026824/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ascp: Failed to open TCP connection for SSH, exiting. Session Stop (Error: Failed to open TCP connection for SSH)AITCPSessionError
- Solaris SSH 服務處於maintenance模式,ssh connection refusedAINaN模式
- SSH出現Connection refused錯誤
- ssh: connect to host localhost port 22: Connection refusedlocalhost
- Performing a Failover to a Physical Standby DatabaseORMAIDatabase
- 坑:ssh: connect to host github.com port 22: Connection refusedGithub
- 異常解決——GitLab : ssh: connect to host port 22: Connection refusedGitlab
- 執行systemctl status ssh返回“Failed to get properties: Connection timed out”AI
- 解決 ssh connect to host github.com port 22 Connection timed outGithub
- 免密scp解決ssh_exchange_identification:read connection reset by peer 原因IDE
- ubuntu ssh: connect to host ** port 22: Connection refused ssh登入遠端伺服器時提示Permission denied (publickey,password)Ubuntu伺服器
- Oracle報performing DMLDDL operation over object in bin案例分析OracleORMObject
- nacos Connection refused (Connection refused)
- Connection
- misdirection靶機work_through
- LamPiao靶機work_throughLAMP
- UdpUDP
- java.net.ConnectException: Connection refused (Connection refused)JavaException
- Through the NBA, clubs players and fans paid their respectsAI
- Unsatisfied dependency expressed through field ‘baseMapper‘ 原因ExpressAPP
- Oracle 12c RMAN Performing Cross-Platform Transport of a PDB Using InconsistentOracleROSPlatform
- socket udpUDP
- Error:Can't connect to SOCKS proxy:Connection refused (Connection refused)Error
- [LeetCode] 524. Longest Word in Dictionary through DeletingLeetCode
- nmcli connection reload
- ssh連線遠端伺服器出現Host key verification failed. lost connection問題的解決伺服器AI
- TCP 和 UDPTCPUDP
- UDP server CodeUDPServer
- UDP與TCPUDPTCP
- TCP和UDPTCPUDP
- TCP與UDPTCPUDP
- TCP vs UDPTCPUDP
- MQTT是TCP還是UDP?TCP與UDP區別MQQTTCPUDP
- 684-Redundant Connection
- yarn socket connection timeoutYarn
- 關於Residual Connection
- 關於隱藏引數:_no_recovery_through_resetlogs
- Error creating bean with name ‘dataSource‘: Unsatisfied dependency expressed through fieldErrorBeanExpress
- Boost UDP Transaction PerformanceUDPORM