iptables 开放 nfs 端口
-
nfs server 搭建流程
-
省略具体步骤,需要确认server 侧两个服务是否已经开启
- systemctl status rpcbind.service
- systemctl status nfs-server.service
-
配置文件写入共享的存储目录,省略规则介绍
-
创建共享目录:/data/nfs_share
-
[root@hs21 ctsiadmin]# cat /etc/exports /data/nfs_share/ 192.168.xx.0/24(rw,sync,no_root_squash) | | | # 共享文件路径 允许共享网段 (共享文件可执行权限) 规则介绍: ro 只读访问 rw 读写访问 sync 所有数据在请求时写入共享 hide 在NFS共享目录中不共享其子目录 no_hide 共享NFS目录的子目录 all_squash 共享文件的UID和GID映射匿名用户anonymous,适合公用目录。 no_all_squash 保留共享文件的UID和GID(默认) root_squash root用户的所有请求映射成如anonymous用户一样的权限(默认) no_root_squas root用户具有根目录的完全管理访问权限
-
使能规则:exportfs -r
-
-
重启服务:systemctl restart rpcbind.service && systemctl restart nfs-utils.service
-
-
nfs client 使用流程
- 设置开机自启:echo “192.168.xx.xx:/data/nfs_share /nfs nfs4 defaults 0 0” >> /etc/fstab && mount -av
- 查看共享信息:showmount -e 192.168.xx.x (此处ip地址为搭建服务器主机地址)
-
iptables 开放 nfs 端口
-
**使用条件:**iptables 限制端口后,无法成功 mount nfs,需要开启 nfs 使用的端口
-
**原理:**默认情况下,各种NFS服务(lockd、statd、mountd等)将从portmapper (portmap)请求随机端口分配,这意味着大多数管理员需要在他们的防火墙规则库中开放一系列端口以使NFS工作,我们可以固定使用的端口,方便 iptables 开放限制
-
方式:
-
固定nfs 端口:vim /etc/sysconfig/nfs
MOUNTD_PORT="10050" STATD_PORT="10051" LOCKD_TCPPORT="10052" LOCKD_UDPPORT="10052" RQUOTAD_PORT="10053" STATD_OUTGOING_PORT="10054"
-
重启服务:systemctl restart rpcbind.service && systemctl restart nfs-utils.service
-
iptables 开放端口
# Portmap ports -A INPUT -m state --state NEW -p tcp --dport 111 -j ACCEPT -A INPUT -m state --state NEW -p udp --dport 111 -j ACCEPT # NFS daemon ports -A INPUT -m state --state NEW -p tcp --dport 2049 -j ACCEPT -A INPUT -m state --state NEW -p udp --dport 2049 -j ACCEPT # NFS mountd ports -A INPUT -m state --state NEW -p udp --dport 10050 -j ACCEPT -A INPUT -m state --state NEW -p tcp --dport 10050 -j ACCEPT # NFS status ports -A INPUT -m state --state NEW -p udp --dport 10051 -j ACCEPT -A INPUT -m state --state NEW -p tcp --dport 10051 -j ACCEPT # NFS lock manager ports -A INPUT -m state --state NEW -p udp --dport 10052 -j ACCEPT -A INPUT -m state --state NEW -p tcp --dport 10052 -j ACCEPT # NFS rquotad ports -A INPUT -m state --state NEW -p udp --dport 10053 -j ACCEPT -A INPUT -m state --state NEW -p tcp --dport 10053 -j ACCEPT
-
查看nfs 端口信息,此时client 已经可以使用nfs 功能
rpcinfo -p program vers proto port service 100000 4 tcp 111 portmapper 100000 3 tcp 111 portmapper 100000 2 tcp 111 portmapper 100000 4 udp 111 portmapper 100000 3 udp 111 portmapper 100000 2 udp 111 portmapper 100024 1 udp 35909 status 100024 1 tcp 35075 status 100005 1 udp 10050 mountd 100005 1 tcp 10050 mountd 100005 2 udp 10050 mountd 100005 2 tcp 10050 mountd 100005 3 udp 10050 mountd 100005 3 tcp 10050 mountd 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100227 3 tcp 2049 nfs_acl 100021 1 udp 39277 nlockmgr 100021 3 udp 39277 nlockmgr 100021 4 udp 39277 nlockmgr 100021 1 tcp 41267 nlockmgr 100021 3 tcp 41267 nlockmgr 100021 4 tcp 41267 nlockmgr
-
-
参考:[Firewalling a Linux NFS server with iptables – Prefetch Technologies](https://prefetch.net/blog/2010/11/02/firewalling-a-linux-nfs-server-with-iptables/#:~:text=Getting NFS working with iptables is a three,and iptables services to pick up the changes.)