Red Hat Certified System Administration 8



Chapter 24: Accessing Network Storage


Sommaire

  • Network File System (NFS)
  • Server Message Block (SMB)


Network File System (NFS)


Network File System (NFS)

On Red Hat Enterprise Linux 7, NFS 4 is the default NFS version.
Default Port : 2049

[root@redhat ~]# nfsstat

Mounting the NFS Share

To mount an NFS share, you first need to find the names of the shares. This information can be provided by the administrator, but it is also possible to find out yourself. To discover which shares are available, you have multiple options:

■ If NFSv4 is used on the server, you can use a root mount. That means that you just mount the root directory of the NFS server, and under the mount point you’ll only see the shares that you have access to.

■ Use netstat -an | grep your.nfs.server.ip:port to verify the availability of the mount.

■ Use the showmount -e nfsserver command to find out which shares are available.


NFS Server Configuration Steps

  1. Install Required Packages
  2. Create network storage Directory
  3. Edit /etc/exports file by adding Authorised hosts
  4. Start NFS services
  5. Check Configuration

NFS Server Config Example

[root@redhat ~]# yum install *nfs*
[root@server ~]# mkdir /nfs
[root@server ~]# chmod 1777 /nfs

[root@server ~]# vi /etc/exports
Add this line

/nfs desk1.one.bg(rw,sync)

[root@server ~]# cat /etc/exports

4. Now start your NFS server, and enable it, so that it can withstand reboots. Use below commands for it.

[root@server ~]# systemctl start rpcbind
[root@server ~]# systemctl enable rpcbind
[root@server ~]# systemctl start nfs-server.service
[root@server ~]# systemctl enable nfs-server.service
[root@server ~]# firewall-cmd --permanent --add-service=nfs
[root@server ~]# firewall-cmd --reload

[root@server ~]# exportfs –r
[root@server ~]# exportfs –v
[root@redhat ~]# showmount -e redhat.one.bg Display Shared Directories

NFS Client Config

At Client Server

5. First of all, create a directory which will be mount point for the NFS share.

[root@server ~]# mkdir /nfsshare

6. Now start rpcbind service and enable it.

[root@server ~]# systemctl start rpcbind
[root@server ~]# systemctl enable rpcbind

Note: Client server does not require NFS services to be running.

7. Now, mount the NFS share on your client server with mount command.
[root@server ~]# mount –t nfs redhat.one.bg:/nfs /nfsshare

For permanent mounting make entry in /etc/fstab file like below and test by rebooting the server.
[root@server ~]# vi /etc/fstab
redhat.one.bg:/nfs /nfsshare nfs defaults 0 0

This is how you can setup NFS server and share directories using it to the client.
You can expect tutorials on Kerberos enabled NFS sharing, troubleshooting NFS, sharing trough NFS version 4.


Mounting NFS Shares Through fstab

server:path /mountpoint fstype option_1,...,option_n, 0 0

server1:/share /nfs/mount/point nfs,_netdev,x-systemd. automount, sync 0 0

When making an NFS mount through fstab, you have a few options to consider:

■ In the first column, you need to specify the server and share name. Use a colon after the name of the server to identify the mount as an NFS share.

■ The second column has the file system where you want to do the mount; this is not different from any regular mount.

■ The third column contains the NFS file system type.

■ The fourth column that is used to specify mount options includes the sync option. This ensures that modified files are committed to the remote file system immediately and are not placed in write buffers first (which would increase the risk of data getting lost).

■ The fifth column contains a zero, which means that no backup support through the dump utility is requested.

■ The sixth column also contains a zero, to indicate that no fsck has to be performed on this file system while booting to check the integrity of the file system. The integrity of the file system would need to be checked on the server, not on the client.


Server Message Block (SMB)


Server Message Block (SMB)

You just learned how to use NFS for accessing file systems on remote computers. NFS is fast and convenient, but it also has an major disadvantage: it works only between Linux and UNIX machines. To offer access to other types of clients, you’ll need to use a filesharing protocol that is available on those clients as well. The Common Internet File System (CIFS) is such a protocol, and it is offered by the Linux Samba server. You’ll learn how to set up a Samba server to offer file shares.

- Samba is a very versatile service that you can use for different purposes on your network. Apart from sharing files, it can share printers and also offer Windows domain services such as directory services.

- You can even integrate Samba into an Active Directory domain and make it a member server of Active Directory. This means that all users in Active Directory get easy access to the resources you offer on the Samba server. The most popular use of Samba, however, is as a file server.

Mounting SMB File Systems

To ensure the best possible compatibility for file exchange between different operating systems, Samba is a common solution. On Red Hat Enterprise Linux, you can configure the Samba server to provide access to clients using the Server Message Block (SMB) or Common Internet File System (CIFS) protocols to access these shares. You can also set up Red Hat Enterprise Linux as a client to servers that are offering SMB or CIFS shares, which allows Red Hat servers to access Windows shares directly. This procedure can be applied to mount SMB-compatible shares that are offered from any platform, so it works on Windows shares and on Linux shares.

NOTE Different terminology is used when talking about SMB-based services. The standard protocol that is offered by Windows servers is known as the Server Message Block (SMB) protocol. This protocol on Linux is implemented by the Samba server. CIFS is a dialect of SMB, and it is rather common that SMB and CIFS are used interchangeably.


Mounting SMB Shares

[root@redhat ~]# mount -t cifs -o user=guest //192.168.122.200/data /mnt

Authenticating to SMB Shares

[root@redhat ~]# mount -o username=sambauser1 //server/share /somewhere

Mounting SMB Shares Through fstab

When mounting SMB file systems through /etc/fstab, you need to consider a specific challenge: You need to specify the user credentials that are needed to issue the mount. On an NFS share, this is not necessary because the user who accesses the shared file system by default does so using his own credentials. While mounting a Samba share through /etc/fstab, these user credentials are normally specified with the username= and password= mount options, but it is not a good idea to put these in clear text in the /etc/fstab file.

As an alternative to specifying credentials in the /etc/fstab file directly, you can consider using a credentials file. When using a credentials file, the credentials file itself contains the username, password, and (optionally) the domain you want to connect to. When using a credentials file, it is mandatory to secure the file. The best way to secure it is by putting it in the home directory of the root user, set the owners to root:root, and set the permission mode 600. The contents of the creds file can look like

Example of a Credentials File

username=linda
password=secret
domain=mydomain

To use a credentials file when mounting from the command line, you can include the -o credentials= filename option, as in the following:

[root@redhat ~]# mount -t cifs -o credentials=/root/creds //server1/data /mnt/data

To do the same from the /etc/fstab file, the following line needs to be included in /etc/fstab:

//server1/data /mnt/data cifs _netdev,, x-systemd. automount,credentials=/root/creds 0 0


SMB Server


Application

[root@redhat ~]# mkdir /SAMBA-SHARE
[root@redhat ~]# chmod 777 /SAMBA-SHARE/
[root@redhat ~]# chown -R nobody:nobody /SAMBA-SHARE
[root@redhat ~]# yum install *samba*
[root@redhat ~]# vi /etc/samba/smb.conf



/etc/samba/smb.conf Configuration Example [homes]
browseable = yes

[global]
workgroup = WORKGROUP
netbios name = redhat
security = user

[Anonymous]
comment = Anonymous File Server Share
path = /SAMBA-SHARE
browsable =yes
writable = yes
guest ok = yes
read only = no
force user = nobody

Go to the bottom of the configuration file, and add the following share configuration:

[sambafiles]
comment = samba files
path = /SAMBA-SHARE
writable = yes
valid user = root, user1, user2


[root@redhat ~]# smbpasswd -a user1
New SMB password:
Retype new SMB password:
Added user user1.

[root@redhat ~]# smbpasswd -a nobody
[root@redhat ~]# systemctl start smb.service
[root@redhat ~]# systemctl enable smb.service

[root@redhat ~]# systemctl start nmb.service
[root@redhat ~]# systemctl enable nmb.service

[root@redhat ~]# firewall-cmd --permanent --add-service=samba
[root@redhat ~]# firewall-cmd --reload

Browse mapping Network on Windows Desktop

[root@redhat ~]# touch /SAMBA-SHARE/SAMBA-TEST
Verify file on Windows Desktop

SMB Client

Discovering SMB Shares

Before an SMB share can be mounted, make sure that the cifs-utils and the sambaclient RPM packages are installed on the client. Also, you need to add the sambaclient service to the firewall configuration on the client by using firewall-cmd --add-service samba-client --permanent; firewall-cmd --reload . After installing this, you can use the smbclient -L command to discover available SMB shares.

The smbclient command asks for the password of the current user. This is because smbclient is a very generic utility that allows you to list shares but also to log in to Samba shares on remote servers and fetch files from the remote server. To list shares, however, no credentials are required. So, when the command asks for the password, you may just press Enter . Alternatively, you can use the -Uusername option with smbclient , to authenticate using a valid Samba user account. shows the result of the smbclient -L command.

[root@localhost ~]# smbclient -L 192.168.122.201
Enter root's password:
Anonymous login successful
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]
Sharename Type Comment
--------- ---- -------
data Disk Demo data directory
homedirs Disk LDAP user home directories
IPC$ IPC IPC Service (Samba Server Version 4.1.1)
Anonymous login successful
Domain=[MYGROUP] OS=[Unix] Server=[Samba 4.1.1]

Server Comment
--------- -------
LABIPA Samba Server Version 4.1.1
Workgroup Master
--------- -------
MYGROUP LABIPA

Listing Samba Shares with net share
Server Comment
--------- -------
LABIPA Samba Server Version 4.1.1
Workgroup Master
--------- -------
MYGROUP LABIPA
[root@server1 ~]# net share -l
Enter root's password:
Anonymous login successful
Enumerating shared resources (exports) on remote server:
Share name Type Description
---------- ---- -----------
sambashare Disk Sambashare
IPC$ IPC IPC Service (Samba Server Version 4.1.12)
textprinter Print textprinter
DummyPrinter Print DummyPrinter

Eninam BAGNABANA     |         |     bagnadavid@outlook.fr     |