LinuxQuestions.org
Review your favorite Linux distribution.
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 09-21-2009, 05:21 PM   #1
Sum1
Member
 
Registered: Jul 2007
Distribution: Fedora, CentOS, and would like to get back to Gentoo
Posts: 332

Rep: Reputation: 30
Linux Router: Iptables rules and dhcp server on eth1


Installed new linux router for use today, Monday: Slackware 13, 2 nics.

eth0 - to the internet
eth1 - to the LAN (dhcp server is set to listen on this interface)

My iptables policies for INPUT OUTPUT and FORWARD are set to DROP.
I've got about 30 users and all day long, at any given time, about 10% of the LAN clients (Win XP Pro Boxes) had difficulty obtaining ip addresses from the dhcp server.

I've been logging packets and it appears I've found the problem, but I'm wondering if there's a better solution than the one I've implemented.

More specifically, I've been logging like this, and dropping whatever doesn't come from the allowed subnet range:

$IPT -t filter -A INPUT -i $LAN1 ! -s $SUBNET1 -j LOG --log-prefix "SPOOFED PKT"
$IPT -t filter -A INPUT -i $LAN1 ! -s $SUBNET1 -j DROP

And I've been ending up with lots of this in the log:

Sep 21 17:19:16 joejoe kernel: SPOOFED PKTIN=eth1 OUT= MAC=(deleted to protect the innocent here)SRC=0.0.0.0 DST=255.255.255.255 LEN=332 TOS=0x00 PREC=0x00 TTL=128 ID=1 PROTO=UDP SPT=68 DPT=67 LEN=312


It seems like these dhcp requests are seen as spoofed packets, and it's happening as part of the natural course of a dhcp client calling out for an ip address, but not yet possessing a an address within the specified address range stated in the iptables rule.

The only thing that appears to have eased the problem is changing the second rule stated above to:

$IPT -t filter -A INPUT -i $LAN1 -j ACCEPT

and also adding the following rule in the OUTPUT chain:
$IPT -t filter -A OUTPUT -o $LAN1 -j ACCEPT

However, both of these cause me some security concerns and I'm not sure if it's good practice to open up the LAN interface to all incoming data.

Is there a better way?

- - - - - - - - - -
Also, a subsequent but related question: In order to facilitate dhcp clients obtaining ip addresses from LAN-side dhcp server, do I need to enable certain rules on the FORWARD chain?

Currently, I have these enabled but I don't know if they are even necessary (remember, my FORWARD policy is set to DROP):

$IPT -t filter -A FORWARD -m state --state INVALID -j LOG --log-prefix "DROP INVALID" --log-ip-options --log-tcp-options
$IPT -t filter -A FORWARD -m state --state INVALID -j DROP
$IPT -t filter -A FORWARD -i $LAN1 -p udp -s $SUBNET1 --dport 67 -j ACCEPT
$IPT -t filter -A FORWARD -i $LAN1 -p udp -s $SUBNET1 --dport 68 -j ACCEPT
$IPT -t filter -A FORWARD -i $LAN1 -m state --state NEW -p tcp -s $SUBNET1 --dport 67 -j ACCEPT
$IPT -t filter -A FORWARD -i $LAN1 -m state --state NEW -p tcp -s $SUBNET1 --dport 68 -j ACCEPT
$IPT -t filter -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPT -t filter -A FORWARD -i $LAN1 ! -s $SUBNET1 -j DROP


Thanks for your time and help.
 
Old 09-23-2009, 02:25 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
It's quite obvious why all the dhcp request are logged by your "not-our-subnet" rule cause the come from 0.0.0.0 which sure is not in your subnet
You could just build a rule to get them before reaching the "not our subnet" rule like this

Code:
iptables -A INPUT -s 0.0.0.0 -d 255.255.255.255 -p udp --sport 67 --dport 68 -j DHCP-rule-chain
or just accept them. (-j ACCEPT).

For the question where to put the
Code:
$IPT -t filter -A FORWARD -i $LAN1 -p udp -s $SUBNET1 --dport 67 -j ACCEPT
$IPT -t filter -A FORWARD -i $LAN1 -p udp -s $SUBNET1 --dport 68 -j ACCEPT
$IPT -t filter -A FORWARD -i $LAN1 -m state --state NEW -p tcp -s $SUBNET1 --dport 67 -j ACCEPT
$IPT -t filter -A FORWARD -i $LAN1 -m state --state NEW -p tcp -s $SUBNET1 --dport 68 -j ACCEPT
you have I'd go for the INPUT part. See the forward rule is used when you forward packages, but I think you need to accept the packages on the very server.
I always helped my self out with something like this to see how packages traverse the iptables rules and chains.

Code:
iptables -A INPUT -j LOG --log-prefix="INPUT chain"
iptables -A OUTPUT -j LOG --log-prefix="OUTPUT chain"
iptables -A FORWARD -j LOG --log-prefix="FORWARD chain"

iptables -t mangle -A INPUT -j LOG --log-prefix="mangle INPUT chain"
....
....
and tail -f the logfile.
Somewhere in /proc/net/ there is a file with all the legal targets and chains for iptables. (I'm just to lazy to look for it).

Cheers Zhjim

Last edited by zhjim; 09-24-2009 at 02:04 AM. Reason: wrong names for log-prefix
 
Old 09-23-2009, 04:12 PM   #3
Sum1
Member
 
Registered: Jul 2007
Distribution: Fedora, CentOS, and would like to get back to Gentoo
Posts: 332

Original Poster
Rep: Reputation: 30
Zhjim, thanks for your thoughtful help.

Here's the solved,functional, and simplified result:

$IPT -t filter -A INPUT -i $LAN1 ! -s $SUBNET1 -j LOG --log-prefix "SPOOFED PKT"
$IPT -t filter -A INPUT -i $LAN1 -j ACCEPT

echo "ouput"
$IPT -t filter -A OUTPUT -m state --state INVALID -j LOG --log-prefix "DROP INVALID" --log-ip-options --log-tcp-options
$IPT -t filter -A OUTPUT -m state --state INVALID -j DROP
$IPT -t filter -A OUTPUT -o $SKYWAY -j ACCEPT
$IPT -t filter -A OUTPUT -o $LAN1 -j ACCEPT

echo "forward"
$IPT -t filter -I FORWARD -i $SKYWAY -s 127.0.0.0/8 -j DROP
$IPT -t filter -I FORWARD -i $SKYWAY -s 192.168.0.0/16 -j DROP
$IPT -t filter -I FORWARD -i $SKYWAY -s 10.0.0.0/8 -j DROP


$IPT -t filter -A FORWARD -m state --state INVALID -j LOG --log-prefix "DROP INVALID" --log-ip-options --log-tcp-options
$IPT -t filter -A FORWARD -m state --state INVALID -j DROP
$IPT -t filter -A FORWARD -i $LAN1 -p udp -s $SUBNET1 --dport 137 -j ACCEPT
$IPT -t filter -A FORWARD -i $LAN1 -p udp -s $SUBNET1 --dport 138 -j ACCEPT

$IPT -t filter -A FORWARD -i $LAN1 -p tcp -s $SUBNET1 --dport 139 -j ACCEPT
$IPT -t filter -A FORWARD -i $LAN1 -p tcp -s $SUBNET1 --dport 445 -j ACCEPT

$IPT -t filter -A FORWARD -i $SKYWAY -o $LAN1 -j ACCEPT
$IPT -t filter -A FORWARD -i $LAN1 -o $SKYWAY -j ACCEPT

the last two FORWARD rules facilitate destination routing to a few servers behind the firewall. They are needed to deal with my overall DROP policy in the FORWARD chain.

I'm definitely going to follow up on the tail -f logging example.

Great stuff.
Thanks for your time.
 
Old 09-24-2009, 02:10 AM   #4
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Hm I don't see now DHCP rules
I'd also say your Forward rules for the machine itself are a bit to open. There should be no need to forward traffic coming from the local interface (127.0.0.1). Also you should accept traffic coming from there.

I just diged up one of my favorite iptables script on the net
http://homelansecurity.sourceforge.net/index.php
This really help me to get the hang on good, paranoid but also simple iptable rules.

Cheers Zhjim
 
Old 09-24-2009, 01:13 PM   #5
Sum1
Member
 
Registered: Jul 2007
Distribution: Fedora, CentOS, and would like to get back to Gentoo
Posts: 332

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by zhjim View Post
Hm I don't see now DHCP rules
Ya true, I only posted the relevant portions that needed work; it's not the whole firewall.

Quote:
I'd also say your Forward rules for the machine itself are a bit to open. There should be no need to forward traffic coming from the local interface (127.0.0.1).
No worries, the rule is a DROP, not accepting the forward --
$IPT -t filter -I FORWARD -i $SKYWAY -s 127.0.0.0/8 -j DROP

I like that HLS site, very good stuff to help follow the logic of chain statements from beginning to end. Thanks.
 
Old 09-25-2009, 03:05 AM   #6
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by Sum1 View Post
No worries, the rule is a DROP, not accepting the forward --
$IPT -t filter -I FORWARD -i $SKYWAY -s 127.0.0.0/8 -j DROP
Ups my bad. Go ahead
 
  


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
Dhcp server and iptables (linux machine as a router) raksh agrawal Linux - Networking 1 09-19-2009 06:38 AM
Instead of Router DHCP Server, Pass DHCP Server control to Slackware orbit Slackware 6 05-11-2009 02:00 AM
dhcp server - can't figure out dhclient.conf for eth1 JoeBleaux Debian 1 04-06-2009 05:13 PM
iptables rules for web server email server,ftp and ssh,please help lightwing Linux - Networking 1 03-25-2009 08:58 PM
DHCP using eth1 for internet eht0 for router... Zero-0-Effect Linux - Networking 12 01-17-2004 04:06 PM

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

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