Mount a network shared drive on Linux
How to mount a network shared drive on Linux
In this post we will go through the process on how to mount a network shared drive on Linux.The procedure is executed on Debian and Ubuntu distros using the cifs-utils and for CentOS as well. With this method, not only you can mount a network shared drive, you can also use this method to mount other network shared locations(network shared folders or other network shares). I have a network shared storage server, the server has HDDs in RAID configuration and the storage drives are shared over the network, I am going to use this setup as an example. Also in this post, we will cover the steps how to mount the network drives permanently and to mount automatically on boot.
UPDATE: published posts that demonstrates another process – how to setup a network share using NFS for Debian and Ubuntu, Rocky Linux 8 and Alma Linux – Alma Linx Rocky Linux 8, Ubuntu 20.04, Debian 10/11
There are couple of things we need to setup in order to make this configuration. We need to install an app called cifs-utils and we need to create a mount point. Also, for this to work – your network shared drive needs to be on a server with a static IP address.
Bellow you can find a video tutorial as well:
Mount a network shared drive on Linux
Creating a mount point
First we need to create our mount point for our network share and for that we need to use the terminal. We will create the mount point in the /mnt folder. Start the terminal and use the following command:
sudo mkdir /mnt sudo mkdir /mnt/share
Next what we need to do is to install the cifs-utils utility. This software will helps to mount and manage our network shares. Another reason we’re going to use this software is because this software supports other non-Linux partition extensions, such as partitions which Windows use.
To install the software, use the command:
For apt package manager(Debian and Ubuntu based distros):
sudo apt install cifs-utils
For RPM package manager(CentOS/Fedora):
yum install cifs-utils
Mounting the network share
Now we can mount the network shared drive. First, please note, the commands bellow are an example and the parameters which are used are for my network setup. They will not be same as how is your network configured. You need to apply parameters according to your network settings.
First we use the command if credentials are set to the network share(meaning, the username and password is required to access the network share):
sudo mount.cifs //10.0.1.4/share /mnt/share/nmshare/ -o user=share,pass=share
- sudo mount.cifs – To mount the network share using cifs software and with root privileges.
- //10.0.1.4/share – IP address and the name of the shared folder(this you need to change and to match your network settings)
- /mnt/share/nmshare/ – The mount point we created earlier where our network share will be placed.
- -o user=share,pass=share – Adding option to access the network share with credentials(adding username and password). Also, you can add option like this : -o username=share,password=share
If for your network share does not have credentials to access it, then you use the command to publicly mount the network share:
sudo mount.cifs //10.0.1.4/share /mnt/share/nmshare/
Mount permanently and automatically on boot
This method is optional and you do it if you want to.
!!!PLEASE PAY ATTENTION ON THIS STEP!!!
If you don’t do it properly, you could lock up your machine on the next restart. Fstab file is the boot process configuration file which has your HDD’s in it as well. So, if the file is not configured properly, you could prevent the machine from booting.
In order to make this configuration we need to access and edit the fstab config file. I kindly advise to backup the fstab config file first before making any changes to it. For this, we need to use the nano text editor and access the fstab file.
Use the command:
sudo -s nano /etc/fstab
You need to get a window like this. AT THE BOTTOM OF THE FILE add the following line(again the parameters needs to match your network settings):
//10.0.1.4/share /mnt/share/nmshare cifs username=share,password=share 0 0
This is an example if you have credentials set to access your network share. To mount the network share which does not have credentials, use this command:
//10.0.1.4/share /mnt/share/nmshare cifs guest,uid=1000 0 0
Once you finish with editing the file, save and exit.
This was the process how to mount a network shared drive on Linux using cifs-utils. Here we covered the process mounting the network shared drive for Debian / Ubuntu based distros and for CentOs as well. If this does not work out for you or you prefer the some other methods, there’s another way as well using the NFS tool which we mentioned at the beginning of the article we covered the procedure for that tool too.
Thank you very much for your time.