測試環境:CentOS 6.7
服務端
# yum -y install nfs-utils rpcbind
# 開啟服務
service nfs start
service rpcbind start
# 配置
nano /etc/exports
# 配置文件內容
/home/filesrv 10.1.8.*(rw,sync)
# 配置生效
exportfs -r
# 檢查
showmount -e
# 共享文件夾的權限
chmod 777 /home/filesrv
# 所用到的端口
rpcinfo -p
# 添加允許端口到iptables或關閉iptables
# 重要 此服務器不暴露在公網時或只能通過內網IP訪問時這樣做,否則不建議這樣做。
iptables -A INPUT -p tcp --dport 111 -j ACCEPT
iptables -A INPUT -p udp --dport 111 -j ACCEPT
........
客戶端
#
檢查服務端共享情況
showmount -e 10.1.8.25
# 掛載共享文件夾到本機
showmount -e 10.1.8.25
# 掛載共享文件夾到本機
mount -t nfs 10.1.8.25:/home/filesrv /home/fileapp
這樣就可以在本機操作/home/fileapp下的文件,讀寫均可。
其實就是一個映射,對此文件夾下的操作對應的就是操作共享文件夾,像是windows上的映射網絡驅動器一樣。