- How to Install and Configure NFS Server on Linux
- Features of NFS
- Setup NFS
- IP address Details of Server & Client
- Configuring NFS Server
- Exporting the Share Directory
- Explanation
- Configure Client
- Creating Mount Point for Share Directory
- Mounting the Share Directory
- To Check the NFS Mount
- How to Share Files Between Linux Computers Using NFS
- Creating the Server
- Connecting the Client Computers
- Expert Q&A
- Tips
- You Might Also Like
How to Install and Configure NFS Server on Linux
In this article we will learn and configure NFS (Network File System) which is basically used to share the files and folders between Linux systems. This was developed by Sun Microsystems in 1980 which allows us to mount the file system in the network and remote users can interact and the share just like local file and folders.
Features of NFS
- NFS can be configured as a centralized storage solution.
- No need of running the same OS on both machines.
- Can be secured with Firewalls.
- It can be shared along with all the flavors of *nix.
- The NFS share folder can be mounted as a local file system.
Setup NFS
NFS mount needed at least two machines. The machine hosting the shared folders is called as server and which connects is called as clients.
IP address Details of Server & Client
Configuring NFS Server
We needed to install the packages for NFS
# yum install nfs-utils nfs-utils-lib Output: Loaded plugins: fastestmirror, security Setting up Install Process Loading mirror speeds from cached hostfile epel/metalink | 4.0 kB 00:00 * base: mirror.digistar.vn * epel: mirrors.ustc.edu.cn * extras: mirror.digistar.vn * updates: mirror.digistar.vn Resolving Dependencies --> Running transaction check ---> Package nfs-utils.x86_64 1:1.2.3-64.el6 will be installed ---> Package nfs-utils-lib.x86_64 0:1.1.5-11.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================ Package Arch Version Repository Size ================================================================================================ Installing: nfs-utils x86_64 1:1.2.3-64.el6 base 331 k nfs-utils-lib x86_64 1.1.5-11.el6 base 68 k Transaction Summary ================================================================================================ Install 2 Package(s) Total download size: 399 k Installed size: 1.1 M Is this ok [y/N]: y Downloading Packages: (1/2): nfs-utils-1.2.3-64.el6.x86_64.rpm | 331 kB 00:00 (2/2): nfs-utils-lib-1.1.5-11.el6.x86_64.rpm | 68 kB 00:00 ------------------------------------------------------------------------------------------------ Total 60 kB/s | 399 kB 00:06 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : nfs-utils-lib-1.1.5-11.el6.x86_64 1/2 Installing : 1:nfs-utils-1.2.3-64.el6.x86_64 2/2 Verifying : 1:nfs-utils-1.2.3-64.el6.x86_64 1/2 Verifying : nfs-utils-lib-1.1.5-11.el6.x86_64 2/2 Installed: nfs-utils.x86_64 1:1.2.3-64.el6 nfs-utils-lib.x86_64 0:1.1.5-11.el6 Complete!
After this run the below commands to start the NFS servers and make sure it start at boot time.
# chkconfig nfs on # service rpcbind start # service nfs start Output: Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS mountd: [ OK ] Starting NFS daemon: [ OK ] Starting RPC idmapd: [ OK ]
Exporting the Share Directory
We need to decide a directory which we want to share with the client. The directory should be added to /etc/exports
All the below lines to the file.
/share 192.168.87.158(rw,sync,no_root_squash,no_subtree_check)
Explanation
- /share – is the share folder which server wants to share
- 192.168.87.158 – is the IP address of the client to whom want to share
- rw – This will all the clients to read and write the files to the share directory.
- sync – which will confirm the shared directory once the changes are committed.
- no_subtree_check – Will prevents the scanning the shared directory, as nfs performs the scans of every share directory, Disabling the subtree check will increase the reliability, but reduces the security.
- no_root_squash – This will all the root user to connect to the designated directory.
Once, we enter the details of the share in config file, run the below command to export them
Configure Client
Install the required packages to connect to NFS
# yum install nfs-utils nfs-utils-lib -y
Creating Mount Point for Share Directory
Once the packages are installed on the client, create the directory to mount point the shared folder
Mounting the Share Directory
# mount 192.168.87.156:/share /mnt/share/
To confirm if the share is mounted or not run the command ‘df -h’, this will show the list of mounted folders.
# df -h Output: Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 50G 5.2G 42G 12% / tmpfs 427M 80K 427M 1% /dev/shm /dev/sda1 477M 42M 410M 10% /boot /dev/mapper/VolGroup-lv_home 95G 60M 90G 1% /home 192.168.87.156:/share 18G 2.0G 15G 13% /mnt/share
To see the list of all the mounted file systems.
# mount Output: /dev/mapper/VolGroup-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) /dev/sda1 on /boot type ext4 (rw) /dev/mapper/VolGroup-lv_home on /home 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) 192.168.87.156:/share on /mnt/share type nfs (rw,vers=4,addr=192.168.87.156,clientaddr=192.168.87.158)
To Check the NFS Mount
Create a file and folders in the server share directory
Then goto the client side machine and check the /mnt/share folders
# ls /mnt/share/ -lh total 4.0K drwxr-xr-x 2 root root 4.0K Apr 20 2016 test -rw-r--r-- 1 root root 0 Apr 20 2016 test1
To automatically mount the share folder permanently while boot in the client machine, add the entries in the /etc/fstab file
# vi /etc/fstab # # /etc/fstab # Created by anaconda on Sat Apr 2 00:11:04 2016 # # 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/VolGroup-lv_root / ext4 defaults 1 1 UUID=1adb2ad5-d0c7-48a5-9b10-f846a3f9258c /boot ext4 defaults 1 2 /dev/mapper/VolGroup-lv_home /home ext4 defaults 1 2 /dev/mapper/VolGroup-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.87.156:/share /mnt/share nfs auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
Some options and important command of NFS
# showmount -e Export list for localhost.localdomain: /share 192.168.87.158
This will show the available share on the local machine, so needed to run on the server side.
# showmount -e 192.168.87.156 Export list for 192.168.87.156: /share 192.168.87.158
This will show the remote server shared folders needed to run on the client side –
# exportfs -v /share 192.168.87.158(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,no_root_squash,no_all_squash)
List all the share files and folders with options on the server
# exportfs -u /share 192.168.87.158
This will un-export the shared folders or files which are in /etc/exports
This will refresh the servers list and check for the changes if any.
After this configuration and setup, you should be able to use NFS to share the files between *inx machines without any problem, then we should be able share the folders to only the client to whom we want to share the folder, this will improve the security.
An investment in knowledge pays the best interest
How to Share Files Between Linux Computers Using NFS
wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 16 people, some anonymous, worked to edit and improve it over time.
The wikiHow Tech Team also followed the article’s instructions and verified that they work.
This article has been viewed 263,214 times.
Nearly all Linux distributions come with the ability to set up a Network File System (NFS) that allows the different Linux computers on the network to easily share files. NFS is only suitable for networks comprised entirely of Linux computers and servers, but works on the system level for fast, efficient transfers between computers.
Creating the Server
Use NFS (Network File System) to share files between Linux computers on a local network. If you need to share files with Windows or Mac computers, you will be much more successful using Samba.
Understand how NFS works. When sharing files with NFS, there are two side: the server and the clients. The server is the computer that is actually storing the files, while the clients are the computers that are accessing the shared folder by mounting the shared folder as a virtual drive. NFS will need to be configured on both the server and any client that wants to connect.
Open the terminal on the server computer. This is the computer that will be hosting the shared files. The server computer will need to be turned on and logged in in order for clients to mount the shared folder. NFS requires using the terminal to install and configure both the server and client.
Type . sudo apt-get install nfs-kernel-server nfs-common portmap and press ↵ Enter . This will begin downloading and installing the NFS files on your computer.
After installation, type . dpkg-reconfigure portmap . Select «No» from the menu that appears. This will enable other computers on the network to connect to your shared folder.
Type . sudo /etc/init.d/portmap restart to restart the portmap service. This will ensure that your changes take effect.
- Type . mkdir -p /export/ dummyname and press ↵ Enter . This will create a directory named dummyname that the clients will see.
Type pico /etc/fstab and press ↵ Enter . This will open the /etc/fstab file and allow you to automatically mount the shared drive whenever the server boots up.
- For example, to share the /dev/sdb drive with the clients using the dummy directory created earlier, you would type /dev/sdb /export/Shared none bind 0 0 . Save the changes to the file.
Open the . /etc/exports file. You will need to add your dummy directory as well as the IPs that are allowed to access it to this file. Use the following format to share with all the IP addresses on your local network: /export/ dummyname 192.168.1.1/24(rw,no_root_squash,async) . [1] X Research source
Connecting the Client Computers
Type . sudo apt-get install portmap nfs-common and press ↵ Enter to install the NFS client files.
Create the directory that the shared files will be mounted in. You can name this whatever you’d like. For example, you can type mkdir /sharedFiles to create a folder called «sharedFiles».
- Using the above examples, the line might look like: 192.168.1.5:/export/Shared /sharedFiles nfs rsize=8192,wsize=8192,timeo=14,intr .
Type . sudo /etc/init.d/portmap restart to restart portmap and use the new settings. The drive will automatically mount each time the computer reboots.
Test the drive by manually mounting it before restarting. Type mount -a and then ls /sharedFiles to see if the shared files are displayed.
Repeat this process for each connecting computer. You should be able to enter the same settings and successfully connect. [2] X Research source
Expert Q&A
Tips
You Might Also Like
Ubuntu Software Installation: The Complete Beginner’s Guide
Can Linux Run .exe Files? How to Run Windows Software on Linux
How to Open Linux Firewall Ports: Ubuntu, Debian, & More
How to Run an INSTALL.sh Script on Linux in 4 Easy Steps
Use Ping in Linux: Tutorial, Examples, & Interpreting Results
How to Delete Read-Only Files in Linux