The shell script opens ports in batches (take 3306, 8080 as an example), and prints out all open ports

You can use the following script to open ports 3306 and 8080 in batches, and output all opened ports:

#!/bin/bash

# 批量开放端口
for port in 3306 8080; do
  firewall-cmd --zone=public --add-port=$port/tcp --permanent
done

# 重载防火墙配置
firewall-cmd --reload

# 查看已经开放的端口
echo "已经开放的端口:"
firewall-cmd --list-ports

The script uses fora loop to open ports 3306 and 8080 in batches, and uses firewall-cmdcommands to configure firewall rules. Among them, --zone=publicthe open port is a public area, --add-port=$port/tcpand the open port number is a variable $port, --permanentwhich means that it is permanently effective, and the firewall configuration needs to be reloaded to take effect. Finally, use firewall-cmd --list-portsthe command to output the ports that have been opened.

おすすめ

転載: blog.csdn.net/weixin_42279822/article/details/130646023