0% found this document useful (0 votes)
4 views

Linux-ALL-NFS-Command

The document provides detailed instructions for configuring and managing an NFS server and client setup using the nfs-utils and autofs packages. It includes steps for installation, service management, firewall configuration, and setting up shared directories. Additionally, it covers both temporary and permanent mounting of NFS shares on the client side.

Uploaded by

jobaer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Linux-ALL-NFS-Command

The document provides detailed instructions for configuring and managing an NFS server and client setup using the nfs-utils and autofs packages. It includes steps for installation, service management, firewall configuration, and setting up shared directories. Additionally, it covers both temporary and permanent mounting of NFS shares on the client side.

Uploaded by

jobaer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Pacage Name :nfs-utils

Service Name :nfs-server.service

Configfile :/etc/exports

or /etc/exports.d/anyname.exports

check :showmount -e

showmount -e <localhost>

showmount -e <Name/IP>

exportfs (Only for self system)

reload :exports -r

or exports-avr

firewall allow :nfs , rpc-bind , mountd

Server Side Configuration :

============================================================

[root@localhost yum.repos.d]# rpm -qa nfs-utils

[root@localhost yum.repos.d]# yum install nfs-utils

[root@localhost yum.repos.d]# rpm -qa nfs-utils

nfs-utils-2.5.4-10.el9.x86_64

[root@localhost ~]# cat /etc/services | grep nfs

nfs 2049/tcp nfsd shilp # Network File System

nfs 2049/udp nfsd shilp # Network File System

nfs 2049/sctp nfsd shilp # Network File System

netconfsoaphttp 832/tcp # NETCONF for SOAP over HTTPS

netconfsoaphttp 832/udp # NETCONF for SOAP over HTTPS

netconfsoapbeep 833/tcp # NETCONF for SOAP over BEEP

netconfsoapbeep 833/udp # NETCONF for SOAP over BEEP


nfsd-keepalive 1110/udp # Client status info

[root@localhost yum.repos.d]# systemctl status nfs-server.service

○ nfs-server.service - NFS server and services

Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)

Active: inactive (dead)

[root@localhost yum.repos.d]#

[root@localhost yum.repos.d]# systemctl enable nfs-server.service

Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service →


/usr/lib/systemd/system/nfs-server.service.

[root@localhost yum.repos.d]#

[root@localhost yum.repos.d]# systemctl restart nfs-server.service

[root@localhost yum.repos.d]#

[root@localhost yum.repos.d]# systemctl status nfs-server.service

● nfs-server.service - NFS server and services

Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)

Active: active (exited) since Mon 2023-10-16 09:37:18 +06; 26s ago

Process: 32214 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)

Process: 32215 ExecStart=/usr/sbin/rpc.nfsd (code=exited, status=0/SUCCESS)

Process: 32232 ExecStart=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ;
fi (code=e>

Main PID: 32232 (code=exited, status=0/SUCCESS)

[root@localhost yum.repos.d]# showmount -e

Export list for localhost.localdomain:


[root@localhost yum.repos.d]#

[root@localhost yum.repos.d]# mkdir /nfs-share

[root@localhost yum.repos.d]# cd /nfs-share/

[root@localhost nfs-share]# cat >f1

file sharing1

[root@localhost nfs-share]# cat >f2

file sharing2

[root@localhost nfs-share]#

[root@localhost nfs-share]# vim /etc/exports

/nfs-share 192.168.0.0/24(rw,sync)

[root@localhost nfs-share]# setfacl -m u:nobody:rwx /nfs-share/

[root@localhost nfs-share]#

=>Permiting rwx to nfs clientside user

[root@localhost nfs-share]# firewall-cmd --permanent --add-service=nfs

success

[root@localhost nfs-share]# firewall-cmd --permanent --add-service=rpc-bind

success
[root@localhost nfs-share]# firewall-cmd --permanent --add-service=mountd

success

[root@localhost nfs-share]# firewall-cmd --reload

success

[root@localhost nfs-share]# firewall-cmd --list-all

public (active)

target: default

icmp-block-inversion: no

interfaces: ens160

sources:

services: cockpit dhcpv6-client mountd nfs rpc-bind ssh

ports:

protocols:

[root@localhost nfs-share]# systemctl reload nfs-server.service

[root@localhost nfs-share]#

[root@localhost nfs-share]# showmount -e

Export list for localhost.localdomain:

/nfs-share 192.168.0.0/24

[root@localhost nfs-share]#

Clientside :

============

Temporary Mount

===============
[root@newhost ~]# rpm -qa nfs-utils

[root@newhost ~]#

[root@newhost ~]# yum install nfs-utils

[root@newhost ~]# systemctl status nfs

nfs-blkmap.service nfs-idmapd.service nfs-utils.service

nfs-client.target nfs-mountd.service

nfsdcld.service nfs-server.service

[root@newhost ~]# systemctl status nfs-server.service

○ nfs-server.service - NFS server and services

Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vend>

Active: inactive (dead)

[root@newhost ~]# systemctl enable nfs-server.service

Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service →


/usr/lib/systemd/system/nfs-server.service.

[root@newhost ~]#

[root@newhost ~]# systemctl restart nfs-server.service

[root@newhost ~]#

[root@newhost ~]# systemctl status nfs-server.service

● nfs-server.service - NFS server and services

Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendo>

Active: active (exited) since Mon 2023-10-16 10:01:24 +06; 23s ago

Process: 3384 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUC>

Process: 3385 ExecStart=/usr/sbin/rpc.nfsd (code=exited, status=0/SUCCESS)


Process: 3402 ExecStart=/bin/sh -c if systemctl -q is-active gssproxy; then>

Main PID: 3402 (code=exited, status=0/SUCCESS)

CPU: 49ms

[root@newhost ~]# showmount -e 192.168.0.168

Export list for 192.168.0.168:

/nfs-share 192.168.0.0/24

[root@newhost ~]#

[root@newhost ~]# mount 192.168.0.168:/nfs-share /mnt

[root@newhost ~]#

[root@newhost ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev

tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm

tmpfs tmpfs 778M 9.7M 769M 2% /run

/dev/nvme0n1p2 xfs 5.0G 3.9G 1.2G 77% /

/dev/nvme0n1p1 xfs 5.0G 257M 4.8G 6% /boot

/dev/nvme0n1p3 xfs 5.0G 73M 5.0G 2% /home

tmpfs tmpfs 389M 96K 389M 1% /run/user/0

/dev/sr0 iso9660 8.0G 8.0G 0 100% /rpms

192.168.0.168:/nfs-share nfs4 5.0G 3.9G 1.2G 77% /mnt

[root@newhost ~]# ls /mnt/

f1 f2

[root@newhost ~]# cat /mnt/f1

file sharing1
ClientSide

===================

Permanent Mount:

===================

[root@newhost mnt]# vim /etc/fstab

192.168.0.168:/nfs-share /mnt nfs4 defaults 00

[root@newhost mnt]# mount -av

/ : ignored

/boot : already mounted

/home : already mounted

none : ignored

/mnt : already mounted

[root@newhost mnt]#

[root@newhost mnt]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev

tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm

tmpfs tmpfs 778M 9.7M 769M 2% /run

/dev/nvme0n1p2 xfs 5.0G 3.9G 1.2G 77% /

/dev/nvme0n1p1 xfs 5.0G 257M 4.8G 6% /boot

/dev/nvme0n1p3 xfs 5.0G 73M 5.0G 2% /home


tmpfs tmpfs 389M 92K 389M 1% /run/user/0

/dev/sr0 iso9660 8.0G 8.0G 0 100% /rpms

192.168.0.168:/nfs-share nfs4 5.0G 3.9G 1.2G 77% /mnt

[root@newhost mnt]#

[root@newhost mnt]# cd /mnt/

[root@newhost mnt]#

Autofs / Automount

===================

Packege Name :autofs

Service Name :autofs.service

Configfile :/etc/auto.master.d/anyname.autofs

or /etc/auto.misc

[root@newhost mnt]# rpm -qa autofs

[root@newhost mnt]#

[root@newhost mnt]# yum install autofs

[root@newhost mnt]# rpm -qa autofs

autofs-5.1.7-27.el9.x86_64

[root@newhost mnt]# systemctl status autofs.service

○ autofs.service - Automounts filesystems on demand

Loaded: loaded (/usr/lib/systemd/system/autofs.service; disabled; vendor p>

Active: inactive (dead)


lines 1-3/3 (END)

[root@newhost mnt]# systemctl enable autofs.service

Created symlink /etc/systemd/system/multi-user.target.wants/autofs.service →


/usr/lib/systemd/system/autofs.service.

[root@newhost mnt]#

[root@newhost mnt]# systemctl restart autofs.service

[root@newhost mnt]#

[root@newhost mnt]# systemctl status autofs.service

● autofs.service - Automounts filesystems on demand

Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor pr>

Active: active (running) since Mon 2023-10-16 11:26:07 +06; 18s ago

Main PID: 2556 (automount)

Tasks: 5 (limit: 24519)

Memory: 1.7M

CPU: 44ms

CGroup: /system.slice/autofs.service

└─2556 /usr/sbin/automount --systemd-service --dont-check-daemon

Oct 16 11:26:06 newhost systemd[1]: Starting Automounts filesystems on demand...

Oct 16 11:26:07 newhost

[root@newhost mnt]# rpm -qc autofs

/etc/auto.master

/etc/auto.misc

/etc/auto.net

/etc/auto.smb
/etc/autofs.conf

/etc/autofs_ldap_auth.conf

/etc/sysconfig/autofs

/usr/lib/systemd/system/autofs.service

[root@newhost mnt]#

[root@newhost ~]# cd /etc/auto.master.d

[root@newhost auto.master.d]# vim anyname.autofs

/- /etc/auto.misc

[root@newhost auto.master.d]# vim /etc/auto.misc

# This is an automounter map and it has the following format

# key [ -mount-options-separated-by-comma ] location

# Details may be found in the autofs(5) manpage

cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

# the following entries are samples to pique your imagination

#linux -ro,soft ftp.example.org:/pub/linux


/mnt -rw,sync 192.168.0.168:/nfs-share (write this line)

#boot -fstype=ext2 :/dev/hda1

#floppy -fstype=auto :/dev/fd0

#floppy -fstype=ext2 :/dev/fd0

#e2floppy -fstype=ext2 :/dev/fd0

[root@newhost auto.master.d]# systemctl restart autofs.service

[root@newhost auto.master.d]# grep -v "#" /etc/autofs.conf

=>Show all line those is not marked by #

[root@newhost auto.master.d]# vim /etc/autofs.conf

# Define default options for autofs.

[ autofs ]

# master_map_name - default map name for the master map.

#master_map_name = auto.master

# timeout - set the default mount timeout in seconds. The internal

# program default is 10 minutes, but the default installed

# configuration overrides this and sets the timeout to 5

# minutes to be consistent with earlier autofs releases.

timeout = 30 (Set the auto mount time as secound)

# master_wait - set the default maximum number of retries (actual


# iterations is half this, each is delayed by 2 seconds

# before retrying) waiting for the master map to become

# available if it cannot be read at program start

# (default 10, then continue). This can be longer

# if the map source itself waits for availability

# (such as sss).

[root@newhost auto.master.d]# systemctl restart autofs.service

[root@newhost auto.master.d]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev

tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm

tmpfs tmpfs 778M 9.7M 769M 2% /run

/dev/nvme0n1p2 xfs 5.0G 3.9G 1.2G 77% /

/dev/nvme0n1p1 xfs 5.0G 257M 4.8G 6% /boot

/dev/nvme0n1p3 xfs 5.0G 73M 5.0G 2% /home

tmpfs tmpfs 389M 96K 389M 1% /run/user/0

/dev/sr0 iso9660 8.0G 8.0G 0 100% /rpms

[root@newhost auto.master.d]#

[root@newhost auto.master.d]# ls /mnt/

f1 f2 f3 f4

[root@newhost auto.master.d]#

[root@newhost auto.master.d]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev

tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm


tmpfs tmpfs 778M 9.7M 769M 2% /run

/dev/nvme0n1p2 xfs 5.0G 3.9G 1.2G 77% /

/dev/nvme0n1p1 xfs 5.0G 257M 4.8G 6% /boot

/dev/nvme0n1p3 xfs 5.0G 73M 5.0G 2% /home

tmpfs tmpfs 389M 96K 389M 1% /run/user/0

/dev/sr0 iso9660 8.0G 8.0G 0 100% /rpms

192.168.0.168:/nfs-share nfs4 5.0G 3.9G 1.2G 77% /mnt

[root@newhost auto.master.d]#

For Q. Solve

==================

Server side :

==================

[root@localhost ~]# mkdir /home/area -p (execute it client side also, need same username with same
uid bothside)

[root@localhost ~]# useradd depo1 -d /home/area/depo1 -u 5001

[root@localhost ~]# useradd depo2 -d /home/area/depo2 -u 5002

[root@localhost ~]# useradd depo5 -d /home/area/depo5 -u 5005

[root@localhost ~]# useradd depo10 -d /home/area/depo10 -u 5010

[root@localhost ~]# ssh root@192.168.1.18 "useradd depo1 -d /home/area/depo1 -u 5001"

root@192.168.1.18's password:
[root@localhost ~]# ssh root@192.168.1.18 "useradd depo2 -d /home/area/depo2 -u 5002"

root@192.168.1.18's password:

[root@localhost ~]# ssh root@192.168.1.18 "useradd depo5 -d /home/area/depo5 -u 5005"

root@192.168.1.18's password:

[root@localhost ~]# ssh root@192.168.1.18 "useradd depo10 -d /home/area/depo10 -u 5010"

root@192.168.1.18's password:

[root@localhost ~]# getfacl /home/area/

getfacl: Removing leading '/' from absolute path names

# file: home/area/

# owner: root

# group: root

user::rwx

group::r-x

other::r-x

[root@localhost ~]# vim /etc/exports.d/user.exports

/home/area 192.168.1.0/24(rw,sync)

[root@localhost ~]# systemctl enable nfs-server.service

Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service →


/usr/lib/systemd/system/nfs-server.service.

[root@localhost ~]# systemctl restart nfs-server.service


[root@localhost ~]# firewall-cmd --reload

success

[root@localhost ~]# showmount -e

Export list for localhost.localdomain:

/home/area 192.168.1.0/24

Client Side :

=========================

[root@newhost ~]# yum install autofs

[root@newhost ~]# systemctl enable autofs.service

Created symlink /etc/systemd/system/multi-user.target.wants/autofs.service →


/usr/lib/systemd/system/autofs.service.

[root@newhost ~]# systemctl restart autofs.service

[root@newhost ~]# systemctl status autofs.service

● autofs.service - Automounts filesystems on demand

Loaded: loaded (/usr/lib/systemd/system/autofs.service; enabled; vendor pr>

Active: active (running) since Wed 2023-10-18 13:06:36 +06; 9s ago

Main PID: 2448 (automount)

Tasks: 5 (limit: 24519)

Memory: 1.8M

CPU: 40ms

CGroup: /system.slice/autofs.service

└─2448 /usr/sbin/automount --systemd-service --dont-check-daemon

[root@newhost ~]# systemctl restart autofs.service

[root@newhost ~]#
[root@newhost ~]# showmount -e 192.168.1.13

Export list for 192.168.1.13:

/home/area 192.168.1.0/24

[root@newhost ~]# su - depo1

[depo1@newhost ~]$ pwd

/home/area/depo1

[depo1@newhost ~]$ logout

[root@newhost ~]# rm -rf /home/area/

[root@newhost ~]# su - depo1

su: warning: cannot change directory to /home/area/depo1: No such file or directory

[depo1@newhost root]$ pwd

/root

[depo1@newhost root]$ logout

[root@newhost ~]# vim /etc/auto.master

# mount-point [map-type[,format]:]map [options]

# For details of the format look at auto.master(5).

/misc /etc/auto.misc

/home/area /etc/auto.misc

# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"

# options are explicitly given.

/net -hosts

[root@newhost ~]# vim /etc/auto.misc

# key [ -mount-options-separated-by-comma ] location

# Details may be found in the autofs(5) manpage

cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

# the following entries are samples to pique your imagination

#linux -ro,soft ftp.example.org:/pub/linux

* -rw,sync 192.168.1.13:/home/area/&

remote10 -ro,sync 192.168.1.13:/home/area/depo10

#boot -fstype=ext2 :/dev/hda1

#floppy -fstype=auto :/dev/fd0

[root@newhost ~]# systemctl restart autofs.service

[root@newhost ~]#

[root@newhost ~]# df -hT

Filesystem Type Size Used Avail Use% Mounted on

devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev

tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm

tmpfs tmpfs 778M 9.7M 769M 2% /run


/dev/nvme0n1p2 xfs 5.0G 3.9G 1.2G 77% /

/dev/nvme0n1p1 xfs 5.0G 257M 4.8G 6% /boot

/dev/nvme0n1p3 xfs 5.0G 68M 5.0G 2% /home

tmpfs tmpfs 389M 96K 389M 1% /run/user/0

/dev/sr0 iso9660 8.0G 8.0G 0 100% /rpms

[root@newhost ~]#

[root@newhost ~]# su - depo1

[depo1@newhost ~]$ pwd

/home/area/depo1

[depo1@newhost ~]$ df -hT

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy