久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

linux如何通過防火墻iptables做隔離端口的腳本

瀏覽:5日期:2023-10-01 20:59:26
目錄通過防火墻iptables做隔離端口的腳本獲取集群內(nèi)hosts的ip,空格分隔配置集群外的ip,空格分隔,格式如下配置需要隔離的端口,空格分隔,以22為例新建chain添加集群內(nèi)ip白名單添加集群外ip白名單最后隔離端口同時開啟firewall和iptables總結(jié)通過防火墻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同時開啟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ù)將配置存儲在/etc/sysconfig/iptables和/etc/sysconfig/ip6tables中,而firewalld將配置存儲在/usr/lib/firewalld/和/etc/firewalld/中的各種XML文件中。

注意,/etc/sysconfig/iptables文件不存在,因為在Red Hat Enterprise Linux上默認安裝了firewalld。

在iptables服務(wù)中,每次更改都意味著刷新所有舊規(guī)則并從/etc/sysconfig/iptables讀取所有新規(guī)則,而在firewalld中不需要重新創(chuàng)建所有規(guī)則。

只應(yīng)用差異。因此,firewalld可以在運行時更改設(shè)置,而不會丟失現(xiàn)有的連接。

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Linux
相關(guān)文章:
主站蜘蛛池模板: 棋牌| 阜新市| 灵寿县| 昌江| 通河县| 宁明县| 阜宁县| 襄樊市| 广昌县| 晋中市| 健康| 湖北省| 仁布县| 自治县| 南川市| 台州市| 班戈县| 福州市| 都昌县| 安福县| 遂溪县| 收藏| 南和县| 锦屏县| 合阳县| 谷城县| 子长县| 军事| 息烽县| 资源县| 天水市| 尉氏县| 孝义市| 含山县| 漠河县| 通城县| 浦城县| 西林县| 宁远县| 宁波市| 米林县|