LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-13-2008, 01:47 PM   #1
Kage_
LQ Newbie
 
Registered: Dec 2008
Location: Texas
Posts: 3

Rep: Reputation: 0
IPTables: block all dns requests except to the server(s) I specify


Hello,

I have been search for an answer for a while to this question so I hope that someone may have an answer.

I have a Linksys router running DD-WRT using OpenDNS instead of my ISPs DNS servers. I'm using OpenDNS mainly due to it's free filtering capabilities. Now I know that if a user is savy enough all they have to do is manually define there DNS servers on there machine and bypass the filtering.

What I would like to do is block all DNS requests on port 53, TCP/UDP, except to the servers that I specify which will be 208.67.222.222 and 208.67.220.220. This will prevent users from using an alternate DNS server and bypassing the filtering.

I'm new to IPTables, I can look at them and understand what the current tables are doing, but I'm having a hard time figuring out if I can even do what I want to do. Any help would be greatly appreciated. Also, if you can point me to some good starter tutorials for IPTables that would be great!

Thanks,

Kage_
 
Old 12-13-2008, 02:56 PM   #2
Kage_
LQ Newbie
 
Registered: Dec 2008
Location: Texas
Posts: 3

Original Poster
Rep: Reputation: 0
Ok I have been playing and I'm not sure if this is correct at least it's a start. I'm not sure which chain I should insert the jump command into. The OUTPUT or possibly the FORWARD chain.

Code:
#Create Chain RejectDNS
iptables -N RejectDNS
#Set default to DROP
iptables -P RejectDNS DROP
#Specify allowed DNS servers drop any other requests
iptables -A RejectDNS -p tcp --dport 53 -d 208.67.222.222 -j ACCEPT
iptables -A RejectDNS -p tcp --dport 53 -d 208.67.220.220 -j ACCEPT
iptables -A RejectDNS -p udp --dport 53 -d 208.67.222.222 -j ACCEPT
iptables -A RejectDNS -p udp --dport 53 -d 208.67.220.220 -j ACCEPT
#Upon matching Jump from the Forward? Output? chain to the RejectDNS chain
iptables -A FORWARD -p tcp --dport 53 -j RejectDNS
iptables -A FORWARD -p udp --dport 53 -j RejectDNS

Last edited by Kage_; 12-13-2008 at 03:09 PM.
 
Old 12-14-2008, 01:45 PM   #3
Kage_
LQ Newbie
 
Registered: Dec 2008
Location: Texas
Posts: 3

Original Poster
Rep: Reputation: 0
Well I ended up with the command below, but it doesn't seem to be working. If I define another DNS server manually, besides the two OpenDNS servers, the DNS request is still making it through the firewall. Any help would be appreciated.

Code:
#Create Chain RejectDNS
iptables -N RejectDNS
#Flush Table
iptables -F RejectDNS
#Set default to DROP
iptables -P RejectDNS DROP
#Specify allowed DNS servers drop any other requests
iptables -A RejectDNS -p tcp --dport 53 -d 208.67.222.222 -j ACCEPT
iptables -A RejectDNS -p tcp --dport 53 -d 208.67.220.220 -j ACCEPT
iptables -A RejectDNS -p udp --dport 53 -d 208.67.222.222 -j ACCEPT
iptables -A RejectDNS -p udp --dport 53 -d 208.67.220.220 -j ACCEPT
#Upon matching Jump from the Forward? Output? chain to the RejectDNS chain
#iptables -A OUTPUT -p tcp --dport 53 -j RejectDNS
#iptables -A OUTPUT -p udp --dport 53 -j RejectDNS
 
Old 12-14-2008, 05:42 PM   #4
Tinker06
LQ Newbie
 
Registered: Apr 2006
Location: Poulsbo, WA
Distribution: Debian
Posts: 5

Rep: Reputation: 1
I was about to use my favorite iptables tool to produce an answer for you - then I noticed your interest in tutorials as well, so here is a much better answer:

fwbuilder

Install this package and play with it a bit. It may seem more involved than you need for this one problem, but I bet you fiddle with iptables much more when you see what complete code this tool generates while making it easy for you to see what it's doing. If you're trying to control creative users and/or hackers, this tool will become your best friend.

Cheers
 
Old 08-25-2019, 02:18 PM   #5
dzmanto
LQ Newbie
 
Registered: Aug 2019
Posts: 1

Rep: Reputation: Disabled
My fix to the dns issue

Here's what I did using iptables on a Ubuntu 18.04 machine:

Code:
#iptables -A OUTPUT -d 208.67.222.123 -p udp -m udp --dport 53 -j ACCEPT 
#iptables -A OUTPUT -d 208.67.220.123 -p udp -m udp --dport 53 -j ACCEPT 
#iptables -A OUTPUT -p udp -m udp --dport 53 -j DROP
The solution can be made permanent by adding the following lines to /etc/iptables/rules.v4:

Code:
-A OUTPUT -d 208.67.222.123 -p udp -m udp --dport 53 -j ACCEPT 
-A OUTPUT -d 208.67.220.123 -p udp -m udp --dport 53 -j ACCEPT 
-A OUTPUT -p udp -m udp --dport 53 -j DROP
Those lines are finally enabled by calling:

Code:
#iptables-restore < /etc/iptables/rules.v4
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Minime server with IPtables forwarding. How to block www by host or IP? AndrzejL Linux - Networking 5 01-06-2009 05:05 AM
Iptables - Block DNS Fredde87 Linux - Networking 5 12-05-2008 08:52 AM
How To Block PPPOE Requests ALInux Linux - Security 2 02-04-2007 12:47 AM
DNS security / primary names server down after large number of requests rioguia Linux - Security 4 10-08-2004 10:00 AM
DNS security / primary names server down after large number of requests rioguia Linux - Networking 1 10-07-2004 11:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration