Tabla de contenido
The Network File System, or NFS as it’s commonly known, is an essential tool that lets you share files and directories between servers and clients on a network. It’s one of the simplest and most efficient ways to share resources on Linux-based systems. If you’re considering setting up your own NFS server on distributions like Ubuntu, Debian, CentOS, Rocky Linux, Alma Linux, or Fedora, you’ve come to the right place! Let me show you how, step by step.
Understanding NFS a bit
Before diving deep into the configuration, it’s worth understanding what NFS is. It’s a protocol that lets Linux machines (and others like MacOS or UNIX systems) mount remote directories as if they were local. So, if you have several devices on your network, you can share files among them seamlessly with NFS. Cool, right?
Why is setting up an NFS server essential?
If you’re running a business or simply have multiple machines at home, file sharing might be a daily task. Imagine if every time you wanted to share a file, you’d need to use a flash drive. Madness! That’s where NFS comes in, allowing you to share directories across multiple devices without a hitch.
Configuration for Ubuntu and Debian
We’ll start with Ubuntu and Debian, two of the friendliest distributions for Linux newcomers. Although the steps are quite similar, there’s always a slight variation worth noting.
Preparation
First things first, always ensure your system is up-to-date. Open your terminal and run:
sudo apt update && sudo apt upgrade
Installing the necessary packages
In your terminal, install the packages we’ll need to set up the NFS server:
sudo apt install nfs-kernel-server
Suppose you want to share the directory /home/your_user/shared. First, you need to grant it the appropriate permissions:
sudo chown nobody:nogroup /home/your_user/shared
Then, modify the /etc/exports file to define which directories you want to share:
sudo nano /etc/exports
Add the following line:
/home/your_user/shared *(rw,sync,no_subtree_check)
Starting the NFS service
With everything set, all that’s left is to start the service and make sure it runs at system boot:
sudo systemctl start nfs-kernel-server sudo systemctl enable nfs-kernel-server
Configuration for CentOS, Rocky Linux, Alma Linux, and Fedora
If you’re on the Red Hat side with distributions like CentOS, Rocky Linux, Alma Linux, or Fedora, the process is just as straightforward, with some slight differences.
Installing necessary packages
Open your terminal and type:
sudo dnf install nfs-utils
Adjusting services
To ensure NFS operates correctly, you’ll need to enable and start a few services:
sudo systemctl enable rpcbind nfs-server sudo systemctl start rpcbind nfs-server
If the directory you wish to share is /home/your_user/shared, ensure it has the correct permissions:
sudo chown nobody:nogroup /home/your_user/shared
Then, like with Ubuntu and Debian, modify the /etc/exports file:
sudo nano /etc/exports
And add:
/home/your_user/shared *(rw,sync,no_root_squash)
Final adjustments and service restart
After setting up the shared directories, have NFS recognize the changes:
sudo exportfs -r
NFS Security
Setting up NFS is easy, but don’t forget about security. Ensure you only share necessary directories and limit access to trusted IPs. Also, consider using firewalls and, if possible, further configurations like SELinux or AppArmor.
Taking the next step
Now that you know how to set up an NFS server on the most popular distributions, it’s time for you to put it into practice. As you’ve seen, although there are some differences based on distribution, the process is pretty straightforward. No excuses not to have your NFS server up and running!
Always remember to test and backup before making changes in production environments. And if you ever feel lost, come back here; I’m here to help! Best of luck with your NFS journey!