Linux Almalinux - 添加第一个可用的 IP 地址

问题描述 投票:0回答:1
for i in {1..254}; do
if ! [ grep 10.22.33.$i /etc/hosts ]; then
sudo echo -e "10.22.33.$i ${Name}.${Domain}" >> /etc/hosts
break
fi
done

我想添加下一个可能的 IP 地址。 有人可以帮我弄这个吗?对于 /24 子网

linux for-loop ip
1个回答
0
投票

处理您的代码片段(显然不是完整的脚本,没有 shebang,并且名称和域未定义):

for i in {1..254}; do
if ! grep 10.22.33.$i /etc/hosts ; then
    sudo echo -e "10.22.33.$i ${Name}.${Domain}" >> /etc/hosts
    break
fi
done
© www.soinside.com 2019 - 2024. All rights reserved.