CentOS 7防火牆開放埠的快速方法

2022-06-21 09:00:13 字數 2531 閱讀 1326

章主要為大家詳細介紹了centos 7防火牆開放埠的快速方法,感興趣的小夥伴們可以參考一下!

一、centos 7快速開放埠:

centos公升級到7之後,發現無法使用iptables控制linuxs的埠,baidu之後發現centos 7使用firewalld代替了原來的iptables。下面記錄如何使用firewalld開放linux埠:

開啟埠

[root@centos7 ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent

查詢埠號80 是否開啟:

[root@centos7 ~]# firewall-cmd --query-port=80/tcp

重啟防火牆:

[root@centos7 ~]# firewall-cmd --reload

查詢有哪些埠是開啟的:

[root@centos7 ~]# firewall-cmd --list-port

命令含義:

--zone #作用域

--add-port=80/tcp #新增埠,格式為:埠/通訊協議

--permanent #永久生效,沒有此引數重啟後失效

關閉firewall:

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall開機啟動

二、centos6防火牆開放埠:

在我們使用centos系統的時候,centos防火牆有時是需要改變設定的。centos防火牆預設是開啟的,設定centos防火牆開放埠方法如下:

開啟iptables的配置檔案:vi /etc/sysconfig/iptables

修改centos防火牆時注意:一定要給自己留好後路,留vnc乙個管理埠和ssh的管理埠

下面是乙個iptables的示例:

# firewall configuration written by system-config-securitylevel

# manual customization of this file is not recommended.

*filter

:input accept [0:0]

:forward accept [0:0]

:output accept [0:0]

:rh-firewall-1-input - [0:0]

-a input -j rh-firewall-1-input

-a forward -j rh-firewall-1-input

-a rh-firewall-1-input -i lo -j accept

-a rh-firewall-1-input -p icmp –icmp-type any -j accept

-a rh-firewall-1-input -p 50 -j accept

-a rh-firewall-1-input -p 51 -j accept

-a rh-firewall-1-input -m state –state established,related -j accept

-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 53 -j accept

-a rh-firewall-1-input -m state –state new -m udp -p udp –dport 53 -j accept

-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 22 -j accept

-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 25 -j accept

-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 80 -j accept

-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 443 -j accept

-a rh-firewall-1-input -j reject –reject-with icmp-host-prohibited

commit

修改centos防火牆需要注意的是,你必須根據自己伺服器的情況來修改這個檔案。

舉例來說,如果你不希望開放80埠提供web服務,那麼應該相應的刪除這一行:

-a rh-firewall-1-input -m state –state new -m tcp -p tcp –dport 80 -j accept

全部修改完之後重啟iptables:service iptables restart

你可以驗證一下是否規則都已經生效:iptables -l

這樣,我們就完成了centos防火牆的設定修改。

更多centos相關資訊見centos 專題頁面 https://w

CentOS 7 開放防火牆埠

centos 7 開放防火牆埠 命令 最近公司新的server要求用centos7,發現以前centos 6 系列中的 iptables 相關命令不能用了,查了下,發現centos 7使用firewalld代替了原來的iptables。使用方法如下 關閉防火牆 systemctl stop fire...

CentOS 7防火牆開放埠

centos公升級到7之後,發現無法使用iptables控制linuxs的埠,baidu之後發現centos 7使用firewalld代替了原來的iptables。下面記錄如何使用firewalld開放linux埠 開啟埠 root centos7 firewall cmd zone public ...

Centos7 防火牆開放埠

一 原來的iptables不用了 輸入 service iptables restart 爆出這個錯誤 redirecting to bin systemctl restart iptables.service 說白了,就是centos的防火牆改為了改為firewalld,用原來的iptables不...