国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

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

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

瀏覽:3日期: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)。

標簽: Linux
相關(guān)文章:
主站蜘蛛池模板: 普定县| 红河县| 张家口市| 齐齐哈尔市| 甘洛县| 石泉县| 崇信县| 原阳县| 浮梁县| 中西区| 乌恰县| 长海县| 甘洛县| 曲松县| 清原| 南汇区| 津市市| 亚东县| 梧州市| 神农架林区| 资溪县| 宁晋县| 新晃| 远安县| 海盐县| 且末县| 彭山县| 奈曼旗| 梓潼县| 邯郸县| 德阳市| 丹凤县| 阳江市| 合水县| 宣化县| 河曲县| 洛南县| 共和县| 东安县| 乌兰浩特市| 柳州市|