월. 8월 4th, 2025

Network File System (NFS) allows seamless file sharing between Linux systems over a network. Whether you’re managing servers or collaborating on projects, NFS eliminates the hassle of manual file transfers. This guide covers server/client setup for NFSv4 (the modern standard) using systemd.


Prerequisites

  1. Two Linux machines:
    • Server: Hosts the shared directory
    • Client: Accesses the shared directory
  2. Terminal access with sudo privileges on both
  3. Static IPs for both (e.g., Server: 192.168.0.100, Client: 192.168.0.101)
  4. Firewall access for NFS ports (TCP/UDP 2049)

Step 1: Server Setup

Install NFS Packages

sudo apt update && sudo apt install nfs-kernel-server -y  # Debian/Ubuntu
sudo dnf install nfs-utils -y                            # RHEL/CentOS/Fedora

Create & Share a Directory

sudo mkdir -p /mnt/nfs_share
sudo chown nobody:nogroup /mnt/nfs_share  # Relax permissions for testing
sudo chmod 777 /mnt/nfs_share             # Optional: Adjust per security needs

Configure Exports

Edit /etc/exports:

sudo nano /etc/exports

Add this line to share with a specific client (replace 192.168.0.101):

/mnt/nfs_share 192.168.0.101(rw,sync,no_subtree_check)
  • rw: Read/write access
  • sync: Write changes immediately
  • no_subtree_check: Better performance

Apply changes:

sudo exportfs -ra  # Reload exports
sudo systemctl restart nfs-server

Open Firewall

sudo ufw allow from 192.168.0.101 to any port nfs  # Ubuntu
sudo firewall-cmd --permanent --add-service=nfs && sudo firewall-cmd --reload  # RHEL

Step 2: Client Setup

Install NFS Client

sudo apt install nfs-common -y   # Debian/Ubuntu
sudo dnf install nfs-utils -y    # RHEL/CentOS

Mount the NFS Share

sudo mkdir -p /mnt/client_share
sudo mount 192.168.0.100:/mnt/nfs_share /mnt/client_share  # Replace with server IP

Auto-Mount at Boot

Edit /etc/fstab:

sudo nano /etc/fstab

Add:

192.168.0.100:/mnt/nfs_share  /mnt/client_share  nfs4  defaults,timeo=300,retrans=5  0  0

Apply:

sudo mount -a

Step 3: Verify Functionality

  1. On the server:
    echo "Hello from server!" > /mnt/nfs_share/test.txt
  2. On the client:
    cat /mnt/client_share/test.txt  # Should show the message
  3. Create a file on the client and check the server.

Troubleshooting

  • “Access Denied”:
    • Verify client IP in /etc/exports
    • Check chown/chmod on the server directory
  • Mount Hangs:
    • Confirm NFS service is running: sudo systemctl status nfs-server
    • Check firewall rules: sudo ufw status or sudo firewall-cmd --list-all
  • Logs:
    • Server: tail -f /var/log/syslog
    • Client: dmesg | grep nfs

Security Notes

  1. Restrict Exports: Never use * in /etc/exports (e.g., 192.168.0.0/24 is safer than wildcards).
  2. User Permissions: For strict access control:
    • Use sudo chown user:group /mnt/nfs_share
    • Match UID/GIDs across server/client
  3. Kerberos: Enable sec=krb5 in exports for enterprise setups.

Conclusion

NFS transforms cross-system file management into a seamless experience. Once configured, shared directories behave like local storage—ideal for clusters, media servers, or team projects. Test in a safe environment first, then explore advanced tuning like NFSv4.1 (parallel access) or automated mounts with autofs.

> Pro Tip: Replace IPs with hostnames in /etc/exports/fstab if using DNS. Always back up config files before editing!

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다