LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-24-2005, 02:09 PM   #1
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Rep: Reputation: 30
iptables to block lan services (audit mine)


Relevant fragment of the startup rules (it's POLICY ACCEPT):
Code:
# Default redirect to gateway
iptables -t nat -A PREROUTING -p tcp -i wlan0 --dport 80 -j DNAT --to 10.0.0.1
iptables -t nat -A PREROUTING -p tcp -i wlan0 ! --dport 80 -j DROP

# Block all those sneaky LAN services
iptables -N LAN_BLOCK
iptables -t filter -A LAN_BLOCK -o wlan0 --match multiport --dport 25 -j DROP
iptables -t filter -A LAN_BLOCK -o wlan0 --match multiport --dport 24 -j DROP
iptables -t filter -A LAN_BLOCK -o wlan0 --match multiport --dport 23 -j DROP
iptables -t filter -A LAN_BLOCK -o wlan0--match multiport  --dport 113 -j DROP
iptables -t filter -A LAN_BLOCK -o wlan0 --match multiport --dport 137:139 -j DROP
iptables -t filter -A LAN_BLOCK -o wlan0 --match multiport --dport 548 -j DROP
iptables -t filter -A LAN_BLOCK -o wlan0 --match multiport --dport 427 -j DROP
iptables -t filter -A LAN_BLOCK -o wlan0 --match multiport --dport 3689 -j DROP
iptables -t filter -A LAN_BLOCK -o wlan0 --match multiport  --dport 8770 -j DROP
And the rule invoked to allow a certain IP address is
Code:
iptables -t nat -I PREROUTING -i wlan0 -s 10.0.0.19 -j LAN_BLOCK
I feel like I'm missing something from the LAN_BLOCK chain. I basically want all services not in LAN_BLOCK to pass through. Is there an ACCEPT or RETURN line I should add at the end?

This is the fruition of much and reading on this forum, thanks everyone, this forum is great!

Last edited by michaelsanford; 04-24-2005 at 04:19 PM.
 
Old 04-25-2005, 07:25 AM   #2
Half_Elf
LQ Guru
 
Registered: Sep 2001
Location: Montreal, Canada
Distribution: Slackware; Debian; Gentoo...
Posts: 2,163

Rep: Reputation: 46
hmmm nice rule there, but I think there is some mistakes.
I dont know --match multiport flag, are you sure this one is valid? Plus, you dont really need multiport if you block ports one by one like you do there.
Then, you seems to be adding your rule to PREROUTING rules (the last firewall line you posted), but I'm not quite sure you can add rules about "filter" table to rules about "nat". I am maybe wrong, but be cautious doing that

You dont really need anything else to allow unmatched trafic there,if you default rules (policy) is set to accept, this should work
 
Old 04-25-2005, 09:44 AM   #3
michaelsanford
Member
 
Registered: Feb 2005
Location: Ottawa/Montréal
Distribution: Slackware + Darwin (MacOS X)
Posts: 468

Original Poster
Rep: Reputation: 30
Thanks for the reply.

Firstly, without --match-multiport for some reason I get an error with --dport. I didn't think I needed it either but it seems that mixing matches (like -s and --dport) seems to need a --match. Anyway, it works that way, but thanks for the observation.

What's wrong with mixing nat and filter table rules since they apple to different chains that are called from each other?
 
Old 04-26-2005, 10:25 AM   #4
Half_Elf
LQ Guru
 
Registered: Sep 2001
Location: Montreal, Canada
Distribution: Slackware; Debian; Gentoo...
Posts: 2,163

Rep: Reputation: 46
You only need multiport when you specify more than 1 port, I think.
About nat table and filter... Nat table isn't used at the same moment or to do the same things as filter, filter is mostly used about local connection and nat, to connection re-routed somewhere else, mixing both is a strange way to do so atmo.
But this is mostly standardisation/programmation concerns, it shouldn't cause any problem. If this work for you, you might want to keep it just like this, it doesnt matter much
 
  


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
IPTables and PPTPD :S (to block or not to block) thewonka Linux - Networking 0 03-24-2005 07:58 PM
IPtables - Block all except what I allow ]SK[ Linux - Software 4 02-10-2005 07:14 AM
Level & Checks block Services (Telnet, VNC...) kt8993 Mandriva 2 10-03-2004 10:35 PM
iptables, block port 80? frank2 Linux - Security 4 09-12-2004 10:14 AM
IPTables to block IP protocol ppuru Linux - Security 3 06-26-2004 03:20 AM

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

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