运行环境:RHEL 6.5
防火墙的配置是在/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
可以看出,默认情况下,安装完系统后只开启了22端口。
如果要开启其它端口,比如80和8080端口,要增加如下两行:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
如果要开放一个范围的端口,比如3000到5000,要增加如下一行:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3000:5000 -j ACCEPT
修改完后,要重启iptables:service iptables restart。
1. 开启/关闭防火墙
(1)机器重启后生效
开启: chkconfig iptables on
关闭: chkconfig iptables off
(2)即时生效,重启后失效
开启: service iptables start
关闭: service iptables stop
2. 检查端口状态
(1)netstat -anp | grep [port]
(2)lsof -i:[port]
(3)telnet [ip] [port]
3. 查看防火墙策略:# iptables -L -n
(1)有策略的情况
Chain INPUT (policy ACCEPT)
target prot opt source destination
tcp -- 0.0.0.0/0 210.51.190.37 tcp dpt:9022 state NEW recent: SET name: sshuser side: source
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:4848
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:8080
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:9009
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2049
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpts:4002:4004
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpts:4002:4004
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:111
ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 state NEW udp dpt:111
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:9022
LOG all -- 0.0.0.0/0 0.0.0.0/0 recent: UPDATE seconds: 60 hit_count: 9 name: sshuser side: source LOG flags 0 level 4 prefix `SSH attack: '
DROP all -- 0.0.0.0/0 0.0.0.0/0 recent: UPDATE seconds: 60 hit_count: 9 name: sshuser side: source
(2)没有策略的情况
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
4. 清除所有策略:# iptables -F
清除预设表filter中的所有规则链的规则。
5. 清除自定义策略:# iptables -X
清除预设表filter中使用者自定链中的规则。
参考文献:
1. http://bluearea65.blog.51cto.com/759549/1127204
2. http://blog.csdn.net/kobe_lzq/article/details/7977013
3. http://tech.ccidnet.com/art/9513/20070601/1098119_1.html
4. http://wenku.baidu.com/link?url=Awsaef-YLde9Uut-FWJVpk7g1SU0JIII-D736JLQsJYENMIg4lZMLGX6crlNCizAuOPn4g0hcSKFxTCduwFPuNr5w3Wf1z2mHtF4LQZ2j3S
5. http://www.doc88.com/p-780491073573.html
6. http://blog.coocla.org/207.html
没有评论:
发表评论