46 Mount and unmount network file systems using NFS

Опубликовано: 24 Июль 2026
на канале: Engineering Academy Online
50
0

*Mounting and Unmounting Network File Systems (NFS)*

NFS (Network File System) allows you to mount remote directories from another machine over the network, making it available as if it were a local directory. Here's a small description of how to *mount* and *unmount* network file systems using NFS.

---

*1. Mount NFS Filesystem*

#### *Step 1: Install NFS Client (if not already installed)*

Before mounting an NFS share, ensure that the NFS client utilities are installed.

On Debian-based systems (e.g., Ubuntu):
```bash
sudo apt-get install nfs-common
```

On Red Hat-based systems (e.g., CentOS):
```bash
sudo yum install nfs-utils
```

#### *Step 2: Mount the NFS Share*

To mount an NFS share, use the `mount` command with the server's IP address or hostname and the path to the shared directory.

**Mount NFS share**:
```bash
sudo mount -t nfs nfs-server-ip:/path/to/share /mnt/nfs
```

Example:
```bash
sudo mount -t nfs 192.168.1.100:/data /mnt/nfs
```

`nfs-server-ip`: The IP address or hostname of the NFS server.
`/path/to/share`: The directory on the NFS server that you want to mount.
`/mnt/nfs`: The local directory where the NFS share will be mounted.

#### *Step 3: Verify the Mount*

To verify that the NFS share has been mounted correctly, use the `df -h` or `mount` command:

```bash
df -h
```

This should show the NFS share mounted at `/mnt/nfs`.

---

*2. Unmount NFS Filesystem*

To unmount an NFS share, use the `umount` command.

#### *Step 1: Unmount the NFS Share*

**Unmount NFS share**:
```bash
sudo umount /mnt/nfs
```

Alternatively, you can unmount it by specifying the NFS server and shared path:
```bash
sudo umount nfs-server-ip:/path/to/share
```

#### *Step 2: Verify the Unmount*

After unmounting, check that the NFS share is no longer mounted:
```bash
df -h
```

If the share was unmounted successfully, it should no longer appear in the list.

---

*3. Auto-Mount NFS at Boot*

To mount the NFS share automatically at boot, add an entry to the `/etc/fstab` file:

#### **Add Entry to `/etc/fstab`**:
```bash
nfs-server-ip:/path/to/share /mnt/nfs nfs defaults 0 0
```

Example:
```bash
192.168.1.100:/data /mnt/nfs nfs defaults 0 0
```

This ensures the NFS share is mounted each time the system starts.

---

*Summary:*

1. **Mount NFS Share**:
```bash
sudo mount -t nfs nfs-server-ip:/path/to/share /mnt/nfs
```

2. **Unmount NFS Share**:
```bash
sudo umount /mnt/nfs
```

3. **Auto-Mount at Boot**:
Add an entry to `/etc/fstab`:
```bash
nfs-server-ip:/path/to/share /mnt/nfs nfs defaults 0 0
```

Mounting and unmounting NFS shares is a straightforward way to share files across a network while ensuring remote directories are easily accessible locally.