Rakesh Jain
Rakesh Jain

@devops_tech

37 Tweets 2 reads Jul 28, 2023
πŸ§πŸ“πŸ”— Mastering NFS! πŸ”—πŸ“πŸ§
πŸ”—Installing & Configuring NFS on Ubuntu Server!πŸ”—
πŸ” NFS Troubleshooting Examples! πŸ”
A Thread explaining everything πŸ‘‡
What is NFS?
πŸš€ NFS stands for Network File System - a vital protocol for file sharing in Linux/UNIX systems.
🌐 It lets you access files over a network as if they were on your local machine! πŸ–₯️
Ready for installing & configuring NFS?
Let's dive in! πŸŠβ€β™‚οΈ
1/6 πŸš€ First, let's install NFS server and utilities:
sudo apt update && sudo apt install nfs-kernel-server nfs-common
πŸ”„ This gets you the required packages to set up and manage NFS! 🌟 #UbuntuServer #NFS #Installation
2/6 βš™οΈ Next, configure NFS server:
Edit /etc/exports file:
sudo nano /etc/exports
πŸ“ Add a line to share /example_dir with client_ip:
/example_dir client_ip(rw,sync,no_subtree_check)
πŸ”§ Save & exit! πŸ—’οΈ #NFS #LinuxConfig #FileSharing
3/6 πŸ”’ Secure NFS with firewall:
Allow NFS traffic:
sudo ufw allow nfs
πŸ›‘οΈ If using NFSv4, also allow:
sudo ufw allow nfs4
πŸ”₯ Reload firewall:
sudo ufw reload
πŸ”« Now, NFS ports are accessible! πŸ”“ #UbuntuServer #NFS #Security
4/6 🌐 Start NFS server & related services:
sudo systemctl start nfs-server πŸš€
sudo systemctl enable nfs-server 🌟
Check status:
sudo systemctl status nfs-server
πŸ”„ It should be active & running! πŸ’»
#NFS #LinuxCommands #Ubuntu
5/6 πŸ”„ Export shared directory:
Apply the changes:
sudo exportfs -ra
πŸ”„ This exports directories listed in /etc/exports πŸ“‚
Make sure your clients have proper permissions to access! πŸ”‘ #NFS #LinuxConfig #FileSharing
6/6 πŸŽ‰ NFS installation & configuration done! πŸŽ‰ Now you can mount the shared directories on client machines πŸš€ Remember to update /etc/fstab for automounting during boot! πŸŒ„ #UbuntuServer #NFS #LinuxTips
Ready for NFS examples? Let's explore some! πŸŠβ€β™‚οΈ
πŸ“‚ Example 1: Mount Remote Directory πŸ”οΈ
You can mount a remote directory from a server to your local machine using NFS.
sudo mount -t nfs server_ip:/remote_dir /local_dir πŸ“₯
Now, /local_dir is linked to the remote directory! 🌟 #NFS #Linux #FileSharing
πŸ“„ Example 2: List Remote Directory πŸ“œ
With NFS, you can list files in a remote directory! πŸ“‘ Just use:
ls /local_dir πŸ“‚
It will show the files from the remote server's directory! 🌐 #NFS #FileSharing #LinuxTricks
πŸ“ Example 3: Read/Write Operations πŸ“
NFS allows you to read/write files on a remote server! ✏️ For instance:
Read:
cat /local_dir/file.txt πŸ“–
Write:
echo "Hello, NFS!" > /local_dir/file.txt πŸ“
Changes are synced with the remote server! πŸ’Ύ #NFS #Linux #FileAccess
βš™οΈ Example 4: Check NFS Status βš™οΈ
Want to see the NFS status? Use:
showmount -e server_ip πŸ•΅οΈβ€β™‚οΈ
It will display the shared directories from the specified server! πŸ—‚οΈ #NFS #LinuxCommands #FileSharing
πŸ”„ Example 5: Automounting πŸ”„
You can automount NFS shares during boot! πŸš€
Add an entry in /etc/fstab:
server_ip:/remote_dir /local_dir nfs defaults 0 0
πŸ”§ Now, the remote share will be available on boot! 🌟 #NFS #LinuxTricks #Automation
πŸ“ Example 6: Export Directory πŸ“
To share your local directory with remote clients:
Add in /etc/exports:
/local_dir client_ip(rw,sync)
🀝 Now, client_ip can mount and read/write to your shared directory! 🀝 #NFS #FileSharing #Linux
πŸ”’ Example 7: Restrict Access πŸ”’
Secure your NFS shares by allowing specific IPs:
/local_dir client_ip(rw) client2_ip(ro) πŸ”
Here, client_ip has read/write, while client2_ip has only read access! πŸ›‘οΈ #NFS #LinuxSecurity
πŸ“‚ Example 8: NFSv4 ACLs πŸ“‚
NFSv4 supports Access Control Lists (ACLs).
🚦 Set ACL for a file:
setfacl -m u:user:permissions /local_dir/file.txt
πŸ” It grants specific user permissions on the file! πŸ•΅οΈβ€β™€οΈ #NFS #Linux #ACLs
πŸ’Ό Example 9: User Mapping πŸ’Ό
NFS maps local users to remote users using "usermap" file.
πŸ—ΊοΈ Configure in /etc/idmapd.conf:
echo "localuser remoteuser" >> /etc/idmapd.conf
πŸ”„ Now, localuser is recognized as remoteuser on NFS share! πŸ—‚οΈ #NFS #LinuxTricks
πŸš€ Example 10: NFS Performance πŸš€
Boost NFS performance by tuning parameters!
For example, increase the read buffer size:
sudo sysctl -w sunrpc.tcp_slot_table_entries=128
πŸ”§ Test the settings and adjust for your system! βš™οΈ #NFS #LinuxPerformance
🌐 Example 11: Cross-Mounting 🌐
NFS allows cross-mounting, where server1 shares dir1 and server2 shares dir2. 🀝
server1: /dir1 client2_ip(rw)
server2: /dir2 client1_ip(rw)
Now, client1_ip can access dir1 from server1 and vice versa! πŸ”„ #NFS #Linux #FileSharing
πŸ“ˆ Example 12: Monitoring NFS πŸ“ˆ
Monitor NFS performance using tools like nfsstat and nfsiostat. πŸ“Š
nfsstat -s πŸ“‰
nfsiostat πŸ“ˆ
Keep an eye on usage and diagnose any issues! 🚨 #NFS #LinuxMonitoring
πŸ—‘οΈ Example 13: NFS Cleanup πŸ—‘οΈ
To unmount a NFS share:
sudo umount /local_dir
🚫 And to stop sharing a directory:
Remove entry from /etc/exports
πŸ” Keep your system tidy! 🧹 #NFS #LinuxTricks
πŸŽ‰ Example 14: Backup with NFS πŸŽ‰
Use NFS for remote backups!
πŸ—„οΈ Mount the backup directory and copy files:
sudo mount -t nfs backup_server:/backup_dir /mnt cp -r /local_dir /mnt
πŸ”„ Safe backups off-site! πŸ’Ύ
#NFS #LinuxBackup #DataSafety
Hope these NFS examples helped you master the Network File System! 🌟
Happy file sharing across the network! πŸ€πŸš€ #NFS #LinuxTips #FileSharing
πŸ§πŸ” NFS Troubleshooting Examples! πŸ”πŸ§
1/ πŸ”„ Issue: NFS Mount Fails 🚫
If NFS mount fails on the client, check server's export list:
showmount -e server_ip
πŸ•΅οΈβ€β™‚οΈ Ensure the shared directory is listed and accessible by the client IP! πŸ“‚ #NFSTroubleshooting #Linux
2/ 🚧 Issue: Stale File Handle 🚧
Encountering "Stale file handle" error? πŸ˜“
Try remounting the NFS share with:
sudo umount /local_dir sudo mount -a
πŸ”„ This should resolve the stale file handle issue! πŸ’‘ #NFS #LinuxErrors
3/ βš™οΈ Issue: Incorrect NFS Version βš™οΈ
If you face compatibility issues, specify NFS version during mount:
sudo mount -t nfs -o vers=3 server_ip:/remote_dir /local_dir
πŸ› οΈ Adjust the version as needed! πŸ”„ #NFSTroubleshooting #LinuxTips
4/ 🚦 Issue: NFS Slow Performance 🚦
Experiencing slow NFS? Check network connectivity & latency.
πŸ“‰ Also, try mounting with different options:
sudo mount -o rsize=8192,wsize=8192 server_ip:/remote_dir /local_dir
πŸš€ Tune to enhance performance! βš™οΈ #NFS #LinuxPerformance
5/ 🚨 Issue: NFS Firewall Blocking 🚨
If NFS clients can't connect, verify firewall settings: Allow NFS traffic:
sudo ufw allow nfs
πŸ›‘οΈ Reload:
sudo ufw reload
πŸ”₯ Ensure NFS ports are open & accessible! πŸ”“ #NFSTroubleshooting #LinuxSecurity
6/ πŸ“‚ Issue: Incorrect Mount Options πŸ“‚
If you encounter permission errors, check mount options.
🚫 Ensure you have the correct options,
e.g. for read-write access:
sudo mount -o rw server_ip:/remote_dir /local_dir
πŸ”„ Verify & adjust options as needed! βš™οΈ#LinuxErrors
7/ πŸ”„ Issue: NFS Share Not Updating πŸ”„
If changes made on the server aren't reflecting on clients, try:
sudo exportfs -rav
πŸ”„ This refreshes NFS exports and updates clients with the latest changes! πŸš€ #NFSTroubleshooting #LinuxTips
8/ 🚨 Issue: NFS Service Not Starting 🚨
If NFS server fails to start, check the service status: sudo systemctl status nfs-server
πŸ’» Review logs in /var/log/syslog for clues on why it's not starting! πŸ“œ #NFS #LinuxErrors
9/ πŸ“¦ Issue: Insufficient Disk Space πŸ“¦
Running out of disk space on NFS server? Clean up unused files or expand storage!
πŸ—‘οΈπŸ’Ύ Ensure clients have enough space too, to prevent write failures! πŸ’‘ #NFS #DiskSpace #Linux
10/ πŸ”’ Issue: NFS Access Denied πŸ”’
Facing "Permission denied" error? Check server's export options:
cat /etc/exports
πŸ•΅οΈβ€β™‚οΈ Ensure client IP is allowed with proper permissions!
πŸ”‘ Then, remount on the client to apply changes. πŸ”„ #NFS #LinuxSecurity
Troubleshooting NFS can be a puzzle, but these examples should help you tackle more challenges! πŸ› οΈπŸŒŸ #Linux #NFS #Troubleshooting
Retweet this mega thread on NFS if you find it useful. Thanks!

Loading suggestions...