1

I am trying to play with socat to simulate a DNS request on localhost. Here is what I did setup DNS server on localhost port 15353 and once request received on 15353, it will forword it to google's DNS server 8.8.8.8:53

socat -v -v TCP-LISTEN:15353,reuseaddr,fork UDP:8.8.8.8:53

Send DNS request on same localhost using dig, specify request port to 15353

dig +tcp example.com @localhost -p 15353

Below are the response I got

On socat server terminal

socat -v -v TCP-LISTEN:15353,reuseaddr,fork UDP:8.8.8.8:53
> 2023/01/24 12:46:13.030249  length=54 from=0 to=53
.4... ........\aexample.com.......).......\f.
.\b........> 2023/01/24 12:46:23.029623  length=54 from=0 to=53
.4.i. ........\aexample.com.......).......\f.
.\b........> 2023/01/24 12:46:49.002657  length=54 from=0 to=53
.4.k. ........\aexample.com.......).......\f.
.\b...Q...0> 2023/01/24 12:46:59.001639  length=54 from=0 to=53
.4... ........\aexample.com.......).......\f.
.\b...Q...0> 2023/01/24 12:47:09.001787  length=54 from=0 to=53
.4E.. ........\aexample.com.......).......\f.

On dig client terminal

dig +tcp example.com @localhost -p 15353
; <<>> DiG 9.16.1-Ubuntu <<>> +tcp example.com @localhost -p 15353
;; global options: +cmd
;; connection timed out; no servers could be reached

Anything wrong on my command ?

Jia
  • 2,417
  • 1
  • 15
  • 25
  • @dest-unreach thank you for pointing out , I changed the address but still the same error occur . PS: I corrected IP in my post also. – Jia Jan 24 '23 at 12:53
  • 1
    DNS over TCP and over UDP are not compatible. DNS over TCP prepends every query and answer with 2 bytes message length, so the peer can reconstruct the packet boundaries from the stream. There exists a utility udp2tcp for this conversion. – dest-unreach Jan 24 '23 at 14:22

1 Answers1

1

Here is the working solution- using socat on UDP set up socat DNS server redirect on localhost(127.0.0.1):

sudo socat -v -v udp4-listen:15353,reuseaddr,fork udp4:8.8.8.8:53

use dig to ask for DNS of newsblur.com on port 15353 on localhost(127.0.0.1)

dig  newsblur.com @127.0.0.1 -p 15353

; <<>> DiG 9.16.1-Ubuntu <<>> newsblur.com @127.0.0.1 -p 15353
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21179
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;newsblur.com.          IN  A

;; ANSWER SECTION:
newsblur.com.       220 IN  A   128.242.245.221

;; Query time: 4 msec
;; SERVER: 127.0.0.1#15353(127.0.0.1)
;; WHEN: Tue Jan 24 18:16:05 CST 2023
;; MSG SIZE  rcvd: 46

The previous solution didn't work , seems because I was trying to transfer TCP to UDP ? I am not very sure yet , still figuring out why

Jia
  • 2,417
  • 1
  • 15
  • 25