Google Plus

NFS Server installation and configuration in CentOS 6.3, RHEL 6.3 and Scientific Linux 6.3

Written by SK on . Posted in CentOS, Fedora, Linux distributions, Linux Mint, Linux tutorials, Ubuntu

NFS, Network File System, is a server-client protocol used for sharing files between linux/unix to unix/linux systems. NFS enables you to mount a remote share locally. You can then directly access any of the files on that remote share.

 Scenario

In this how-to I use two systems running with CentOS 6.3, but it will work on any based distros.

NFS Server IP Address : 192.168.1.250/24

NFS Client IP Address  : 192.168.1.251/24

1. Install NFS in Server system

[root@nfs ~]# yum install nfs* -y

 2. Start NFS service

[root@nfs ~]# service rpcbind start

Starting rpcbind:                                          [  OK  ]

[root@nfs ~]# service nfs start

Starting NFS services:                                     [  OK  ]

Starting NFS mountd:                                       [  OK  ]

Starting NFS daemon:                                       [  OK  ]

[root@nfs ~]# chkconfig rpcbind on

[root@nfs ~]# chkconfig nfs on

 

3. Install NFS in Client System

[root@client unixmen]# yum install nfs* -y

 

4. Start NFS service

[root@client unixmen]# service rpcbind start

[root@client unixmen]# service nfs start

[root@client unixmen]# chkconfig rpcbind on

[root@client unixmen]# chkconfig nfs on

 

5. Create shared directories in server

Create a shared directory named ‘/var/unixmen_share’ in server and let the client users to read and write files in that directory.

[root@nfs ~]# mkdir /var/unixmen_share 

[root@nfs ~]# chmod 755 /var/unixmen_share/

6. Export shared directory on NFS Server

Open /etc/exports file and add the entry as shown below

[root@nfs ~]# vi /etc/exports 

/var/unixmen_share/     192.168.1.0/24(rw,sync,no_root_squash,no_all_squash)

 where,

/var/unixmen_share  – shared directory

192.168.1.0/24           – IP address range of clients

rw                               – Writable permission to shared folder

sync                            – Synchronize shared directory

no_root_squash          – Enable root privilege

no_all_squash             – Enable user’s authority

 

7. Restart the NFS service.

[root@nfs ~]# service nfs restart 

Shutting down NFS daemon:                                  [  OK  ] 

Shutting down NFS mountd:                                  [  OK  ] 

Starting NFS services:                                     [  OK  ] 

Starting NFS mountd:                                       [  OK  ] 

Starting NFS daemon:                                       [  OK  ]

 8. Mount the share directory in client

Create a mount point to mount the share directory ‘var/unixmen_local’ which we created in the earlier step 5.

[root@client unixmen]# mkdir /var/nfs_share

 Mount the share from server to client as shown below

[root@client unixmen]# mount -t nfs 192.168.1.250:/var/unixmen_share/ /var/nfs_share/ 

mount.nfs: Connection timed out 

 Probably it will show a connection timed out issue which means the firewall is blocking NFS server. To allow NFS server to access from the outbound, goto NFS server system and add the as shown below in the ‘etc/sysconfig/iptables’ file.

[root@nfs ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
-A INPUT -m state --state NEW -m udp -p udp --dport 2049 -j ACCEPT 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT 
-A INPUT -m state --state NEW -m udp -p udp --dport 111 -j ACCEPT 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT 
-A INPUT -m state --state NEW -m udp -p udp --dport 32769 -j ACCEPT 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 32803 -j ACCEPT 
-A INPUT -m state --state NEW -m udp -p udp --dport 892 -j ACCEPT 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 892 -j ACCEPT 
-A INPUT -m state --state NEW -m udp -p udp --dport 875 -j ACCEPT 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 875 -j ACCEPT 
-A INPUT -m state --state NEW -m udp -p udp --dport 662 -j ACCEPT 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 662 -j ACCEPT 
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

 

Now restart the iptables service

[root@nfs ~]# service iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK

 

Again mount the share in client system

 

[root@client unixmen]# mount -t nfs 192.168.1.250:/var/unixmen_share/ /var/nfs_share/ 

[root@client unixmen]# 

 Now the NFS share will mount without any connection timed out error.

 

9. Verify NFS

Verify the share from the server is mounted or not using ‘mount’ command.

[root@client unixmen]# mount

/dev/mapper/vg_client-lv_root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.1.250:/var/unixmen_share/ on /var/nfs_share type nfs (rw,vers=4,addr=192.168.1.250,clientaddr=192.168.1.251) 

 

10.  Automount the Shares

To mount the shares automatically instead of mounting them manually at every reboot, add the following lines shown in bold in the ‘/etc/fstab’ file of client system.

[root@client unixmen]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Mar 3 22:10:15 2013
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_client-lv_root / ext4 defaults 1 1
UUID=1aa7d041-056b-48f4-a773-f713759e981f /boot ext4 defaults 1 2
/dev/mapper/vg_client-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
192.168.1.250:/var/unixmen_share/ /var/nfs_share/ nfs rw,sync,hard,intr 0 0

 Reboot the client system and check the share whether it is automatically mounted or not.

 

[root@client unixmen]# mount

/dev/mapper/vg_client-lv_root on / type ext4 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")

/dev/sda1 on /boot type ext4 (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

nfsd on /proc/fs/nfsd type nfsd (rw)

192.168.1.250:/var/unixmen_share/ on /var/nfs_share type nfs (rw,vers=4,addr=192.168.1.250,clientaddr=192.168.1.251) 

 

Thats it. Now NFS server is ready to use.

For questions please refer to our Q/A forum at : http://ask.unixmen.com

SK

I'm Senthilkumar a.k.a SK, a Linux Admin & Tech writer from Tamilnadu, India. I love very much to write about Linux, Open Source, Computers and Internet to help newbies of Linux and Open Source. For any queries, suggestions and comments, please feel free to contact me at ask2sk@in.com.
  • Murugananthan

    Thanks Mr.Senthikumar..

    • SK

      Thanks Mr.Muruganathan. Please recommend this website to your friends and colleagues . Keep visiting.

  • Scott Dowdle

    Nice article. Thanks. Obviously it only covers the basics. I’m looking for an article that covers how to measure and improve NFS performance as well as common troubleshooting tips. It would also been nice if you had addressed SELinux and how to relabel the shared directory and the SELinux booleans related to NFS so that your recipe would work within SELinux. Since SELinux isn’t mentioned at all, I guess one is to assume it is disabled or it isn’t a problem with the recipe.

    • SK

      Thanks for the comment. You don’t have to disable SELINUX. It will work either SELINUX is disabled or enabled. All you need to do that is adjust iptables to allow NFS from outside of your LAN. I will write a detailed post about NFS performance and troubleshooting in my upcoming articles. Keep visiting http://www.unixmen.com.

Like us on Facebook

This week Top Posts

Write for us

Recent Comments

cave

|

it can be used to talk or chat through the internet,

it is using strong encryption.

but for example TOR is using some obfuscation because some countrys try to block all outgoing connections which can not be scanned with DPI

And the TOR Project is facing an arms race in obfuscation and encryption detection.

cave

|

You can friend someone if you give him your public Certificate.

both peers must friend each other.

i suggest to not enter a valid e-mail address. it is not necessary, but pgp needs a mail addy. something@something.so fits perfectly… :)

http://redd.it/18vsq5 <– faq, featurelist, todo, howto, useful links to manual wiki etc, …

you can connect to chatservers, which will give you access to chatlobby, where always some people are lurking.

#1 https://www.f2f-fr.net/w2c/en/
#2 http://retrosharechatserver.no-ip.org/w2c/en/

and in this rooms, you can find other people to talk and friend.

cave

|

http://redd.it/18vsq5
please have a look at this link. it is a FAQ, QuickTip, HowTo, etc etc etc …

If you want to make friends, please use the Chatservers.
#1 https://www.f2f-fr.net/w2c/en/
#2 http://retrosharechatserver.no-ip.org/w2c/en/

if you enter your certificate, the chatserver adds you as his friend and shows his certificate too add him to your friends.

After the connection to the chatservers is established, you can join a few chatrooms where the chatserver is lurking.

in this rooms are other people too help you and make first friends and get into the network.

add friends only with wisdom. if you friend some policeman, it will be problematic like in real life.

best is to add only people you trust in real life or trust from other communitys too. and not to add random unkown strangers.

If you have questions, ask them in the chatlobbys, there is always someone to answer them.

please read http://redd.it/18vsq5

or question me here :)

Ladi Oyekanmi

|

Could you please assist in step by step on how to install nagios on solaris

Adhraa

|

Greate tutorial :)

 
IDG Tech Network
Copyright © 2008-2013 Unixmen.com .
Maintained by Anblik .