How to configure your BIND DNS server on a different port no other than 53 in Linux

By default DNS server works on port no. 53 but what if you want to change the default port no. in your machine.

I wanted to give a try if it is possible and if yes then in that case how am I suppose to do that.
Well here is the solution which I found.

The following commands are with respect to RedHat and CentOS so kindly check the commands if you are planning to do the same in any other distribution.

Open up your named.conf and make the following changes

# vi /etc/named.conf
listen-on port 6236 { 127.0.0.1; };
query-source port 6236;

Make sure your firewall and selinux is not blocking the port no. you have selected

# netstat -ntlp | grep 6236
tcp        0     0     10.10.10.30:6236        0.0.0.0:*     LISTEN      32711/named
tcp        0     0     127.0.0.1:6236          0.0.0.0:*     LISTEN      32711/named

[root@server ~]# telnet localhost 6236
Trying ::1...
Connected to localhost.
Escape character is '^]'.

This all means that the port 6236 is open on our system

Now when you have configured your DNS server use the following command to dig your server

# nslookup -po=6236 server.example.com
# dig -p 6236 server.example.com

I hope the article was useful.