Linux NFS Setup

NFS (Network File System) is a distributed file system protocol that allows you to share files and directories across a network. It is commonly used in Unix and Linux operating systems to enable easy file sharing between multiple machines. In this article, we will discuss how to set up NFS on a Linux system.

Step 1: Install NFS Server

The first step in setting up NFS is to install the NFS server software on the server machine. This can be done using the package manager of your Linux distribution. For example, on a Debian-based system, you can use the following command:

```
sudo apt-get install nfs-kernel-server
```

On a Red Hat-based system, you can use:

```
sudo yum install nfs-utils
```

Step 2: Configure NFS Exports

Once the NFS server software is installed, you need to configure the directories that you want to share. This is done by editing the `/etc/exports` file. Add a line for each directory that you want to share in the following format:

```
/path/to/directory client_ip(options)
```

For example, to share `/data` with a client with IP address `192.168.1.100`, you can add the following line to the file:

```
/data 192.168.1.100(rw,sync)
```

In this example, `rw` indicates that the client has read and write permissions, and `sync` ensures that changes are immediately written to the disk.

Step 3: Export the Directories

After configuring the directories in the `/etc/exports` file, you need to export them using the following command:

```
sudo exportfs -a
```

This command reloads the NFS server configuration and makes the shared directories available to clients.

Step 4: Start the NFS Server

To start the NFS server, use the following command:

```
sudo systemctl start nfs-server
```

You can also enable the NFS server to start automatically on boot with the following command:

```
sudo systemctl enable nfs-server
```

Step 5: Configure NFS Client

On the client machine, you need to install the NFS client software using the package manager. For example, on a Debian-based system, you can use the following command:

```
sudo apt-get install nfs-common
```

On a Red Hat-based system:

```
sudo yum install nfs-utils
```

Step 6: Mount NFS Shares

Finally, you can mount the NFS shares from the server on the client machine. This can be done using the `mount` command. For example, to mount the `/data` directory from the server with IP address `192.168.1.10`, use the following command:

```
sudo mount 192.168.1.10:/data /mnt/data
```

Now, you should be able to access the shared directory `/data` on the client machine at `/mnt/data`.

In conclusion, setting up NFS on a Linux system involves installing the NFS server software, configuring shared directories, exporting them, starting the NFS server, installing the NFS client software on client machines, and mounting the NFS shares. With these steps, you can easily share files and directories across a network using the NFS protocol.