linux系统

linux iptables允许NFS Client访问NFS Server[技术]

portmapper在NFS服务启动的时候给每一个NFS服务分配了一个动态的端口,如何才能让NFS client在使用RHEL/Fedora/CentOS linux iptales防火墙时可以正常使用NFS服务呢?

需要打开下面的端口

a] TCP/UDP 111 – RPC 4.0 portmapper

b] TCP/UDP 2049 – NFSD (nfs server)

c] Portmap 静态端口—在/etc/sysconfig/nfs文件中定义的一系列TCP/UDP端口

按nfs默认启动的话,很多服务如rpc.mounted,端口都不是固定的,这样不方便在防火墙上进行管理,所以我们需要把每个启动的服务的端口固定下来,需要做的就是编辑/etc/sysconfig/nfs文件。

# vi /etc/sysconfig/nfs

更改下面的配置,将端口分配为一个没被占用的

# TCP port rpc.lockd should listen on.
LOCKD_TCPPORT=lockd-port-number
# UDP port rpc.lockd should listen on.
LOCKD_UDPPORT=lockd-port-number
# Port rpc.mountd should listen on.
MOUNTD_PORT=mountd-port-number
# Port rquotad should listen on.
RQUOTAD_PORT=rquotad-port-number
# Port rpc.statd should listen on.
STATD_PORT=statd-port-number
# Outgoing port statd should used. The default is port is random
STATD_OUTGOING_PORT=statd-outgoing-port-numbe

下面是我用于测试的机器上修改的内容

RQUOTAD_PORT=6005
LOCKD_TCPPORT=6004
LOCKD_UDPPORT=6004
MOUNTD_PORT=6002
STATD_PORT=6003
STATD_OUTGOING_PORT=6006

保存退出后就可以重启nfs服务,portmap服务

# service portmap restart
# service nfs restart

下面就是iptables方面的配置了,蚊子这里因为是学习,所以设置的比较严格,下面先说下我的环境

1,两台Server:192.168.211.128(nfs-server),192.168.211.129(nfs-client)
2,nfs-server上只允许nfs,ssh的访问,其余都拒绝

下面是我的iptables的配置

iptables -A INPUT -p tcp -s 192.168.211.0/24 –dport 22 -m state –state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 6002 -j ACCEPT
iptables -A INPUT -p tcp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 6003 -j ACCEPT
iptables -A INPUT -p tcp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 6004 -j ACCEPT
iptables -A INPUT -p tcp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 6005 -j ACCEPT
iptables -A INPUT -p tcp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 6006 -j ACCEPT
iptables -A INPUT -p udp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 6002 -j ACCEPT
iptables -A INPUT -p udp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 6003 -j ACCEPT
iptables -A INPUT -p udp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 6004 -j ACCEPT
iptables -A INPUT -p udp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 6005 -j ACCEPT
iptables -A INPUT -p udp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 6006 -j ACCEPT
iptables -A INPUT -p tcp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 111 -j ACCEPT
iptables -A INPUT -p udp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 111 -j ACCEPT
iptables -A INPUT -p tcp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 2049 -j ACCEPT
iptables -A INPUT -p udp -m state –state NEW,ESTABLISHED,RELATED -s 192.168.211.0/24 –dport 2049 -j ACCEPT
iptables -P INPUT DROP

第一条就是允许连接ssh
第二条作用是在启动nfs的时候,nfs-server会通过本地回环接口与portmap进行会话,所以需要允许
最后一条是设置input链的默认策略为drop
中间的就是允许nfs-server相应的端口了

如果在配置iptables的时候有问题可以使用service iptables restart重置,如果没有问题就可以使用service iptables save保存相应的配置,保存的配置文件放在/etc/sysconfig/iptables里。

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *