ubuntu 使用nfs服务报错:mount.nfs:access denied by server while mounting

本文提供了一个详细的步骤来解决Ubuntu 8.04上NFS服务的配置问题,并解决了客户端挂载时遇到的权限拒绝错误。文章包括安装NFS组件、配置防火墙、设置端口映射等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我使用的版本是ubuntu8.04nfs

安装很简单:shell>sudo apt-get install nfs-common nfs-kernel-server portmap

 

shell>vi /etc/defualt/portmap

 

注释掉: -i 127.0.0.1 这一行

 

配置共享:shell>vi /etc/exports

添加:/home/work 192.168.1.*(rw,sync)

 

启动:shell>/etc/init.d/portmap start

         shell>/etc/init.d/nfs-kernel-server start

客户端测试:

shell>mount -t nfs  服务端_ip:/home/work  /mnt

 

出现mount.nfs:access denied by server while mounting

 

1.关掉防火墙 shell>/etc/init.d/iptables stop


2. 是我自己的经验 有的文章说可以在 exports 文件中用 * 代替ip ,可我最终配置具体的ip才可以共享,不能用*代替

 

注:如果因为安全必须开启防火墙,那必须将nfs所有需要的端口都开发

曾经操作时做的

 

在设置了防火墙的环境中使用NFS,需要在防火墙上打开如下端口:

1. portmap 端口 111 udp/tcp


2. nfsd
端口 2049 udp/tcp


3. mountd
端口 "xxx" udp/tcp
系统 RPC服务在 nfs服务启动时默认会为 mountd动态选取一个随机端口(32768--65535)来进行通讯,我们可以通过编辑/etc/services 文件为 mountd指定一个固定端口:

 

4. 修改/etc/service,添加以下内容(端口号必须在1024以下,且未被占用)
# Local services
mountd 1011/tcp #rpc.mountd
mountd 1011/udp #rpc.mountd
rquotad 1012/tcp #rpc.rquotad
rquotad 1012/udp #rpc.rquotad

 

5. 重起nfs服务
service nfs restart
chkconfig nfs on

 

6. 此时rpc相关端口已经被固定,可以添加防火墙规则
#portmap
/sbin/iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 111 -j ACCEPT
/sbin/iptables -A INPUT -s 192.168.1.0/24 -p udp --dport 111 -j ACCEPT
#nfsd
/sbin/iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 2049 -j ACCEPT
/sbin/iptables -A INPUT -s 192.168.1.0/24 -p udp --dport 2049 -j ACCEPT
#mountd
/sbin/iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 1011 -j ACCEPT
/sbin/iptables -A INPUT -s 192.168.1.0/24 -p udp --dport 1011 -j ACCEPT
#rquotad
/sbin/iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 1012 -j ACCEPT
/sbin/iptables -A INPUT -s 192.168.1.0/24 -p udp --dport 1012 -j ACCEPT
#rpc.statd
/sbin/iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 32768 -j ACCEPT
/sbin/iptables -A INPUT -s 192.168.1.0/24 -p udp --dport 32768 -j ACCEPT

 

 

或者

 

       /sbin/iptables -A INPUT -i eth1 -p TCP --dport 111 -j ACCEPT

       /sbin/iptables -A INPUT -i eth1 -p UDP --dport 111 -j ACCEPT

       /sbin/iptables -A INPUT -i eth1 -p TCP --dport 2049 -j ACCEPT

       /sbin/iptables -A INPUT -i eth1 -p UDP --dport 2049 -j ACCEPT

       /sbin/iptables -A INPUT -i eth1 -p TCP --dport 1011 -j ACCEPT

       /sbin/iptables -A INPUT -i eth1 -p UDP --dport 1011 -j ACCEPT

       /sbin/iptables -A INPUT -i eth1 -p TCP --dport 1012 -j ACCEPT

       /sbin/iptables -A INPUT -i eth1 -p UDP --dport 1012 -j ACCEPT

7.重启防火墙

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值