View Full Version : Remote file mount won't work when pf is enable
hollis2507
December 9th, 2009, 12:00
Hi all,
I have a server and a client. I have set up an NFS server on the server and i can successfully connect to my backup file from my client machine.
My issue is that this will only work with the firewall off. When i turn the firewall on i get
RPCPROG_NFS: RPC: Port mapper failure - RPC: Timed out
I'm not very experienced with the firewalls within BSD. I've tried enabling various ports within the pf.conf but i still have the same issue.
Is there any configuration changes i can make in order to allow this through?
Thanks in advance
graudeejs
December 9th, 2009, 12:05
pass on $ext_if proto { tpc, udp } from any to any port { nfsd, lockd }
i think should work
SirDice
December 9th, 2009, 12:19
NFS is somewhat tricky to firewall. RPC uses different ports each time.
graudeejs
December 9th, 2009, 12:34
In that case you can allow all ports form known to be "secure" hots... [similar to what i did with ftp :D]
hollis2507
December 9th, 2009, 12:46
Thanks for the replies.
I tried
pass on $ext_if proto { tpc, udp } from any to any port { nfsd, lockd }
I got the same error message i quoted in my first post.
You say i can allow all ports from known to be "secure" hosts?
How do i go about doing this?
graudeejs
December 9th, 2009, 12:53
Well... this is probably not good... but for desktop...
I created list of hosts ip addresses.
In my case I created sh script that extracted ftp addresses from ports tree [I need ftp to install ports :) ]
table <ftp_ports_ip_w_list> const file "/etc/ftp_ports_wlist"
...
...
# enable passive ftp
pass out log on $ext_if inet proto tcp from { $ext_ip, <jail_ip_list> } port >1023 to <ftp_ports_ip_w_list> port { ftp, >1023 } group wheel keep state
pass out log on $ext_if inet proto tcp from { $ext_ip, <jail_ip_list> } port >1023 to <ftp_ip_w_list> port { ftp, >1023 } group { users, wheel } keep state
this is from my pf.conf
dennylin93
December 9th, 2009, 13:56
NFS is somewhat tricky to firewall. RPC uses different ports each time.
This might help: nfs_reserved_port_only="YES"?
hollis2507
December 9th, 2009, 14:37
This might help: nfs_reserved_port_only="YES"?
Where does this go? rc.conf?
graudeejs
December 9th, 2009, 14:42
from rc.conf:
nfs_reserved_port_only
(bool) If set to “YES”, provide NFS services only on a secure
port.
answer: yes
phoenix
December 9th, 2009, 17:16
If you control the NFS server, then you can tell all of the NFS utilities to listen to specific ports (search for _flags in /etc/defaults/rc.conf and look at nfs, rpcbind, lockd, statd, and so on).
Then you only have to allow TCP/UDP traffic through on those ports.
For example, on one NFS server, we use the following:
mountd_enable="yes" # Run mountd (or NO).
mountd_flags="-r -h 192.168.0.186 -p 32000" # Flags to mountd (if NFS server enabled)
rpc_lockd_enable="yes" # Run NFS rpc.lockd needed for client/server.
rpc_lockd_flags="-h 192.168.0.186" # Flags to rpc.lockd (if enabled).
rpc_statd_enable="yes" # Run NFS rpc.statd needed for client/server.
rpc_statd_flags="-p 32001" # Flags to rpc.statd (if enabled).
rpcbind_enable="yes" # Run the portmapper service (YES/NO).
rpcbind_flags="-h 192.168.0.186"
nfs_server_enable="yes" # This host is an NFS server (or NO).
nfs_server_flags="-u -t -n 4 -h 192.168.0.186" # Flags to nfsd (if enabled).
graudeejs
December 9th, 2009, 17:30
There's another option... [this is how I solved pf+torrents problem]
create jail with aliased IP run NFS in jail....
allow all traffic to/from that IP....
I wonder what others think about this [perhaps it's totally bad]
SirDice
December 9th, 2009, 17:56
There's another option... [this is how I solved pf+torrents problem]
create jail with aliased IP run NFS in jail....
allow all traffic to/from that IP....
I wonder what others think about this [perhaps it's totally bad]
That's not entirely going to work. IIRC it's mountd that you can't bind to a specific address. Which means it will listen on all addresses, including the ones belonging to other jails and the host itself.
DutchDaemon
December 9th, 2009, 22:25
I think allowing {sunrpc nfsd-status nfsd-keepalive nfsd lockd } should be enough. I normally use {sunrpc nfsd lockd }, which appears to be enough. Note two other things:
1. use no-df (pf.conf) on nfs traffic
2. make sure your nfs host/client can resolve one another correctly (DNS or /etc/hosts)
phoenix
December 10th, 2009, 00:52
That's not entirely going to work. IIRC it's mountd that you can't bind to a specific address. Which means it will listen on all addresses, including the ones belonging to other jails and the host itself.
See my post above. You can set everything to it's own IP, and even lock in the port that most of the NFS-related services can use.
J65nko
December 10th, 2009, 01:55
You see which packets are being blocked withblock log all
The blocked packets will show up on the pflog0 device. Run tcpdump on pflog0 to see the blocked stuff.
BTW If your firewall is a corporate firewall, then the general consensus is to not allow NFS through the firewall. NFS = No File Security ;)
johnblue
December 17th, 2009, 03:59
Run tcpdump on pflog0 to see the blocked stuff.Agreed. Not that I am an expert by any means, but to get a quick snap shot of what is going on I like to use:
tcpdump -n -i pflog0
There are additional switches that you can add to the command and then you can it pipe to grep or whatever you want to do with the output.
honk
December 18th, 2009, 03:41
rc.conf on the nfs-server:
## NFS-Server
rpcbind_enable="YES"
nfs_server_enable="YES"
mountd_flags="-p 789"
pf.conf on the firewall:
pass log quick proto {udp tcp} from 172.16.1.0/24 to 172.16.3.2 port {111 789 2049} keep state
And then mount the nfs with tcp as transport protocol:
mount_nfs -o tcp,rw 172.16.3.2:/data /mnt
Works for me (nfs3).
To explain:
At first the nfs-client contacts the portmapper on the server. The portmapper always runs on port 111 udp and tcp (actually only udp is used). The Client then asks the portmapper on which port the mountd is listening. This port is normally dynamically chosen, but you can force mountd to register always on a specific port and this step is important if you have a (stupid) firewall, because you have to allow this port in the ruleset too. Therefore you have to configure your mountd on the server to always use a specific port (in my case 789). As the next step, the client asks the portmapper for the nfsd. Nfsd's port could be also dynamically chosen, but usually only port 2049 is used (tcp or udp, depends on how you mount!). So for the minimal setup you need at least 111, one port for mountd (789) and one port for nfsd (2049). And if you mount_nfs with tcp you will become less trouble with dropped packets (because of congestion on fast links and/or packet drops on the firewall because of fragmentation).
Hope that helps!
cheers,
honk
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.
0