Mounting network shares

So far in this chapter, we've worked through creating both NFS and Samba shares. But we haven't actually mounted any of those shares yet. In this section, we'll take care of that.

In Linux, the mount command works for mounting just about everything. Whether you connect an external hard drive, insert a CD, or wish to mount a network share, the mount command serves as a Swiss Army Knife to allow you to mount such resources to your system. The mount command allows you to mount a resource and attach it to a local directory on your system. In most cases, mount runs automatically on most Linux systems where a graphical desktop environment is used. You've probably seen this if you've inserted a flash drive or some sort of optical media. In network shares, these are not mounted automatically, though they can be configured to be.

Perhaps the easiest way to mount network shares is to use a GUI file manager if you are using a system with a desktop environment installed. If you click on a file share, it will likely be mounted and you will be allowed to access it providing you have the necessary permissions on that system to do so. Nautilus, Caja, Pcmanfm, and Dolphin are popular Linux file managers.

Mounting network shares

The pcmanfm file manager, viewing shares from a Samba file server

The mount command is most useful on systems without a graphical environment, or when you'd prefer to mount a resource somewhere other than the default. To use the mount command, give it the type of resource you'd like to mount, where it can find the resource, followed by which local directory to use for the mount. For example, to mount an NFS export, we might do something like this:

# mount -t nfs 10.10.10.101:/exports/docs /mnt/docs

Alternatively, use the following command if we set our NFS root, as I mentioned earlier:

# mount -t nfs 10.10.10.101:/docs /mnt/docs

In that example, we tell the mount command we'd like to mount an NFS export by providing it with the -t parameter followed by nfs for the type. In my lab, this share exists on a computer with an IP address 10.10.10.101, which I provide next with a colon and the directory on that system I'm accessing. In this case, /exports/docs on 10.10.10.101 is being accessed. Finally, I have a local directory /mnt/docs, which exists on my local computer where I'd like for this share to be mounted. After executing this command, each time I access /mnt/docs on my local computer, I'm actually accessing /exports/docs on my file server. After using this export, I simply unmount it:

# umount /mnt/docs

Mounting a Samba share on a Linux machine is a bit more involved. I'll include an example command that can be used to mount a Samba share from that same server. But before we get to that, you'll first need to have the necessary packages installed on your system in order to be able to mount Samba shares. On CentOS, install samba-client. On Debian, the package is smbclient. After you install the required package, you should be able to mount Samba shares by executing the following command:

# mount -t cifs //10.10.10.101/Videos -o username=jay /mnt/samba/videos

If you need to access the resource via a password, use the following command:

# mount -t cifs //10.10.10.101/Videos -o username=jay, password=mypassword /mnt/samba/videos

As you can see, the same basic idea is used to mount a Samba share. But in this case, we format our target path differently, we use cifs for the filesystem type and we also include the username (and password, if your Samba server requires it). As in previous examples, we end the command with a local directory we would like to attach the mount to. In this case, I've created a /mnt/samba/Videos directory for this share.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset