LinuxQuestions.org
Visit Jeremy's Blog.
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 01-25-2014, 06:25 PM   #1
mulberry_pi
LQ Newbie
 
Registered: Jan 2014
Posts: 2

Rep: Reputation: Disabled
iptables config to restrict some NATed traffic


Hi All,

I've just setup a RaspberryPI using Raspbian as a Wireless access point. Traffic from wlan0 gets forwarded to eth0 (which is plugged into my router) and the traffic goes out to the web. All good.

I'm trying to restrict the traffic so DNS requests can only go to specific DNS servers. From the man pages and reading, I think I know what I need to do - explicitly allow tcp and udp on port 53 for just a particular address and block everything else. Something like this:

-A FORWARD -d 8.8.8.8 -i wlan0 -o eth0 -p udp -m udp --dport 53 -j ACCEPT
-A FORWARD -d 8.8.8.8 -i wlan0 -o eth0 -p tcp -m tcp --dport 53 -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -p udp -m udp --dport 53 -j DROP
-A FORWARD -i wlan0 -o eth0 -p tcp -m tcp --dport 53 -j DROP

When I do that, all the traffic is still let through. I'm a little unclear on where the rules go - filter or nat? And whether order is important. And whether any of the 'allow all rules' override the DROP ones.

Here's what I have now in ip tables and I restore this using iptables-restore


# Generated by iptables-save v1.4.14 on Sat Jan 25 11:41:20 2014
*nat
:PREROUTING ACCEPT [9390:898244]
:INPUT ACCEPT [4509:271576]
:OUTPUT ACCEPT [257:19408]
:POSTROUTING ACCEPT [23:1600]
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Sat Jan 25 11:41:20 2014
# Generated by iptables-save v1.4.14 on Sat Jan 25 11:41:20 2014
*filter
:INPUT ACCEPT [925:62130]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [561:116190]
-A FORWARD -d 8.8.8.8/32 -i wlan0 -o eth0 -p udp -m udp --dport 53 -j ACCEPT
-A FORWARD -d 8.8.8.8/32 -i wlan0 -o eth0 -p tcp -m tcp --dport 53 -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -p udp -m udp --dport 53 -j DROP
-A FORWARD -i wlan0 -o eth0 -p tcp -m tcp --dport 53 -j DROP
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
COMMIT
# Completed on Sat Jan 25 11:41:20 2014

Any help appreciated.

Last edited by mulberry_pi; 01-25-2014 at 06:26 PM.
 
Old 01-25-2014, 06:33 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,348

Rep: Reputation: Disabled
The order is important, as the rules are checked from top to bottom. A "DENY" rule below an "ACCEPT" rule for the same type of traffic (or vice versa) will have no effect.

Your FORWARD chain only drops one type of traffic: DNS traffic (packets to TCP or UDP port 53) to servers other than 208.67.222.222. Everything else is allowed, as the chain policy is ACCEPT. The policy affects any packet for which no other matching rule was found.

Since you're blocking/allowing traffic, the rules go in the "filter" table (which is the default). The "nat" table is only for manipulating addresses and port numbers.
 
Old 01-26-2014, 08:41 AM   #3
mulberry_pi
LQ Newbie
 
Registered: Jan 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks Ser Olmy,

OK, so now I have "allow dns to my chosen dns", drop any other dns traffic, allow anything else...

I'm still able to do DNS lookups to any DNS server from devices connecting to wlan0... any other hints?

# Generated by iptables-save v1.4.14 on Sat Jan 25 11:41:20 2014
*nat
:PREROUTING ACCEPT [9390:898244]
:INPUT ACCEPT [4509:271576]
:OUTPUT ACCEPT [257:19408]
:POSTROUTING ACCEPT [23:1600]
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Sat Jan 25 11:41:20 2014
# Generated by iptables-save v1.4.14 on Sat Jan 25 11:41:20 2014
*filter
-A FORWARD -d 8.8.8.8/32 -i wlan0 -o eth0 -p udp -m udp --dport 53 -j ACCEPT
-A FORWARD -d 8.8.8.8/32 -i wlan0 -o eth0 -p tcp -m tcp --dport 53 -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -p udp -m udp --dport 53 -j DROP
-A FORWARD -i wlan0 -o eth0 -p tcp -m tcp --dport 53 -j DROP
:INPUT ACCEPT [925:62130]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [561:116190]
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
COMMIT
# Completed on Sat Jan 25 11:41:20 2014
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Using tc and iptables to restrict download speed DavidPCV Linux - Networking 1 09-17-2010 08:00 PM
Iptables & Kernel Config To Do Conntrack of Bittorrent Traffic mrmnemo Linux - Networking 21 08-05-2010 08:04 AM
[HELP] redirect traffic to spesific port based on Traffic Content using iptables summersgone Linux - Server 2 06-22-2009 12:26 PM
Restrict ssh attempts with iptables Madone_SL_5.5 Linux - Security 5 11-09-2007 04:05 PM
restrict access using squid, iptables? jgnasser Linux - Networking 3 04-13-2005 08:21 AM

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

All times are GMT -5. The time now is 01:35 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