美国云服务器的ubuntu 批量添加 IP的操作步骤

已关闭留言

美国云服务器的ubuntu 批量添加 IP的操作步骤

针对整个CIP一次性添加的方式

新建批量IP脚本文件

sudo vi /opt/ip1.sh

#!/bin/bash

for ((i=0;i<=254;i=i+1))

do

echo “auto enp2s0:$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<=223;i=i+1))

do

echo “auto enp2s0:$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