LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 11-06-2011, 12:44 AM   #1
Mavman
Member
 
Registered: Mar 2008
Distribution: Debian
Posts: 44

Rep: Reputation: 1
iptables & NFS question


Hey guys, hoping someone can clarify some things for me, couldn't seem to get a decent answer.

I had iptables setup with just two rules --
Code:
INPUT -s 192.168.1.0/24 -j ACCEPT
INPUT -j REJECT
My assumption is that would essentially allow all traffic on the local LAN, and nothing else.

Yet with that, if I create an NFS export and restart the NFS service, it totally hangs on NFS Quotas (which aren't configured).

I'm doing this on CentOS 6. I have been able to clear the error altogether by adding this line inbetween the two above --
Code:
INPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
I guess I thought that line shouldn't have mattered if I'm set to just accept anything coming from the subnet anyways, can anyone teach me something new as to why that is or how iptables works so I can be more efficient in the future?

Last edited by Mavman; 11-06-2011 at 01:10 AM. Reason: Clarifying code
 
Old 11-06-2011, 01:06 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
To the best of my knowledge there is no "DENY" target in iptables.
Are you getting a "target doesnt exist" type error when creating that rule?

You would want to use the DROP, or REJECT targets.

iptables wont make restarting nfs hang. That is most likely a configuration problem with NFS.
 
Old 11-06-2011, 01:10 AM   #3
Mavman
Member
 
Registered: Mar 2008
Distribution: Debian
Posts: 44

Original Poster
Rep: Reputation: 1
I'm sorry, I did that from memory, and you are correct, it was actually a REJECT statement. (I edited the original post to reflect that.)
It isn't going to be an issue with NFS I don't think, considering the entire file contains the one line -
Code:
/directory 192.168.1.*(rw,sync)
Without iptables on, that works like a champ, if I turn iptables on and I just have the two lines, it hangs.
Seriously, I challenge anyone to try this. I would really like to know.
 
Old 11-06-2011, 01:30 AM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
So it works if you have the NEW,RELATED,ESTABLISHED rule?

I havent had much to do with simplified sets of rules such as this, ive always used full sets of rules that have generally had a REL/EST rule in there anyway. But i THINK it shouldnt matter if you are matching anything from that subnet regardless of its state.

What is the actual problem, that nfs-server wont restart, with iptables rules in place?
or that the client cant connect due to iptables rules?

Try
Code:
watch iptables -nvL
and trying to connect from the client, then watching the packet/byte counters, to see which rule its hitting, if any.
 
Old 11-06-2011, 01:44 AM   #5
Mavman
Member
 
Registered: Mar 2008
Distribution: Debian
Posts: 44

Original Poster
Rep: Reputation: 1
Yeah, it works fine with that rule in place.

The problem is the service doesn't even start. If you do that first method, and then do an NFS restart, it hangs on 'Starting NFS quotas:', after a few minutes it fails.
Then it goes to 'Starting NFS daemon:' and after a very long time, that fails as well. If you turn off iptables, it works fine.

I don't do many simple iptable configs either, but this was for a special project and thus I would like it clarified somehow so I better know how it works, it just doesn't seem right to me to HAVE to have that other rule in order for this to work.

Edit: Here's the output from after the NFS Daemon fails -
Code:
Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 110 (Connection timed out)
rpc.nfsd: unable to set any sockets for nfsd
But I still don't understand why that rule allows it the ability to create sockets?

Last edited by Mavman; 11-06-2011 at 01:59 AM. Reason: More info
 
Old 11-06-2011, 01:23 AM   #6
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
what does iptables -nvL give you?

I dont understand the default RHEL/CentOS iptables setup (RH-FIREWALL whatever it is) these days. As i use my own which is somewhat different.

Quote:
In order for NFS to work with a default installation of Red Hat Enterprise Linux with a firewall enabled, IPTables with the default TCP port 2049 must be configured. Without proper IPTables configuration, NFS does not function properly.
The NFS initialization script and rpc.nfsd process now allow binding to any specified port during system start up. However, this can be error prone if the port is unavailable or conflicts with another daemon.
http://www.centos.org/docs/5/html/De...US/ch-nfs.html

Maybe CentOS 6 is loading some extra firewall rules itself that are blocking rpcbind/portmap, and then you are adding your rules on top of them?

http://forums.fedoraforum.org/showpo...36&postcount=2 may be of some help..
 
Old 11-06-2011, 01:35 AM   #7
Mavman
Member
 
Registered: Mar 2008
Distribution: Debian
Posts: 44

Original Poster
Rep: Reputation: 1
The 'iptables -nvL' just list those two rules under input, all other chains are empty.

The first rule should enable that tcp 2049 deal, I tried creating an explicit rule for it anyways, same result. I also was able to verify that rpcbind is indeed running before I try to restart the service. As this is CentOS 6, it's based off RHEL 6 and using NFSv4 if that helps at all. I didn't see anything new in the Centos manual.

I sincerely thank you for your help regardless fuwaki1, thanks.
 
Old 11-06-2011, 01:45 AM   #8
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
Im out of ideas.
If it works with the NEW,REL,EST rule in there, i say let it work. :-P

Maybe someone more knowledge-able than me will chime in
 
Old 11-06-2011, 09:30 AM   #9
Mavman
Member
 
Registered: Mar 2008
Distribution: Debian
Posts: 44

Original Poster
Rep: Reputation: 1
Thanks anyways fukawi, if anyone has any other ideas, I'm completely open, I'd really like to know why that's the case.


Side note: I thought about it a bit more and since sockets are made locally, it would appear it can also work if you add-
Code:
-I INPUT 2 -s 127.0.0.0/8 -j ACCEPT
That just allows the localhost through the firewall, and that also appears to resolve it, I'm still pretty confused as to why that'd be necessary however because the original fix doesn't allow it through that subnet either, so two difference methods to fix the same issue. Can someone clear it up for me please?

Last edited by Mavman; 11-06-2011 at 10:22 AM. Reason: New info
 
Old 11-07-2011, 12:44 PM   #10
unixfool
Member
 
Registered: May 2005
Location: Northern VA
Distribution: Slackware, Ubuntu, FreeBSD, OpenBSD, OS X
Posts: 782
Blog Entries: 8

Rep: Reputation: 158Reputation: 158
Mavman,

Which ports are you allowing for NFS? All I saw was 2049/tcp.

On researching, you should probably allow the following ports:

sunrpc 111/tcp rpcbind #SUN Remote Procedure Call
sunrpc 111/udp rpcbind #SUN Remote Procedure Call
nfsd-status 1110/tcp #Cluster status info
nfsd-keepalive 1110/udp #Client status info
nfsd 2049/tcp nfs # NFS server daemon
nfsd 2049/udp nfs # NFS server daemon
lockd 4045/udp # NFS lock daemon/manager
lockd 4045/tcp

At the very least, allow 111/tcp, 111/udp, 2049/tcp, and 2049/udp. See if that helps.

Last edited by unixfool; 11-07-2011 at 12:45 PM.
 
Old 11-07-2011, 01:12 PM   #11
Mavman
Member
 
Registered: Mar 2008
Distribution: Debian
Posts: 44

Original Poster
Rep: Reputation: 1
But that's the thing, it's allowing everything with a source in that subnet, so all those ports would be included anyways regardless. Also just a quick reminder, I do know that I can fix it by using the state rules or by adding the localhost to it, I just wanted a better explanation on why it works in that fashion because I would have assumed the source rule I listed to be enough.
 
Old 11-07-2011, 01:24 PM   #12
unixfool
Member
 
Registered: May 2005
Location: Northern VA
Distribution: Slackware, Ubuntu, FreeBSD, OpenBSD, OS X
Posts: 782
Blog Entries: 8

Rep: Reputation: 158Reputation: 158
Quote:
Originally Posted by Mavman View Post
But that's the thing, it's allowing everything with a source in that subnet, so all those ports would be included anyways regardless. Also just a quick reminder, I do know that I can fix it by using the state rules or by adding the localhost to it, I just wanted a better explanation on why it works in that fashion because I would have assumed the source rule I listed to be enough.
At this point, it shouldn't hurt to add to the firewall the specifics about tcp/udp and the ports involved. You might HAVE to be specific in this regard, especially since it seems you can't get this running successfully.

You can check the the FW logs to see why you can't get NFS working. You can also run a tcpdump to check this (either on the FW or wherever the NFS service is being run, if this is a remote server...or both).

You might also be able to check to see if there's an issue with NFS itself by looking at the log files. Or, disable the firewall and see if NFS works then (do this to get a good idea if it's a FW issue or an NFS issue).

I can try to test this on one of my test machines.
 
Old 11-07-2011, 01:42 PM   #13
Mavman
Member
 
Registered: Mar 2008
Distribution: Debian
Posts: 44

Original Poster
Rep: Reputation: 1
Again, I can get it to run successfully, just fine, with the '-m state --state NEW,ESTABLISHED,RELATED -j ACCEPT' or the '-s 127.0.0.0/8 -j ACCEPT' commands, which is a lot easier than making a bunch of port rules, I just wanted clarification on why it works in this manner for the purpose of being able to write more efficient firewall rules...

Also, I mentioned that NFS was dumping because of a socket error, in which it failed to create a local socket. Yes it involves binding the port to the IP, but if the IP range altogether is allowed then it shouldn't matter, additionally it's not even a full blown connection between two nodes, just the socket itself cracks up.

There is no issue with NFS, if iptables is disabled then it works fine. Also you don't have to go out of your way to test on your machines, I thank you though. I just was wondering if anyone had any more information as to why the loopback & state rules cleared up issues with just creating local sockets.
 
Old 11-07-2011, 05:53 PM   #14
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,376

Rep: Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756
I am wondering whether this is to do with packet fragmentation. According to the NFS-HOWTO, NFS will not work unless packet fragments can traverse the firewall.
 
Old 11-07-2011, 05:56 PM   #15
Mavman
Member
 
Registered: Mar 2008
Distribution: Debian
Posts: 44

Original Poster
Rep: Reputation: 1
Er, which source are you getting that from? I'd be interested in a good read if you have something available.


EDIT: http://nfs.sourceforge.net/nfs-howto/ -- Found it, please ignore my ignorance, thanks. :/

Last edited by Mavman; 11-07-2011 at 06:01 PM.
 
  


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
NFS through iptables jnojr Linux - Networking 2 09-12-2008 02:12 PM
Allowing NFS in IPTABLES: Fix port for NFS Lock Manager Swakoo Linux - General 10 08-25-2006 05:24 AM
nfs and iptables muumi Linux - General 0 08-15-2006 02:31 PM
NFS and IPTables? german Linux - Networking 3 11-11-2003 08:25 AM
Help w/ nfs and iptables Newbie Chris Linux - Networking 5 03-19-2003 03:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 11:56 PM.

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