針對整個C段IP一次性添加的方式
新建批量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填入網(wǎng)卡不重復(fù)起始數(shù)字,j填入IP的開始數(shù)字
#!/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
執(zhí)行批量IP腳本文件
sudo bash /opt/ip1.sh
重啟網(wǎng)卡綁定IP
sudo ?/etc/init.d/networking restart
查看已添加的IP
ip addr