目前我正在使用 ufw 通过键入手动添加 ip 规则
sudo ufw allow from (my ip address)
我通过从数据库调用一些脚本来检索客户端 IP 地址并将其保存到 .txt 文件中。
这是我得到的值
ipaddress
10.1.100.90
10.1.100.91
是否可以读取 .txt 文件中的 IP 地址并将其保存到规则中,而不是手动输入?
最佳答案
您可以使用如下所示的 bash
脚本
#!/bin/bash
{
# Skip the header line containing 'name ipaddress'
read skipLine;
# Read the rest of the lines till end of the file
while IFS= read -r name IP
do
# All the IP's are stored in the variable $IP. Use it
# however you want
printf "%s %s\n" "$name" "$IP"
# To print only the IPs, do
# printf "%s\n" "$IP"
done
} <IPFile
# IPFile - Input file name containing IP addresses. Replace it with your file
关于mysql - 从文本文件读取 IP 地址到 IPTABLES,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41997248/