萬盛學電腦網

 萬盛學電腦網 >> 安全資訊防護 >> 設置CentOS防火牆開放端口

設置CentOS防火牆開放端口

在我們使用CentOS系統的時候,CentOS防火牆有時是需要改變設置的。CentOS防火牆默認是打開的,,設置CentOS防火牆開放端口方法如下: .


打開iptables的配置文件:vi /etc/sysconfig/iptables .


修改CentOS防火牆時注意:一定要給自己留好後路,留VNC一個管理端口和SSh的管理端口

.


下面是一個iptables的示例:
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp –icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 25 -j ACCEPT .
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited
COMMIT .


修改CentOS防火牆需要注意的是,你必須根據自己服務器的情況來修改這個文件。

.


舉例來說,如果你不希望開放80端口提供web服務,那麼應該相應的刪除這一行:
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT .


全部修改完之後重啟iptables:service iptables restart

.


你可以驗證一下是否規則都已經生效:iptables -L .


這樣,我們就完成了CentOS防火牆的設置修改。 .

.

copyright © 萬盛學電腦網 all rights reserved