目錄通過(guò)防火墻iptables做隔離端口的腳本獲取集群內(nèi)hosts的ip,空格分隔配置集群外的ip,空格分隔,格式如下配置需要隔離的端口,空格分隔,以22為例新建chain添加集群內(nèi)ip白名單添加集群外ip白名單最后隔離端口同時(shí)開啟firewall和iptables總結(jié)通過(guò)防火墻iptables做隔離端口的腳本vi iptables_fix.sh#!/bin/bash#備份舊的規(guī)則iptables-save > “/opt/firewall-“date '+%Y-%m-%d-%H:%M:%S'”.txt”獲取集群內(nèi)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添加集群內(nèi)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同時(shí)開啟firewall和iptables
使用向?qū)?/p>
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)服務(wù)的本質(zhì)區(qū)別是:
iptables服務(wù)將配置存儲(chǔ)在/etc/sysconfig/iptables和/etc/sysconfig/ip6tables中,而firewalld將配置存儲(chǔ)在/usr/lib/firewalld/和/etc/firewalld/中的各種XML文件中。
注意,/etc/sysconfig/iptables文件不存在,因?yàn)樵赗ed Hat Enterprise Linux上默認(rèn)安裝了firewalld。
在iptables服務(wù)中,每次更改都意味著刷新所有舊規(guī)則并從/etc/sysconfig/iptables讀取所有新規(guī)則,而在firewalld中不需要重新創(chuàng)建所有規(guī)則。
只應(yīng)用差異。因此,firewalld可以在運(yùn)行時(shí)更改設(shè)置,而不會(huì)丟失現(xiàn)有的連接。
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。