Setting Up An NFS Server And Client On CentOS 5.5 - Page 2

4 Mounting The NFS Shares On The Client

client:

First we create the directories where we want to mount the NFS shares, e.g.:

mkdir -p /mnt/nfs/home
mkdir -p /mnt/nfs/var/nfs

Afterwards, we can mount them as follows:

mount 192.168.0.100:/home /mnt/nfs/home
mount 192.168.0.100:/var/nfs /mnt/nfs/var/nfs

You should now see the two NFS shares in the outputs of

df -h

[root@client ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       28G  2.2G   25G   8% /
/dev/sda1              99M   13M   82M  14% /boot
tmpfs                 250M     0  250M   0% /dev/shm
192.168.0.100:/home    28G  2.6G   25G  10% /mnt/nfs/home
192.168.0.100:/var/nfs
                       28G  2.6G   25G  10% /mnt/nfs/var/nfs
[root@client ~]#

and

mount

[root@client ~]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.0.100:/home on /mnt/nfs/home type nfs (rw,addr=192.168.0.100)
192.168.0.100:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,addr=192.168.0.100)
[root@client ~]#

 

5 Testing

On the client, you can now try to create test files on the NFS shares:

client:

touch /mnt/nfs/home/test.txt
touch /mnt/nfs/var/nfs/test.txt

Now go to the server and check if you can see both test files:

server:

ls -l /home/

[root@server ~]# ls -l /home/
total 55540
-rw-r--r-- 1 root         root                0 Sep 16 17:30 test.txt
[root@server ~]#

ls -l /var/nfs

[root@server ~]# ls -l /var/nfs
total 0
-rw-r--r-- 1 65534 65534 0 Sep 16 17:30 test.txt
[root@server ~]#

(Please note the different ownerships of the test files: the /home NFS share gets accessed as root, therefore /home/test.txt is owned by root; the /var/nfs share gets accessed as nobody/65534, therefore /var/nfs/test.txt is owned by 65534.)

 

6 Mounting NFS Shares At Boot Time

Instead of mounting the NFS shares manually on the client, you could modify /etc/fstab so that the NFS shares get mounted automatically when the client boots.

client:

Open /etc/fstab and append the following lines:

vi /etc/fstab

[...]
192.168.0.100:/home  /mnt/nfs/home   nfs      rw,sync,hard,intr  0     0
192.168.0.100:/var/nfs  /mnt/nfs/var/nfs   nfs      rw,sync,hard,intr  0     0

Instead of rw,sync,hard,intr you can use different mount options. To learn more about available options, take a look at

man nfs

To test if your modified /etc/fstab is working, reboot the client:

reboot

After the reboot, you should find the two NFS shares in the outputs of

df -h

[root@client ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       28G  2.2G   25G   8% /
/dev/sda1              99M   13M   82M  14% /boot
tmpfs                 250M     0  250M   0% /dev/shm
192.168.0.100:/home    28G  2.6G   25G  10% /mnt/nfs/home
192.168.0.100:/var/nfs
                       28G  2.6G   25G  10% /mnt/nfs/var/nfs
[root@client ~]#

and

mount

[root@client ~]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.0.100:/home on /mnt/nfs/home type nfs (rw,sync,hard,intr,addr=192.168.0.100)
192.168.0.100:/var/nfs on /mnt/nfs/var/nfs type nfs (rw,sync,hard,intr,addr=192.168.0.100)
[root@client ~]#

 

7 Links

Share this page:

5 Comment(s)

Add comment

Comments

From: Robert P. J. Day at: 2010-09-28 12:19:45

I've asked this question elsewhere -- can you configure NFS on both the client and server side to use *nothing* but NFSv4 and no earlier versions? If you examine the NFS init script /etc/init.d/nfs, you can see that the mountd invocation accepts options "--no-nfs-version 1", "--no-nfs-version 2" and so on. Can you explicitly deactivate support for all NFS versions other than 4?

From: Phill at: 2011-03-13 13:42:54

I had to tweak the suggested line to get my MacBook OS 10.6.6 to mount the exported folder.  The settings below are as 'relaxed' as I could get it so it could do with more testing to see how much tighter the security can be while still working.

I think the /24 (subnet size) may be importnt in any case though.

/mnt/2T/  192.168.7.0/24(rw,sync,no_subtree_check,insecure,all_squash,anonuid=1001,anongid=1001)

From: Joost Ringoot at: 2012-10-17 14:25:44

Nice but:

 If rpcbind is not running, and it isn't on a centos 6 minimal install.

You get these kind of errors:

[root@myhost ]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS mountd:                                       [FAILED]
Starting NFS daemon: rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused)
rpc.nfsd: unable to set any sockets for nfsd
                                                           [FAILED]
[root@myhost ]# 

 [root@myhost ]# /etc/init.d/rpcbind start
Starting rpcbind:                                          [  OK  ]
[root@myhost ]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
[root@myhost ]#

make it permanent with 

# chkconfig --level 35 rpcbind on

 

From: erik at: 2010-09-28 07:58:09

nice writeup.

mounting via fstab wastes resources (it will keep the nfs mounts mounted

even if not used). better use automap files to do a "demand based"

mounting by clients.


 

From: Yogi at: 2011-04-07 07:42:28

Hi Eric, Any tutorial for auto mounting?