Ubuntu批量添加IP

ubuntu 18.04 17.04

#写入到 /etc/netplan/01-netcfg.yaml
echo "      addresses: " >> /etc/netplan/01-netcfg.yaml
for ((i=1;i<=64;i++))
do
echo "        - 1.2.3.$i/29" >> /etc/netplan/01-netcfg.yaml
done
echo "      gateway4: 1.2.3.4" >> /etc/netplan/01-netcfg.yaml

#应用
netplan apply

ubuntu 16.04 14.04 脚本

# !/bin/bash
for ((i=1;i<=64;i=i+1))
do
echo "auto eth0:$i">>/etc/network/interfaces
echo "iface eth0:$i inet static">>/etc/network/interfaces
let j=$i+5
echo "address 1.2.3.$j">>/etc/network/interfaces
echo "netmask 255.255.255.248">>/etc/network/interfaces
echo "gateway 1.2.3.4">>/etc/network/interfaces
echo " ">>/etc/network/interfaces
done
# end