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防火牆的設定修改。
轉自:http://os.51cto.com/art/201003/192211.htm