Mount directory from a server to another server in Linux

mounting directories in servers are used to share common files among many servers. mounting a directory from a server to another server in Linux can be done easily by following the below steps. The setup will be as follows;

Remote Server (IP: 192.168.1.1) – the remote server which the directory that will be shared is hosted.

Server 1 (IP: 192.168.1.2) – local server 1

Server 2 (IP: 192.168.1.3) – local server 2

We are mounting through the NFS. NFS which stands for Network File System is a way of sharing directories/files across a network. It is used primarily in Linux and UNIX systems, although there are NFS clients for Windows.

Installing the packages

Install the following in the servers;

Remote Server:

apt-get install nfs-server nfs-comon

Server 1 and Server 2:

apt-get install nfs-kernel-server nfs-comon

Configuring the mount directory

Specify the directory (eg: /shared_mount/share/) to share in the remote server by adding the configurations to /etc/exports:

/shared_mount/share/ 192.168.1.2(rw,sync,no_subtree_check,no_root_squash)
/shared_mount/share/ 192.168.1.3(rw,sync,no_subtree_check,no_root_squash)

Then apply those settings;

exportfs -ra
/etc/init.d/nfs-kernel-server restart

Mounting remote directory

Now, mount the directory in the remote server to the local servers;

sudo mount -o soft,intr,rsize=8192,wsize=8192 192.168.1.1:/shared_mount/share/ /local_mount/share/

Testing the mount

To test this mounted setup we will create a file in the remote directory and see if they are available in the mounted directories of the 2 local servers. In the remote mounted directory;

touch /shared_mount/share/hello.txt

now, go and check in the local servers mounted directory. the hello.txt file should be available.

Adding mounting to server startup

This is a good practice to have in case your server goes down or reboots. To add the startup add the following to /etc/fstab in both local servers;

192.168.1.2:/shared_mount/share/ /local_mount/share/ nfs rsize=16384,wsize=16384,rw,auto,nolock

2 Replies to “Mount directory from a server to another server in Linux”

  1. user1

    the mounting of remote directory section; it should only be
    sudo mount -o soft,intr,rsize=8192,wsize=8192 192.168.1.1:/shared_mount/share/ /local_mount/share/
    Am I right?

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.