需求介绍:
生产上想要利用NFS实现共享, 由于生产规则防火墙仅开放了22端口,此时我们需要开启NFS服务端口
但是NFS启动时会随机启动多个端口并向RPC注册. 为了设置安全组以及防火墙规则,此时就需要设置NFS固定端口。 NFS服务需要开启 mountd,nfs,nlockmgr,portmapper,rquotad这5个服务. 其中nfs、portmapper的端口是固定的. 另外三个服务的端口是随机分配的. 所以需要给mountd,nlockmgr,rquotad设置固定的端口。
1.给mountd、rquotad设置端口
编写/etc/sysconfig/nfs文件设置端口
vim /etc/sysconfig/nfs
RQUOTAD_PORT=30001
LOCKD_TCPPORT=30002
LOCKD_UDPPORT=30002
MOUNTD_PORT=30003
STATD_PORT=30004
2.重启rpc、nfs的配置与服务:
systemctl restart rpcbind.service systemctl restart nfs.service
3.在/etc/modprobe.d/lockd.conf中添加以下设置:
options lockd nlm_tcpport=30002
options lockd nlm_udpport=30002
4.重新加载NFS配置和服务:
systemctl restart nfs-config
systemctl restart nfs-idmap
systemctl restart nfs-lock
systemctl restart nfs-server
5:查看修改后的NFS端口使用情况:
[root@server1 ~]# 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 30004 status
100024 1 tcp 30004 status
100005 1 udp 30003 mountd
100005 1 tcp 30003 mountd
100005 2 udp 30003 mountd
100005 2 tcp 30003 mountd
100005 3 udp 30003 mountd
100005 3 tcp 30003 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 30002 nlockmgr
100021 3 udp 30002 nlockmgr
100021 4 udp 30002 nlockmgr
100021 1 tcp 30002 nlockmgr
100021 3 tcp 30002 nlockmgr
100021 4 tcp 30002 nlockmgr
## 这样端口就都固定了
6.编写防火墙规则(firewalld),开放NFS端口访问
查看firewalld防火墙规则:
[root@server1 ~]# firewall-cmd --permanent --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: ssh dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
添加规则:
[root@server1 ~]#firewall-cmd --permanent --add-port=2049/tcp
[root@server1 ~]#firewall-cmd --permanent --add-port=2049/udp
[root@server1 ~]#firewall-cmd --permanent --add-port=111/tcp
[root@server1 ~]#firewall-cmd --permanent --add-port=111/udp
[root@server1 ~]#firewall-cmd --permanent --add-port=30001/tcp
[root@server1 ~]#firewall-cmd --permanent --add-port=30001/udp
[root@server1 ~]#firewall-cmd --permanent --add-port=30002/tcp
[root@server1 ~]#firewall-cmd --permanent --add-port=30002/udp
[root@server1 ~]#firewall-cmd --permanent --add-port=30003/udp
[root@server1 ~]#firewall-cmd --permanent --add-port=30003/tcp
[root@server1 ~]#firewall-cmd --permanent --add-port=30004/tcp
[root@server1 ~]#firewall-cmd --permanent --add-port=30004/udp
[root@server1 ~]#firewall-cmd --reload
#再次查看:
[root@server1 ~]# firewall-cmd --permanent --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: ssh dhcpv6-client
ports: 2049/tcp 2049/udp 111/tcp 111/udp 30001/tcp 30001/udp 30002/tcp 30002/udp 30003/udp 30003/tcp 30004/tcp 30004/udp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
## 端口已成功加入
此时NFS可以正常挂载使用。
Pingback引用通告: buy priligy singapore
Pingback引用通告: kamagra żel
Pingback引用通告: generic tadalafil 20mg for sale