Iptables 和 NFS 配置指南
OS: RHEL 6.0 (Santiago)
FireWall: iptables v1.4.7
NFS: nfs-utils-1.2.2-7.el6.i686
1. 启动NFS服务:service nfs start (假设已安装nfs-utils 和 portmap且iptables已停止)
[root@rhel6-git nfs]# service nfs start
Starting NFS services: [ OK ]
Starting NFS quotas: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
2. 设置NFS服务端口:vi /etc/sysconfig/nfs
将以下两行中注释符“#”删除,并将端口号修改成你的数值(须小于1024)
RQUOTAD_PORT=875
MOUNTD_PORT=876
3. 设置共享目录和权限:vi /etc/exports
/home/nfs 192.168.254.0/24(rw,no_root_squash)
4.重启NFS服务:service nfs restart或 exportfs -r
5.检查NFS服务网络连接端口:rpcinfo –p
[root@rhel6-git nfs]# rpcinfo -p
program vers proto port service
100000 4 tcp 111 portmapper
100000 2 udp 111 portmapper
100011 1 udp 875 rquotad
100011 2 tcp 875 rquotad
100003 2 tcp 2049 nfs
100227 2 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 47549 nlockmgr
100021 1 tcp 51246 nlockmgr
100005 1 udp 876 mountd
100005 1 tcp 876 mountd
6.在客户机上挂载NFS共享目录:
mount –t nfs nfs-server-ip:/home/nfs /home/nfs
or mount.nfs nfs-server-ip:/home/nfs /home/nfs
7.在客户机上检查NFS服务器信息: showmount nfs-server-ip(你的nfs服务器ip地址)
若iptables已启动
1.查看防火墙当前状态:service iptables status
Or iptables –L Or iptables –S (rhel6有该参数)
2. 查看(编辑vi)防火墙缺省配置:cat /etc/sysconfig/iptables
[root@rhel6-git nfs]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
配置文件说明:
*filter ——默认过滤表为filter , 包含了内建的链INPUT(处理进入的包)、FORWORD(处理通过的包)和OUTPUT(处理本地生成的包)。(其他表为nat,mangle)
:INPUT ACCEPT [0:0] ——如果没有规则匹配,则所有进入的包都将接收
:FORWARD ACCEPT [0:0] ——如果没有规则匹配,则所有包都将转发
:OUTPUT ACCEPT [0:0] ——如果没有规则匹配,则所有从本地生产的包都将发出
-A INPUT -i lo -j ACCEPT ——接收所有进入到接口lo的数据包
-A INPUT -p icmp -j ACCEPT ——接收所有进入的icmp数据包(允许ping本机)
-A INPUT -j REJECT --reject-with icmp-host-prohibited ——拒绝所有进入的包,并返回提示信息
3. 查看防火墙缺省规则:iptables –L or iptables –S
[root@rhel6-git nfs]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
4. 通过防火墙实现服务器对外只开放nfs服务(假设已对nfs服务绑定端口)
4.1 启动防火墙: service iptables start
4.2 设置开机启动iptables: chkconfig --level 345 iptables on
4.3 清除iptables所有配置:iptables –F
4.4 设置INPUT缺省策略:iptables –P INPUT DROP
4.5 允许网络192.168.254.0/24访问nfs服务——添加如下规则:
iptables -A INPUT -p tcp -s 192.168.254.0/24 --dport 111 -j ACCEPT
iptables -A INPUT -p tcp -s 192.168.254.0/24 --dport 875 -j ACCEPT
iptables -A INPUT -p tcp -s 192.168.254.0/24 --dport 2049 -j ACCEPT
iptables -A INPUT -p tcp -s 192.168.254.0/24 --dport 876 -j ACCEPT
iptables -A INPUT -p udp -s 192.168.254.0/24 --dport 2049 -j ACCEPT
iptables -A INPUT -p udp -s 192.168.254.0/24 --dport 875 -j ACCEPT
iptables -A INPUT -p udp -s 192.168.254.0/24 --dport 111 -j ACCEPT
iptables -A INPUT -p udp -s 192.168.254.0/24 --dport 876 -j ACCEPT
显示结果如下:
[root@rhel6-git nfs]# iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- 192.168.254.0/24 anywhere tcp dpt:sunrpc
ACCEPT tcp -- 192.168.254.0/24 anywhere tcp dpt:rquotad
ACCEPT tcp -- 192.168.254.0/24 anywhere tcp dpt:nfs
ACCEPT tcp -- 192.168.254.0/24 anywhere tcp dpt:876
ACCEPT udp -- 192.168.254.0/24 anywhere udp dpt:nfs
ACCEPT udp -- 192.168.254.0/24 anywhere udp dpt:rquotad
ACCEPT udp -- 192.168.254.0/24 anywhere udp dpt:876
ACCEPT udp -- 192.168.254.0/24 anywhere udp dpt:sunrpc
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
4.6. 以上规则中875和876端口是通过修改配置文件/etc/sysconfig/nfs指定的(缺省mountd和rquotad是使用随机生成的小于1024的端口号)
4.7. 以上规则重启iptables后将失效,若需永久有效须修改文件/etc/sysconfig/iptables内容如下:
Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -s 192.168.254.0/24 -p tcp -m tcp --dport 111 -j ACCEPT
-A INPUT -s 192.168.254.0/24 -p tcp -m tcp --dport 875 -j ACCEPT
-A INPUT -s 192.168.254.0/24 -p tcp -m tcp --dport 2049 -j ACCEPT
-A INPUT -s 192.168.254.0/24 -p tcp -m tcp --dport 876 -j ACCEPT
-A INPUT -s 192.168.254.0/24 -p udp -m udp --dport 2049 -j ACCEPT
-A INPUT -s 192.168.254.0/24 -p udp -m udp --dport 875 -j ACCEPT
-A INPUT -s 192.168.254.0/24 -p udp -m udp --dport 876 -j ACCEPT
-A INPUT -s 192.168.254.0/24 -p udp -m udp --dport 111 -j ACCEPT
COMMIT
其他:ArchLinux 安装telnet服务
1. 升级包数据库: pacman –Syu
2. 强制安装包: pacman –Sf inetutils xinetd
3. 修改文件/etc/xinetd.d/telnet中数值为disable = no
4. 启动服务: /etc/rc.d/xinetd restart
5. 确认telnet网络端口已启动: netstat –lp |grep telnet
6. 退出telnet的方法: ctrl + ] 并输入 q
转载于:https://blog.51cto.com/zhongq/710477