Linux: Mounting an NFS Share



  • If you followed my last example for creating a Simple NFS File Server and Share, we can now mount that share to another machine on our network. To get started, we need the IP address of the NFS Server that we will be mounting the share from (assuming that you are following my examples, this is the IP address of the server from the previous example.)

    We can start my listing all shares available from the NFS server. For our example, we will assume that the NFS server's IP address is 192.168.2.2. Make sure to always substitute your server's IP address.

    showmount -e 192.168.2.2

    This should show us the share that we created in the other example. If not, check your file server setup, make sure that you can ping the server, etc.

    Now, like with any filesystem, in order to use it we need a place to mount it. To make things quick and simple, there is a portion of the file hierarchy designated for this under /mnt. But you could mount anywhere that makes sense. A very common location would be something like /data. In our case, we will make a new spot at /mnt/nfs1

    mkdir /mnt/nfs1
    

    Now we can manually mount the share to this new location with the mount command. Other than a small extra amount of detail to tell the local system where the NFS share is located, nothing special is needed. The mount command will even detect the use of NFS automatically for us, so no need to speficy the filesystem in question.

    mount 192.168.2.2:/var/nfs_share1 /mnt/nfs1
    

    That is it. You should be able to "cd /mnt/nfs1" and create, read, modify files or whatever. You can view details about this mount point in the usual ways with things like the mount, df, and similar commands.

    Configure NFS Share to Mount at Boot Automatically

    Like other filesystems, we can make an NFS share be mounted automatically when our system boots. To do this, we add it to the /etc/fstab file where our other mounts are specified.

    vi /etc/fstab
    

    Navigate to the bottom of the file and for our mount point example, just add this line:

    192.168.2.2:/var/nfs_share1 /mnt/nfs1 nfs rw,sync,hard,intr 0 0
    

    Now you can reboot to verify that it mounts and is available after a system restart.


    Part of a series on Linux Systems Administration by Scott Alan Miller



  • I have always wished that the mount command had to switch to put the damn thing Into fstab.



  • @JaredBusch said in Linux: Mounting an NFS Share:

    I have always wished that the mount command had to switch to put the damn thing Into fstab.

    You mean like --perm and it just appended into fstab? That would rock.



  • @scottalanmiller said in Linux: Mounting an NFS Share:

    @JaredBusch said in Linux: Mounting an NFS Share:

    I have always wished that the mount command had to switch to put the damn thing Into fstab.

    You mean like --perm and it just appended into fstab? That would rock.

    Yeah pretty much anything like that