背景
测试系统ubuntu16.04 64位
1.修改网卡名
/etc/default/grub
找到GRUB_CMDLINE_LINUX=“”
改为GRUB_CMDLINE_LINUX=“net.ifnames=0 biosdevname=0”
然后sudo grub-mkconfig -o /boot/grub/grub.cfg
2.生成网卡配置
#! /bin/bash
FILE_NETWORK_INTERFACE=/etc/network/interfaces
FLAG_HASSET_NMSP=0
NUM_NETWORK_INTERFACE=0
LISTNAME_NETWORK_INTERFACE=`cat /proc/net/dev | awk '{if(NR > 2) print substr($1, 0, index($1,":")-1)}'`
for network_interface in ${LISTNAME_NETWORK_INTERFACE}
do
let NUM_NETWORK_INTERFACE=${NUM_NETWORK_INTERFACE}+1;
done
for network_interface in ${LISTNAME_NETWORK_INTERFACE}
do
if [ "2" = "$NUM_NETWORK_INTERFACE" ]; then
cat >${FILE_NETWORK_INTERFACE} << "EOF"
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto eth0:1
iface eth0:1 inet static
address 192.168.200.136
netmask 255.255.255.0
EOF
elif [ "3" = "$NUM_NETWORK_INTERFACE" ]; then
cat >${FILE_NETWORK_INTERFACE} << "EOF"
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto eth0:1
iface eth0:1 inet static
address 192.168.200.136
netmask 255.255.255.0
auto eth1
iface eth1 inet static
address 192.168.2.136
netmask 255.255.255.0
EOF
elif [ "4" = "$NUM_NETWORK_INTERFACE" ]; then
cat >${FILE_NETWORK_INTERFACE} << "EOF"
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto eth0:1
iface eth0:1 inet static
address 192.168.200.136
netmask 255.255.255.0
auto eth1
iface eth1 inet static
address 192.168.2.136
netmask 255.255.255.0
auto eth2
iface eth2 inet static
address 192.168.3.136
netmask 255.255.255.0
EOF
elif [ "5" = "$NUM_NETWORK_INTERFACE" ]; then
cat >${FILE_NETWORK_INTERFACE} << "EOF"
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto eth0:1
iface eth0:1 inet static
address 192.168.200.136
netmask 255.255.255.0
auto eth1
iface eth1 inet static
address 192.168.2.136
netmask 255.255.255.0
auto eth2
iface eth2 inet static
address 192.168.3.136
netmask 255.255.255.0
auto eth3
iface eth2 inet static
address 192.168.4.136
netmask 255.255.255.0
EOF
fi
done