NFS: Network File System

By using NFS a server shares a directory with a client. CAUTION: the com between the server and the client is done in clear so it’s basically not safe.

NFS Server Configuration

1. First you need to make sure the NFS daemon is running

[root@i7 ~]# service nfs status
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped
[root@i7 ~]# service nfs start
Starting NFS services:                                     [  OK ]
Starting NFS quotas:                                        [  OK ]
Starting NFS daemon:                                     [  OK ]
Starting NFS mountd:                                     [  OK ]

Continue to step 2 even if NFS doesn’t start.

2. Second you need to make sure rpcbind or portmap is running (depending on the distro). To get info about rpcbind you need to issue a rpcinfo -p:

(this is the case where NFS started above)

[root@i7 dev]# rpcinfo -p
program vers proto   port
100000    2   tcp    111  portmapper
100000    2   udp    111  portmapper
100024    1   udp    876  status
100024    1   tcp    879  status
100003    2   udp   2049  nfs
100003    3   udp   2049  nfs
100003    4   udp   2049  nfs
….

If rpcinfo -p fails with this message:

root@gts2 [~]# rpcinfo -p
rpcinfo: can’t contact portmapper: RPC: Remote system error – Connection refused

…issue a portmap start:

root@gts2 [~]# service portmap start

And now try to start nfs again! This time should work:

root@gts2 [~]# rpcinfo -p
program vers proto   port
100000    2   tcp    111  portmapper
100000    2   udp    111  portmapper

3.  The NFS resource access is set in the file /etc/exports

The format of /etc/exports is this:

exported_dir     ip_allowed_to_mount(option1,option2)

exported_dir = the directory offered by the server to be mounted by the remote client

ip_allowed_to_mount = the client’s IP (that is allowed to execute the NFS mount)

Important options: ro (read-only), rw(read-write), root_squash (the root from the client will no get root access on the server, no_root_squash (the root on the client will have root rights on the server as well).

Example (the IP can be a public one as well):

/nfs    192.168.1.101(ro,root_squash)

4. Export all entries from /etc/exports

exportfs -a

Client use

To use NFS on the client:

mount -t nfs server_ip:/shared_dir /client_mount_dir

Starting NFS mountd:                                     [  OK ]
File system