一、安装nfs服务
yum install nfs-utils rpcbind -y
systemctl start rpcbind
systemctl enable rpcbind
systemctl start nfs
systemctl enable nfs
二、只允许指定ip访问
vim /etc/exports
/mnt 192.168.0.191(rw,no_root_squash,sync,insecure)
内网穿透的只能是localhost
三、设置防火墙
vim /etc/firewalld/services/nfs.xml
<service>
<short>nfs</short>
<description>nfs</description>
<port protocol="tcp" port="111"/>
<port protocol="udp" port="111"/>
<port protocol="tcp" port="662"/>
<port protocol="udp" port="662"/>
<port protocol="tcp" port="892"/>
<port protocol="udp" port="892"/>
<port protocol="tcp" port="2049"/>
<port protocol="udp" port="2049"/>
<port protocol="udp" port="32769"/>
<port protocol="tcp" port="32803"/>
</service>
firewall-cmd --add-service=nfs --zone=public --permanent
firewall-cmd --reload
共计放开111、662、892、2049(tcp、udp)
32769(udp)、32803(tcp)
原因:
由于nfs服务需要开启 mountd,nfs,nlockmgr,portmapper,rquotad这5个服务,将这5个服务的端口加到iptables里面而nfs 和 portmapper两个服务是固定端口的,nfs为2049,portmapper为111。其他的3个服务是用的随机端口。
rpcinfo -p 查看端口
四、固定随机接口
1、vim /etc/sysconfig/nfs
放开或添加如下代码:
RQUOTAD_PORT=30001
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
STATD_PORT=662
2、vim /etc/modprobe.d/lockd.conf
修改如下:
3、重启服务
systemctl restart rpcbind.service
systemctl restart nfs.service
systemctl restart nfs-config
systemctl restart nfs-idmap
systemctl restart nfs-lock
systemctl restart nfs-server
4、验证rpcinfo -p
五、ngrok内网穿透后的防护
1、限制nfsip地址为本地地址
vim /etc/exports
内容设置为
/nfs 127.0.0.1(rw,no_root_squash,sync,insecure)
重启nfs
[root@localhost /]# systemctl restart nfs-server
[root@localhost /]# systemctl restart rpcbind
2、增加云服务器安全组防护
来源只允许家里的IP(不知道家里ip,可以百度“ip地址”,即可显示)
最好IP段进行配置,如:111.197.0.0/16 ,因为ip也可能会变
3、验证挂载
用家里服务器和其他ip云服务器尝试分别尝试挂载
mkdir nfs_test
mount -t nfs sumengnan.com:/nfs /nfs_test/
常用目录
/etc/exports NFS服务的主要配置文件
/usr/sbin/exportfs NFS服务的管理命令
/usr/sbin/showmount 客户端的查看命令
/var/lib/nfs/etab 记录NFS分享出来的目录的完整权限设定值
/var/lib/nfs/xtab 记录曾经登录过的客户端信息