香港云服务器的ubuntu 批量添加 IP的操作步骤

[复制链接] |主动推送
查看36 | 回复0 | 2024-9-11 14:52:22 | 显示全部楼层 |阅读模式
?香港云服务器的ubuntu 批量添加 IP的操作步骤:
针对整个C段IP一次性添加的方式
新建批量IP脚本文件
sudo vi /opt/ip1.sh


#!/bin/bash
for ((i=0;i>/etc/network/interfaces
echo "iface enp2s0i inet static">>/etc/network/interfaces
let j=$i+1
echo "address 192.168.1.$j">>/etc/network/interfaces
echo "netmask 255.255.255.0">>/etc/network/interfaces
#echo "gateway 192.168.1.1">>/etc/network/interfaces
echo " ">>/etc/network/interfaces
done
# end


ubuntu 批量添加
针对多C段的IP添加方式,i填入网卡不重复起始数字,j填入IP的开始数字
#!/bin/bash
#i is iface, j is ip
j=162
for ((i=194;i>/etc/network/interfaces
echo "iface enp2s0i inet static">>/etc/network/interfaces
echo "address 192.168.1.$j">>/etc/network/interfaces
echo "netmask 255.255.255.0">>/etc/network/interfaces
#echo "gateway 192.168.1.1">>/etc/network/interfaces
echo " ">>/etc/network/interfaces
let j=$j+1
done
# end


执行批量IP脚本文件
sudo bash /opt/ip1.sh


重启网卡绑定IP
sudo /etc/init.d/networking restart


查看已添加的IP
ip addr
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则