Aim_yuan 发表于 2024-9-11 14:52:22

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

?香港云服务器的ubuntu 批量添加 IP的操作步骤:
针对整个C段IP一次性添加的方式
新建批量IP脚本文件
sudo vi /opt/ip1.sh


#!/bin/bash
for ((i=0;i>/etc/network/interfaces
echo "iface enp2s0:$i 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 enp2s0:$i 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
页: [1]
查看完整版本: 香港云服务器的ubuntu 批量添加 IP的操作步骤