Centos6/7 防火牆配置說明

Centos6防火牆配置

vi /etc/sysconfig/iptables

# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-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
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

說明

#CentOS6
#開放端口運行外部訪問(不指定源IP)
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --dport 22 -j ACCEPT
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

#定向開放本地端口允許訪問
iptables -I INPUT -s 10.86.87.0/24 -p tcp --dport 10050 -j ACCEPT

#然後保存:
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables status

#防火牆啓停
/etc/init.d/iptables start
/etc/init.d/iptables stop

禁止linux向外建立新連接(INPUT 向內)
1、iptables -I OUTPUT -m state --state NEW -j DROP

#拒絕IP所有請求
iptables -I INPUT -s 10.86.87.123 -j DROP
service iptables save
iptables -L

Centos7防火牆配置

# 查詢端口是否開放
firewall-cmd --query-port=8080/tcp
# 開放80端口
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=8080-8085/tcp
# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp
查看防火牆的開放的端口
firewall-cmd --permanent --list-ports

#重啓防火牆(修改配置後要重啓防火牆)
firewall-cmd --reload


# 參數解釋
1、firwall-cmd:是Linux提供的操作firewall的一個工具;
2、--permanent:表示設置爲持久;
3、--add-port:標識添加的端口;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章