DNS resolution with socks proxy in ubuntu

Saeed
2 min readNov 29, 2023

--

In some of linux distributions like ubuntu you can’t simply use your socks proxy for DNS resolution, in this article I’ll show you how you can do it, so keep reading!

Wait !! Why should we use socks proxy for DNS at all ?!
-
To prevent DNS leak
- To prevent DNS hijacking (It’s a common thing in the countries with internet censorship)

There are some alternative ways to do it but we are going to use jtripper/dns-tcp-socks-proxy as a DNS tunnel tool, It was written in C, so we need gcc to compile it, let’s build it from its source:

sudo su
apt install git build-essential
git clone https://github.com/jtripper/dns-tcp-socks-proxy.git /opt/dns-tcp-socks-proxy
cd /opt/dns-tcp-socks-proxy
make

Now you have the dns_proxy executable file.
Before running it you need to edit dns_proxy.conf first:

socks_port = 2080
socks_addr = 127.0.0.1
listen_addr = 127.0.0.1
listen_port = 53
set_user = root
set_group = root
resolv_conf = /opt/dns-tcp-socks-proxy/resolv.conf
log_file = /dev/null

There is another file called resolv.conf which is a list of DNS servers, you can customize it for yourself
Now you can run it: (You have to run it with root user)

/opt/dns-tcp-socks-proxy/dns_proxy /opt/dns-tcp-socks-proxy/dns_proxy.conf
[*] Listening on: 127.0.0.1:53
[*] Using SOCKS proxy: 127.0.0.1:2080
[*] Will drop priviledges to root:root
[*] Loaded 10 DNS servers from resolv.conf.

[*] No errors, backgrounding process.

That’s it !! You can test it by nslookup command:

nslookup youtube.com

Output should be like:

Server:  127.0.0.1
Address: 127.0.0.1#53

Non-authoritative answer:
Name: youtube.com
Address: x.x.x.x
...

Please note that ubuntu default nameserver is 127.0.0.53#53 but the Address here is 127.0.0.1#53 which confirms that our DNS tunnel is working correctly :)

--

--