Linux – iptables rules for nfs

centos-6linuxnfsscientific-linux

I was getting below error while typing showmount -e 192.168.56.2 in client machine

[root@client ~]# showmount -e 192.168.56.2
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)

This is my nfs server configuration

nfs server ip 192.168.56.2

This is my nfs share

[root@www ~]# cat /etc/exports 
/files  192.168.56.7(rw,sync)

These are the two services running in server machine

[root@www ~]# service rpcbind status
rpcbind (pid  2626) is running...
[root@www ~]# service nfs status
rpc.svcgssd is stopped
rpc.mountd (pid 2716) is running...
nfsd (pid 2781 2780 2779 2778 2777 2776 2775 2774) is running...
rpc.rquotad (pid 2712) is running...

This is my iptables rule

[root@www ~]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Thu Oct 31 02:08:16 2013
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [5:388]
-A INPUT -p tcp -m tcp --dport 111 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 2049 -j ACCEPT 
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A INPUT -p icmp -j ACCEPT 
-A INPUT -i lo -j ACCEPT 
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 
-A INPUT -j REJECT --reject-with icmp-host-prohibited 
-A FORWARD -j REJECT --reject-with icmp-host-prohibited 
COMMIT
# Completed on Thu Oct 31 02:08:16 2013

If I flush the iptables rule in server machine then my client is able to see nfs share

[root@client ~]# showmount -e 192.168.56.2
Export list for 192.168.56.2:
/files 192.168.56.7

That means problem with iptables rule , can anybody tell me what is the problem with my iptables rule , am I missing any other port ? How to troubleshoot these types of problems ?

I tried this method from my client machine to verify port is listening or not and this is the output of that

[root@client ~]# telnet 192.168.56.2 111
Trying 192.168.56.2...
Connected to 192.168.56.2.
Escape character is '^]'.
[root@client ~]# telnet 192.168.56.2 2049
Trying 192.168.56.2...
Connected to 192.168.56.2.
Escape character is '^]'.

Best Answer

The list of open ports for NFS is too restrictive. First, you will have to open the same ports to UDP, then you will need to add 2 more ports. The complete list of ports to be opened is:

 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
Related Question