Sharing file system on linux

How to Setup NFS (Network File System) on RHEL/CentOS/Fedora and Debian/Ubuntu

NFS (Network File System) is basically developed for sharing of files and folders between Linux/Unix systems by Sun Microsystems in 1980. It allows you to mount your local file systems over a network and remote hosts to interact with them as they are mounted locally on the same system. With the help of NFS, we can set up file sharing between Unix to Linux system and Linux to Unix system.

Install NFS Server in Linux

Benefits of NFS
  1. NFS allows local access to remote files.
  2. It uses standard client/server architecture for file sharing between all *nix based machines.
  3. With NFS it is not necessary that both machines run on the same OS.
  4. With the help of NFS we can configure centralized storage solutions.
  5. Users get their data irrespective of physical location.
  6. No manual refresh needed for new files.
  7. Newer version of NFS also supports acl, pseudo root mounts.
  8. Can be secured with Firewalls and Kerberos.
NFS Services

Its a System V-launched service. The NFS server package includes three facilities, included in the portmap and nfs-utils packages.

  1. portmap : It maps calls made from other machines to the correct RPC service (not required with NFSv4).
  2. nfs: It translates remote file sharing requests into requests on the local file system.
  3. rpc.mountd: This service is responsible for mounting and unmounting of file systems.
Important Files for NFS Configuration
  1. /etc/exports : Its a main configuration file of NFS, all exported files and directories are defined in this file at the NFS Server end.
  2. /etc/fstab : To mount a NFS directory on your system across the reboots, we need to make an entry in /etc/fstab.
  3. /etc/sysconfig/nfs : Configuration file of NFS to control on which port rpc and other services are listening.

Setup and Configure NFS Mounts on Linux Server

To setup NFS mounts, we’ll be needing at least two Linux/Unix machines. Here in this tutorial, I’ll be using two servers.

  1. NFS Server: nfsserver.example.com with IP-192.168.0.100
  2. NFS Client : nfsclient.example.com with IP-192.168.0.101
Installing NFS Server and NFS Client

We need to install NFS packages on our NFS Server as well as on NFS Client machine. We can install it via “yum” (Red Hat Linux) and “apt-get” (Debian and Ubuntu) package installers.

[[email protected] ~]# yum install nfs-utils nfs-utils-lib [[email protected] ~]# yum install portmap (not required with NFSv4)
[[email protected] ~]# apt-get install nfs-utils nfs-utils-lib

Now start the services on both machines.

[[email protected] ~]# /etc/init.d/portmap start [[email protected] ~]# /etc/init.d/nfs start [[email protected] ~]# chkconfig --level 35 portmap on [[email protected] ~]# chkconfig --level 35 nfs on

After installing packages and starting services on both the machines, we need to configure both the machines for file sharing.

Setting Up the NFS Server

First we will be configuring the NFS server.

Читайте также:  Copying linux file system
Configure Export directory

For sharing a directory with NFS, we need to make an entry in “/etc/exports” configuration file. Here I’ll be creating a new directory named “nfsshare” in “/” partition to share with client server, you can also share an already existing directory with NFS.

Now we need to make an entry in “/etc/exports” and restart the services to make our directory shareable in the network.

[[email protected] ~]# vi /etc/exports /nfsshare 192.168.0.101(rw,sync,no_root_squash)

In the above example, there is a directory in / partition named “nfsshare” is being shared with client IP “192.168.0.101” with read and write (rw) privilege, you can also use hostname of the client in the place of IP in above example.

NFS Options

Some other options we can use in “/etc/exports” file for file sharing is as follows.

  1. ro: With the help of this option we can provide read only access to the shared files i.e client will only be able to read.
  2. rw: This option allows the client server to both read and write access within the shared directory.
  3. sync: Sync confirms requests to the shared directory only once the changes have been committed.
  4. no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger file system, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
  5. no_root_squash: This phrase allows root to connect to the designated directory.

For more options with “/etc/exports“, you are recommended to read the man pages for export.

Setting Up the NFS Client

After configuring the NFS server, we need to mount that shared directory or partition in the client server.

Mount Shared Directories on NFS Client

Now at the NFS client end, we need to mount that directory in our server to access it locally. To do so, first we need to find out that shares available on the remote server or NFS Server.

[[email protected] ~]# showmount -e 192.168.0.100 Export list for 192.168.0.100: /nfsshare 192.168.0.101

Above command shows that a directory named “nfsshare” is available at “192.168.0.100” to share with your server.

Mount Shared NFS Directory

To mount that shared NFS directory we can use following mount command.

[[email protected] ~]# mount -t nfs 192.168.0.100:/nfsshare /mnt/nfsshare

The above command will mount that shared directory in “/mnt/nfsshare” on the client server. You can verify it following command.

[[email protected] ~]# mount | grep nfs sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) nfsd on /proc/fs/nfsd type nfsd (rw) 192.168.0.100:/nfsshare on /mnt type nfs (rw,addr=192.168.0.100)

The above mount command mounted the nfs shared directory on to nfs client temporarily, to mount an NFS directory permanently on your system across the reboots, we need to make an entry in “/etc/fstab“.

Add the following new line as shown below.

192.168.0.100:/nfsshare /mnt nfs defaults 0 0

Test the Working of NFS Setup

We can test our NFS server setup by creating a test file on the server end and check its availability at nfs client side or vice-versa.

At the nfsserver end

I have created a new text file named “nfstest.txt’ in that shared directory.

[[email protected] ~]# cat > /nfsshare/nfstest.txt This is a test file to test the working of NFS server setup.
At the nfsclient end

Go to that shared directory in client server and you’ll find that shared file without any manual refresh or service restart.

[[email protected]]# ll /mnt/nfsshare total 4 -rw-r--r-- 1 root root 61 Sep 21 21:44 nfstest.txt [email protected] ~]# cat /mnt/nfsshare/nfstest.txt This is a test file to test the working of NFS server setup.

Removing the NFS Mount

If you want to unmount that shared directory from your server after you are done with the file sharing, you can simply unmount that particular directory with “umount” command. See this example below.

Читайте также:  Все репозитории kali linux

You can see that the mounts were removed by then looking at the filesystem again.

You’ll see that those shared directories are not available any more.

Important commands for NFS

Some more important commands for NFS.

  1. showmount -e : Shows the available shares on your local machine
  2. showmount -e: Lists the available shares at the remote server
  3. showmount -d : Lists all the sub directories
  4. exportfs -v : Displays a list of shares files and options on a server
  5. exportfs -a : Exports all shares listed in /etc/exports, or given name
  6. exportfs -u : Unexports all shares listed in /etc/exports, or given name
  7. exportfs -r : Refresh the server’s list after modifying /etc/exports

This is it with NFS mounts for now, this was just a start, I’ll come up with more option and features of NFS in our future articles. Till then, Stay connected with Tecmint.com for more exciting and interesting tutorials in future. Do leave your comments and suggestions below in the comment box.

I am a linux server admin and love to play with Linux and all other distributions of it. I am working as System Engineer with a Web Hosting Company.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Install NFS Server on CentOS 8

128 thoughts on “How to Setup NFS (Network File System) on RHEL/CentOS/Fedora and Debian/Ubuntu”

Found some missing files in the fedora 33 servers /etc the exports file has to be created, also I cruised thru usr/systemd.conf files, some needed a user added as only root can access some of them. Redhat has removed the “rsh” login while Debian has it, with rsh I can connect eth0 to the dell idrac port, type rsh 192.168.0.? And can log in gives tons of cli commands that the web-based idrac doesn’t seem to have, not sure there’s a difference in formats. Debian for some reason does not include netstat if config and FTP? Also, fedora7 and 8 had rwhod, whois, telnet, FTP, apache web server. The fefora33 server I’m using lacks these old tools and I’m not sure if I’m getting past the firewall other than pinging my idrac on my dell server! Unfortunately, I have to go online to ad nfs files to make it work in the fedora33 server. I noticed you used init.d but redhat and its subsidiary ones all use the system.d in their configuration, so init.d might not work on a redhat/fedora/centos box! Reply

I have one doubt, why he did not add some services to the firewall without adding? it is possible. below are some of the services – nfs-server, rpcbind mounted, can some confirm Reply

Читайте также:  Установка etcher linux mint

I had difficulty getting the server to reboot, the solution for me was to change the /etc/fstab on the nfsclient to the following: nfsserver:/var/nfsshare/work /opt/work nfs defaults,_netdev,x-systemd.after=nfs-server.service 0 0 Reply

This is one of the easiest installation. But this is not as simple as this is mentioned in the blog. Here the consideration is taken when the Firewall is stopped. Which specific ports to be allowed for NFS server to work properly. Only allowing NFS service is firewall is not working. It keeps on giving error of portmapper and something like that. I am doing it on CentOS 7, NFS server does not work independently so allowing NFS port is not making any difference Reply

Источник

How to share files with Samba

Samba provides easy, flexible, cross-platform, and open source collaboration across your organization.

File system

Career advice

The Samba project provides file sharing and print services for computers on a network. It uses the Server Message Block and Common Internet File System (SMB/CIFS) protocol, so the services created by running Samba are available to Linux, macOS, and Windows clients. It’s an essential service to run in organizations that support multiple operating systems, and it’s even useful on homogenous networks.

It’s not difficult to set up, and all you need is at least one server you want to designate as a file-share host (it doesn’t have to be rack mounted and could even be a dedicated workstation). For client access, Samba is either built into the operating system or easily installed from a repository.

Install Samba

On your designated Samba server, install the Samba package:

This command also installs the samba-common-tools and samba-libs packages.

Next, start the SMB and NMB daemons. The SMB daemon manages most Samba services, while the NMB daemon provides NetBIOS services. Here are the commands:

$ systemctl enable --now smb $ systemctl enable --now nmb

That’s the installation. All that’s left is a little configuration.

Configure your firewall

Make sure that your file-share server is accessible over your network by adding the samba service to your firewall config:

$ sudo systemctl enable --now firewalld $ sudo firewall-cmd --list-services cockpit dhcpv6-client ssh $ sudo firewall-cmd --add-service samba success

Configure Samba

Create a directory on the server to hold your shared files and folders, and change the SELinux context to samba_share_t :

$ sudo mkdir /sambashare $ sudo chcon -t samba_share_t /sambashare/

To configure shares and users, edit the /etc/samba/smb.conf file. The default file has several good examples of common options, including provisions for shared printers and home directories.

There’s a global section, which defines a workgroup. I arbitrarily set mine to SAMBA . I have no other existing workgroups on my network, so the workgroup hardly matters for my setup. If your organization has a specific workgroup structure, then follow that.

[global] workgroup = SAMBA security = user passdb backend = tdbsam . 

By default, your Samba server’s NetBIOS name is the server’s Linux hostname. If you don’t have DNS configured on your local network, you can use the server’s IP address when contacting the Samba server.

[ Download the Linux networking cheat sheet to get a list of Linux utilities and commands for managing servers and networks. ]

Create a shared location

To create a new share location, add a section to the /etc/samba/smb.conf configuration file with these two definitions:

[sambashare] path = /sambashare read only = No

Источник

Оцените статью
Adblock
detector