1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Remote file mount won't work when pf is enable

Discussion in 'Firewalls' started by hollis2507, Dec 9, 2009.

  1. hollis2507

    hollis2507 New Member

    Messages:
    17
    Thanks Received:
    0
    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
    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
     
  2. graudeejs

    graudeejs Well-Known Member

    Messages:
    4,594
    Thanks Received:
    632
    Code:
    pass on $ext_if proto { tpc, udp } from any to any port { nfsd, lockd }


    i think should work
     
  3. SirDice

    SirDice Moderator Staff Member Moderator

    Messages:
    17,515
    Thanks Received:
    2,351
    NFS is somewhat tricky to firewall. RPC uses different ports each time.
     
  4. graudeejs

    graudeejs Well-Known Member

    Messages:
    4,594
    Thanks Received:
    632
    In that case you can allow all ports form known to be "secure" hots... [similar to what i did with ftp :D]
     
  5. hollis2507

    hollis2507 New Member

    Messages:
    17
    Thanks Received:
    0
    Thanks for the replies.

    I tried

    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?
     
  6. graudeejs

    graudeejs Well-Known Member

    Messages:
    4,594
    Thanks Received:
    632
    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 :) ]

    Code:
    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
     
  7. dennylin93

    dennylin93 New Member

    Messages:
    784
    Thanks Received:
    104
    This might help: nfs_reserved_port_only="YES"?
     
  8. hollis2507

    hollis2507 New Member

    Messages:
    17
    Thanks Received:
    0
    Where does this go? rc.conf?
     
  9. graudeejs

    graudeejs Well-Known Member

    Messages:
    4,594
    Thanks Received:
    632
    from rc.conf():
    Code:
         nfs_reserved_port_only
                     (bool) If set to “YES”, provide NFS services only on a secure
                     port.
    
    


    answer: yes
     
  10. phoenix

    phoenix Moderator Staff Member Moderator

    Messages:
    3,422
    Thanks Received:
    753
    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:
    Code:
    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).
     
  11. graudeejs

    graudeejs Well-Known Member

    Messages:
    4,594
    Thanks Received:
    632
    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]
     
  12. SirDice

    SirDice Moderator Staff Member Moderator

    Messages:
    17,515
    Thanks Received:
    2,351
    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.
     
  13. DutchDaemon

    DutchDaemon Administrator Staff Member Administrator Moderator

    Messages:
    10,721
    Thanks Received:
    2,137
    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(5)) on nfs traffic
    2. make sure your nfs host/client can resolve one another correctly (DNS or /etc/hosts)
     
  14. phoenix

    phoenix Moderator Staff Member Moderator

    Messages:
    3,422
    Thanks Received:
    753
    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.
     
  15. J65nko

    J65nko Member

    Messages:
    424
    Thanks Received:
    109
    You see which packets are being blocked with
    Code:
    block 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 ;)
     
  16. johnblue

    johnblue Member

    Messages:
    225
    Thanks Received:
    19
    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.
     
  17. honk

    honk New Member

    Messages:
    134
    Thanks Received:
    13
    rc.conf on the nfs-server:
    Code:
    ## NFS-Server
    rpcbind_enable="YES"
    nfs_server_enable="YES"
    mountd_flags="-p 789"
    



    pf.conf on the firewall:
    Code:
    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:
    Code:
    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