nfs服务所需要的的iptables设置

来源:互联网 发布:js cookie存储时间 编辑:程序博客网 时间:2024/05/19 19:40


portmapp在NFS服务启动的时候给每一个NFS服务分配了一个动态的端口,如这些服务MOUNTD_PORT、 STATD_PORT、 LOCKD_TCPPORT、 LOCKD_UDPPORT。
如何才能让NFS client在使用 iptables时可以正常使用NFS服务呢?办法就是指定将上述服务的运行端口,然后在iptables中发布。相关的配置文件为 /etc/sysconfig/nfs 。
要使用iptables来控制NFS,需静态指定端口号让portmap调用。NFS服务启用时会检查/etc/sysconfig/nfs文件。在此文件下来指定mountd,statd,lockd,rquotad端口号。
RQUOTAD_PORT=10001
LOCKD_TCPPORT=10002
LOCKD_UDPPORT=10002
MOUNTD_PORT=10003
STATD_PORT=10004
/etc/sysconfig/nfs默认安装的时候可能会不存在,5.1以上版本除外。可以手工创建此文件编写以上内容。
设定后需重启服务
service nfslock restart
service nfs restart
使用命令查看端口
#rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 10004 status
100024 1 tcp 10004 status
100011 1 udp 10001 rquotad
100011 2 udp 10001 rquotad
100011 1 tcp 10001 rquotad
100011 2 tcp 10001 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100021 1 udp 10002 nlockmgr
100021 3 udp 10002 nlockmgr
100021 4 udp 10002 nlockmgr
100021 1 tcp 10002 nlockmgr
100021 3 tcp 10002 nlockmgr
100021 4 tcp 10002 nlockmgr
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100005 1 udp 10003 mountd
100005 1 tcp 10003 mountd
100005 2 udp 10003 mountd
100005 2 tcp 10003 mountd
100005 3 udp 10003 mountd
100005 3 tcp 10003 mountd
接下来就是配置iptables规则了
iptables -A INPUT -p tcp --dport 111 -j ACCEPT
iptables -A INPUT -p udp --dport 111 -j ACCEPT
iptables -A INPUT -p tcp --dport 2049 -j ACCEPT
iptables -A INPUT -p udp --dport 2049 -j ACCEPT
iptables -A INPUT -p tcp --dport 10001:10004 -j ACCEPT
iptables -A INPUT -p udp --dport 10001:10004 -j ACCEPT


mount -t nfs -o nolock 172.16.10.254:/opt /mnt

0 0