NFS server on CentOS8

NFS server on CentOS8

Install and configure NFS server

Step 1: Install NFS Packages:

  1. Open a terminal on your CentOS 8 VM.

  2. Run the following command to install the necessary NFS packages using

    1
    sudo yum install nfs-utils

Step 2: Configure NFS Exports:

  1. Create a directory that will be shared with NFS clients. For example, let’s create a directory called /shared

    1
    sudo mkdir /shared
  2. Assign appropriate permissions to the shared directory:

    1
    sudo chmod -R 777 /shared
  3. Open the /etc/exports file in a text editor:

    1
    sudo vi /etc/exports
  4. Add an entry in the file to define the shared directory and specify the allowed NFS clients. For example:

    1
    /shared 192.168.1.0/24(rw,sync,no_root_squash)
    • /shared: Path to the directory you created.
    • 192.168.1.0/24: IP address range or specific IP of the NFS clients allowed to access the shared directory.
    • rw: Allows read and write access.
    • sync: Synchronizes changes to the disk before acknowledging the request.
    • no_root_squash: Allows the root user on the NFS client to have root privileges on the NFS server.

Step 3: Start and Enable NFS Services:

  1. Start the NFS server service:

    1
    sudo systemctl start nfs-server
  2. Enable the NFS server service to start automatically at boot:

    1
    sudo systemctl enable nfs-server

Step 4: Configure Firewall for NFS:

  1. If you have a firewall enabled, open the necessary ports for NFS:

    1
    2
    3
    4
    sudo firewall-cmd --permanent --zone=public --add-service=nfs
    sudo firewall-cmd --permanent --zone=public --add-service=mountd
    sudo firewall-cmd --permanent --zone=public --add-service=rpc-bind
    sudo firewall-cmd --reload

Step 5: Export the Shared Directory:

  1. Export the shared directory by running the following command:

    1
    sudo exportfs -r

Step 6: Test NFS Access:

  1. On a client machine, ensure that the NFS utilities package is installed. If not, install it using sudo dnf install nfs-utils.

  2. Create a directory on the client machine where you want to mount the NFS share. For example, let’s create a directory called

    /mnt/nfs

    1
    sudo mkdir /mnt/nfs
  3. Mount the NFS share from the server to the client:

    1
    sudo mount server_ip:/shared /mnt/nfs
    • Replace server_ip with the IP address of your NFS server.
  4. Verify that the NFS share is mounted successfully by accessing the /mnt/nfs directory on the client.

Access NFS server shared folder from windows

Step 1: Enable NFS Client Feature:

  1. Open the “Control Panel” on your Windows machine.
  2. Go to “Programs” or “Programs and Features”.
  3. Click on “Turn Windows features on or off”.
  4. Scroll down and locate “Services for NFS”.
  5. Check the box next to “Client for NFS”.
  6. Click “OK” and wait for the feature to be installed.

Step 2: Mount the NFS Share:

  1. Open the “File Explorer” on your Windows machine.

  2. In the address bar, enter the following command, replacing nfs_server_ip with the IP address of your NFS server and shared_directory with the path to the shared directory on the NFS server:

    1
    \\nfs_server_ip\shared_directory

    For example:

    1
    \\192.168.1.100\shared
  3. Press Enter or click on the arrow button to access the NFS share.

  4. If prompted, enter the appropriate credentials to access the NFS share (if the NFS server requires authentication).

  5. Optional: Use web browser to access the shared folder:

    image-20231208113943859


NFS server on CentOS8
https://blog.excelsre.com/2023/12/07/nfs-server-on-centos8/
作者
Felix Yang
发布于
2023年12月8日
许可协议