Create NFS server and mount on client on Linux

Summary

This is a quick tutorial that guides you to create NFS server and mount it on your client.

Install required package

  • If you are using OEL7, then you don’t have to install packages, since they are installed by default.
  • If not, you are required to install portmap and nfs-utils.

You can use rpm -qa | grep portmap to see if portmap is installed, also apt --installed list can be used for whom use APT.

For those who didn’t install required packages, you can download required rpm package mentioned above and run following command rpm -ivh <RPM_PACKAGE>.rpm to install.

If you cannot use RPM, you can also use YUM or APT to install these 2 packages by running sudo yum install <YUM_PACKAGE> or sudo apt install <APT_PACKAGE>.

/etc/exports

Edit your /etc/exports to create rules for NFS.

Following is the format of /etc/exports.

<DIR_TO_USED_FOR_NFS> <CLIENT_IP_ADDRESS>/<MASK>(<LIST_OF_RIGHTS>)

Attention, there’s no space betwwen <MASK> and (<LIST_OF_RIGHTS>).

  • <DIR_TO_USED_FOR_NFS>: The directory that you want to share.
  • <CLIENT_IP_ADDRESS>: Client IP address that will be allowed to connect.
  • <MASK>: Network mask.
  • <LIST_OF_RIGHTS>: Rights for clients, separates by comma.

<LIST_OF_RIGHTS> can be the following options
- ro: Read only,
- rw: Read and write.
- all_squash: All remote users will be marked as anonymous.
- root_squash: Root remote users will be marked as anonymous. (This is recommended)
- no_all_squash: Negation of all_squash.
- no_root_squash: Negation of root_squash. (This is NOT recommended).
- sync: Sync changes.
- etc.

Start NFS server

  • If you are using OEL7, NFS server is started by default.

Use following command as root user to start NFS.

# service portmap start
# service nfs start

Be aware that you have to run commands above accordingly.

Also you can set to start NFS on start up by running following commands as root user.

# chkconfig --list portmap
# chkconfig --list nfs

Refresh export settings

exportfs -[aruv] can be used to refresh /etc/exports settings.

FYI exportfs located in /sbin.

Options:
- exportfs -a: Mount all settings in /etc/exports.
- exportfs -r: Refresh /etc/exports and update /etc/exports and var/lib/nfs/xtab.
- exportfs -u <DIR>: Unmount desinated directory.
- exportfs -v: Display shared directories.

Mount on clients

Example

Share /nfsserver to 192.168.0.0/24 with read and write rights, regards all root users as anonymous user.

  • Edit /etc/exports
/nfsserver 192.168.0.0/24(rw,root_squash,sync)
  • Refresh after editing /etc/exports.
# /sbin/exportfs -a
  • Make directory on client.
# mkdir /nfsshare
  • Mount NFS to /nfsshare
mount <NFS_SERVER_IP_ADDRESS>:/nfsserver /nfsshare
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值