[CentOS]CentOS7-防火墻開放端口

第一步:先檢查是否安裝了iptables

[root@localhost ~]# service iptables status

結(jié)果一:需要安裝iptable iptable-service (執(zhí)行1.1、1.2、1.3命令)

image.png

結(jié)果二:不需要安裝iptable iptable-service
image.png

1.1 安裝iptable

[root@localhost ~]# yum install -y iptables

1.2 升級iptables

[root@localhost ~]# yum update -y iptables

1.3 安裝iptable-service

[root@localhost ~]# yum install -y iptables-services

第二步: 停止/禁用 自帶的firewalld服務(wù)

2.1 停止firewalld服務(wù)

[root@localhost ~]# systemctl stop firewalld

2.2 禁用firewalld服務(wù)

[root@localhost ~]# systemctl mask firewalld

第三步: 設(shè)置現(xiàn)有規(guī)則

3.1 查看iptables現(xiàn)有規(guī)則

[root@localhost ~]# iptables -L -n

3.2 先允許所有(不然有可能會杯具)

[root@localhost ~]# iptables -P INPUT ACCEPT

3.3 清空所有默認(rèn)規(guī)則

[root@localhost ~]# iptables -F

3.3 清空所有自定義規(guī)則

[root@localhost ~]# iptables -X

3.4 所有計(jì)數(shù)器歸0

[root@localhost ~]# iptables -Z

3.5 允許來自于lo接口的數(shù)據(jù)包(本地訪問)

[root@localhost ~]# iptables -A INPUT -i lo -j ACCEPT

3.6 開放22端口

[root@localhost ~]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT

3.7 允許ping,開放8端口

[root@localhost ~]# iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT

第四步: 按照實(shí)際要求,添加規(guī)則

4.1 允許接受本機(jī)請求之后的返回?cái)?shù)據(jù) RELATED,是為FTP設(shè)置的

[root@localhost ~]# iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

4.2 其他入站一律丟棄

[root@localhost ~]# iptables -P INPUT DROP

4.3 所有出站一律綠燈

[root@localhost ~]# iptables -P OUTPUT ACCEPT

4.4 所有轉(zhuǎn)發(fā)一律丟棄

[root@localhost ~]# iptables -P FORWARD DROP

第五步:其他規(guī)則設(shè)定

5.1 如果要添加內(nèi)網(wǎng)ip信任(接受其所有TCP請求)

[root@localhost ~]# iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT

5.2 過濾所有非以上規(guī)則的請求

[root@localhost ~]# iptables -P INPUT DROP

5.3 要封停一個IP,使用下面這條命令:

[root@localhost ~]# iptables -I INPUT -s ***.***.***.*** -j DROP

5.4 要解封一個IP,使用下面這條命令:

[root@localhost ~]# iptables -D INPUT -s ***.***.***.*** -j DROP

第六步 保存規(guī)則設(shè)定

[root@localhost ~]# service iptables save

第七步 開啟iptables服務(wù)

7.1 注冊iptables服務(wù)

相當(dāng)于以前的chkconfig iptables on

[root@localhost ~]# systemctl enable iptables.service

7.2 開啟服務(wù)

[root@localhost ~]# systemctl start iptables.service

7.3 查看狀態(tài)

[root@localhost ~]# systemctl status iptables.service

查看

[root@localhost ~]# vim /etc/sysconfig/iptables

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 每年過年,都是媽媽在主導(dǎo),臘月二十打掃衛(wèi)生,家里的房子,院子預(yù)計(jì)需要打掃一天,忙完所有人都是灰頭土臉;臘月...
    火色石榴花閱讀 609評論 0 2
  • 人格的劃分 一般說來,人是什么相比對他的評價是什么更影響他的幸福。因?yàn)閭€性隨時隨地伴隨著人,并且影響他所有的經(jīng)驗(yàn),...
    a紅霞Li閱讀 296評論 0 0

友情鏈接更多精彩內(nèi)容