ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Linux: Installing and Configuring an NFS Server

    IT Discussion
    linux sam linux administration unix nfs fedora centos
    5
    10
    3.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      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

      JaredBuschJ 1 Reply Last reply Reply Quote 4
      • black3dynamiteB
        black3dynamite
        last edited by

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

        1 Reply Last reply Reply Quote 2
        • JaredBuschJ
          JaredBusch @scottalanmiller
          last edited by

          @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
          
          scottalanmillerS ObsolesceO 3 Replies Last reply Reply Quote 2
          • scottalanmillerS
            scottalanmiller @JaredBusch
            last edited by

            @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.

            1 Reply Last reply Reply Quote 0
            • scottalanmillerS
              scottalanmiller @JaredBusch
              last edited by

              @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."

              black3dynamiteB 1 Reply Last reply Reply Quote 0
              • black3dynamiteB
                black3dynamite @scottalanmiller
                last edited by black3dynamite

                @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.

                1 Reply Last reply Reply Quote 0
                • ObsolesceO
                  Obsolesce @JaredBusch
                  last edited by

                  @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.

                  1 Reply Last reply Reply Quote 1
                  • 1
                    1337
                    last edited by 1337

                    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.

                    1 Reply Last reply Reply Quote 2
                    • black3dynamiteB
                      black3dynamite
                      last edited by

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

                      1 Reply Last reply Reply Quote 1
                      • black3dynamiteB
                        black3dynamite
                        last edited by black3dynamite

                        rpcbind services is not required for NFSv4

                        https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/deploying_different_types_of_servers/exporting-nfs-shares_deploying-different-types-of-servers
                        d4520326-8f0f-48df-b2bf-62e8b7a0040c-image.png

                        25c783d8-ba90-4aee-b652-017c220451b6-image.png

                        1 Reply Last reply Reply Quote 0
                        • scottalanmillerS scottalanmiller referenced this topic on
                        • 1 / 1
                        • First post
                          Last post