Linux 如何開放埠號

2021-09-26 03:51:15 字數 1810 閱讀 1281

sudo vim /etc/sysconfig/iptables
iptables配置檔案裡面的內容為:

# sample configuration for iptables service

# you can edit this manually or use system-config-firewall

# please do not ask us to add additional ports/services to this default configuration

*filter

:input accept [0:0]

:forward accept [0:0]

:output accept [0:0]

-a input -m state --state related,established -j accept

-a input -p icmp -j accept

-a input -i lo -j accept

-a input -p tcp -m state --state new -m tcp --dport 22 -j accept

-a input -j reject --reject-with icmp-host-prohibited

-a forward -j reject --reject-with icmp-host-prohibited

commit

將下面內容加入到配置檔案中

-a input -p tcp -m state --state new -m tcp --dport 埠號 -j accept
比如將伺服器的5005埠號開放,則加入的內容為:

-a input -p tcp -m state --state new -m tcp --dport 5005 -j accept
增加配置後的iptables配置檔案內容為:

# sample configuration for iptables service

# you can edit this manually or use system-config-firewall

# please do not ask us to add additional ports/services to this default configuration

*filter

:input accept [0:0]

:forward accept [0:0]

:output accept [0:0]

-a input -m state --state related,established -j accept

-a input -p icmp -j accept

-a input -i lo -j accept

-a input -p tcp -m state --state new -m tcp --dport 22 -j accept

-a input -p tcp -m state --state new -m tcp --dport 5005 -j accept

-a input -j reject --reject-with icmp-host-prohibited

-a forward -j reject --reject-with icmp-host-prohibited

commit

sudo systemctl restart iptables

centos開放埠號

systemctl stop firewalld.service 停止firewall systemctl disable firewalld.service 禁止firewall開機啟動 firewall cmd zone public add port 80 tcp permanent 命令含義...

centos如何對外開放埠號

檢視防火牆狀態 firewall cmd state 開啟防火牆 systemctl start firewalld 關閉防火牆 systemctl stop firewalld 設定開機啟動 systemctl enable firewalld 停止並禁用開機啟動 sytemctl disable...

centos開放埠號命令

1.檢視已開放的埠 預設不開放任何埠 firewall cmd list ports 2.開啟80埠 firewall cmd zone public 作用域 add port 80 tcp 埠和訪問型別 permanent 永久生效 3.重啟防火牆 firewall cmd reload 4.停止...