Linux: Installing and Configuring an NFS Server



  • The most common file server on any Linux system is NFS. Creating an NFS based file server is an extremely common UNIX task.

    Installing NFS Server

    Install NFS Server on Fedora Linux

    dnf -y install nfs-util libnfsidmap
    systemctl enable rpcbind
    systemctl enable nfs-server
    systemctl start rpcbind
    systemctl start nfs-server
    systemctl start rpc-statd
    systemctl start nfs-idmapd
    

    Install NFS Server on CentOS Linux 7

    yum -y install nfs-util libnfsidmap
    systemctl enable rpcbind
    systemctl enable nfs-server
    systemctl start rpcbind
    systemctl start nfs-server
    systemctl start rpc-statd
    systemctl start nfs-idmapd
    

    Configuring the Firewall for NFS Services

    The CentOS, RHEL, and Fedora firewall firewalld makes managing NFS pretty easy. If we know our active zone (which is generally "public" on CentOS and RHEL, and generally "FedoraServer" on Fedora Server, we can open the necessary ports for NFS. These examples are generic, check your active zone to determine if they are right for your environment.

    firewall-cmd --permanent --zone="FedoraServer" --add-service mountd
    firewall-cmd --permanent --zone="FedoraServer" --add-service rpc-bind
    firewall-cmd --permanent --zone="FedoraServer" --add-service nfs
    firewall-cmd --reload
    

    Creating an NFS Share

    First we need a folder that we will share to other hosts on our network. We will create a unique folder for this, although technically we could use just about any existing folder for this task. We will also make the folder universally readable and writeable as, for this example, we will rely solely on NFS permissions to manage access to the share.

    mkdir /var/nfs_share1
    chmod 777 /var/nfs_share1
    

    The configuration of NFS shares on our system is contained in the /etc/exports file. We will need to edit this to create our first NFS share.

    vi /etc/exports
    

    By default we expect that this file will be blank. We will fill in a basic configuration line. Edit the file and add this line:

    /var/nfs_share1 *(rw,sync,no_root_squash)
    

    This configuration will allow any host that can communicate with the server to mount the share, with no additional security. This configuration is only good for an example and is not safe in reality. In a production scenario we would replace the wildcard (the asterisk: * ) with some network address or subnet, and root_squash instead of no_root_squash, and we would add POSIX level ACLs as a minimum for security. But this is just an example to make understanding NFS shares as simple as possible.

    Now that we have configured a share (you can populate the /etc/exports file with as many shares as you want to make) we just need to tell the NFS service to reread the configuration file to make it available. Of course we could just reboot to do this, or we can just use this command:

    exportfs -r
    

    And that's it. We should now have a share available on our network.

    Red Hat has good documentation of NFS: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/deployment_guide/s1-nfs-server-config-exports


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



  • I noticed you provide NFSv3 configuration, how about including NFSv4 too or does it matter from a client perspective?



  • @scottalanmiller said in Linux: Installing and Configuring an NFS Server:

    and generally "FedoraServer" on Fedora Server

    This is wrong and you have been told that before.

    It is only FedoraServer if you choose a Fedora Server install. If you choose a minimal install it is "public"

    As has you have also been told before if you leave the zone off, it uses the default zone.

    So if you want to make a generic assumption without adding logic to figure out WTF zone is being used, you simply do not specify the zone.

    firewall-cmd --permanent --add-service mountd
    firewall-cmd --permanent --add-service rpc-bind
    firewall-cmd --permanent --add-service nfs
    firewall-cmd --reload
    


  • @JaredBusch said in Linux: Installing and Configuring an NFS Server:

    and generally "FedoraServer" on Fedora Server

    This is wrong and you have been told that before.
    It is only FedoraServer if you choose a Fedora Server install.

    Literally what was said.



  • @JaredBusch said in Linux: Installing and Configuring an NFS Server:

    If you choose a minimal install it is "public"

    If it is "minimal", it isn't "Fedora Server", is it? The Fedora Server install means "not minimal."



  • @scottalanmiller said in Linux: Installing and Configuring an NFS Server:

    @JaredBusch said in Linux: Installing and Configuring an NFS Server:

    If you choose a minimal install it is "public"

    If it is "minimal", it isn't "Fedora Server", is it? The Fedora Server install means "not minimal."

    But you wouldn't have to check which zone is active, if you leave out specifying the active zone.
    If I wanted to create a generic script to install and configuring nfs server for Fedora installation, I would leave out --zone= because I wouldn't need check which active zone you are using before adding the rules.



  • @JaredBusch said in Linux: Installing and Configuring an NFS Server:

    @scottalanmiller said in Linux: Installing and Configuring an NFS Server:

    and generally "FedoraServer" on Fedora Server

    This is wrong and you have been told that before.

    It is only FedoraServer if you choose a Fedora Server install. If you choose a minimal install it is "public"

    As has you have also been told before if you leave the zone off, it uses the default zone.

    So if you want to make a generic assumption without adding logic to figure out WTF zone is being used, you simply do not specify the zone.

    firewall-cmd --permanent --add-service mountd
    firewall-cmd --permanent --add-service rpc-bind
    firewall-cmd --permanent --add-service nfs
    firewall-cmd --reload
    

    Yeah, leave out the zone specification. 99.9999999% of everyone reading this guide will be using the default zone and won't need to specify.



  • I did this just now so I though I'll add it to the thread.

    Install NFS Server on Debian 9

    apt install nfs-server
    

    As you may know debian installer start services automatically so it's just less to write.

    By default folders for nfs goes into /srv.



  • @scottalanmiller At least with Fedora 30, its nfs-utils instead of nfs-util