改Linux系統防火牆配置需要修改 /etc/sysconfig/iptables 這個文件
vim /etc/sysconfig/iptables
在vim編輯器,會看到下面的內容
# 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 -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
需要開放端口,請在裏面添加一條一下內容即可:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1521 -j ACCEPT
其中 1521 是要開放的端口號,然後重新啟動linux的防火牆服務。
Linux下停止/啟動防火牆服務的命令(root用户使用):
service iptables stop --停止
service iptables start --啟動
寫在最後:
#永久性生效,重啟後不會復原
chkconfig iptables on #開啟
chkconfig iptables off #關閉
#即時生效,重啟後復原
service iptables start #開啟
service iptables stop #關閉