目錄通過防火墻iptables做隔離端口的腳本獲取集群內hosts的ip,空格分隔配置集群外的ip,空格分隔,格式如下配置需要隔離的端口,空格分隔,以22為例新建chain添加集群內ip白名單添加集群外ip白名單最后隔離端口同時開啟firewall和iptables總結通過防火墻iptables做隔離端口的腳本vi iptables_fix.sh#!/bin/bash#備份舊的規則iptables-save > “/opt/firewall-“date '+%Y-%m-%d-%H:%M:%S'”.txt”獲取集群內hosts的ip,空格分隔clusters=cat /etc/hosts | grep -v ::1 | grep -v '^$' | awk '{print $1}'配置集群外的ip,空格分隔,格式如下business=“127.0.0.1 172.17.0.1/16”配置需要隔離的端口,空格分隔,以22為例block_ports=“22”echo “FireWall fix…”新建chainiptables -t filter -N BIGDATA_BLOCK_PORTS添加集群內ip白名單for block_port in $block_ports;dofor chost in $clusters;do#echo $ahostiptables -I BIGDATA_BLOCK_PORTS -s $chost -p tcp --dport $block_port -j ACCEPTiptables -I BIGDATA_BLOCK_PORTS -s $chost -p udp --dport $block_port -j ACCEPTdonedone添加集群外ip白名單for block_port in $block_ports;dofor bhost in $business;do#echo $ahostiptables -I BIGDATA_BLOCK_PORTS -s $bhost -p tcp --dport $block_port -j ACCEPTiptables -I BIGDATA_BLOCK_PORTS -s $bhost -p udp --dport $block_port -j ACCEPTdonedone最后隔離端口for block_port in $block_ports;doiptables -A BIGDATA_BLOCK_PORTS -p tcp --dport $block_port -j DROPiptables -A BIGDATA_BLOCK_PORTS -p udp --dport $block_port -j DROPdone將BIGDATA_BLOCK_PORTS加入INPUT和FORWARDiptables -I INPUT -j BIGDATA_BLOCK_PORTSiptables -I FORWARD -j BIGDATA_BLOCK_PORTSecho 'fix finished同時開啟firewall和iptables
使用向導
With the iptables service, every single change means flushing all the old rules and reading all the new rules from /etc/sysconfig/iptables, while with firewalld there is no recreating of all the rules. Only the differences are applied. Consequently, firewalld can change the settings during runtime without existing connections being lost.
翻譯
firewalld與iptables(和ip6tables)服務的本質區別是:
iptables服務將配置存儲在/etc/sysconfig/iptables和/etc/sysconfig/ip6tables中,而firewalld將配置存儲在/usr/lib/firewalld/和/etc/firewalld/中的各種XML文件中。
注意,/etc/sysconfig/iptables文件不存在,因為在Red Hat Enterprise Linux上默認安裝了firewalld。
在iptables服務中,每次更改都意味著刷新所有舊規則并從/etc/sysconfig/iptables讀取所有新規則,而在firewalld中不需要重新創建所有規則。
只應用差異。因此,firewalld可以在運行時更改設置,而不會丟失現有的連接。
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。