Ubuntu 16.04 修改网卡名字,脚本化
使用 oracle vm 安装 Ubuntu 16.04 时,网卡名称显示:enp0s3,enp0s8,可以通过修改配置文件调整网卡名称。
udev配置文件
# vi /etc/udev/rules.d/70-persistent-net.rules:
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:08:4c:07:00:48", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:08:4c:07:09:68", NAME="eth1"
网络配置文件
# vi /etc/network/interfaces
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.56.101
netmask 255.255.255.0
gateway 192.168.56.1
脚本化
#!/bin/bash
if [[ $1 == "" ]]; then
echo "Usage: .sh {92|90|88|86|84}"
exit 1
fi
route del default
route add default gw 10.0.2.1
apt install -y lrzsz zip unzip tree sysstat iftop pigz
IF1=`ifconfig -a|grep -i enp0s8`
IF2=${IF1:0-19:17}
echo "$IF2"
echo "SUBSYSTEM==\"net\", ACTION==\"add\", ATTR{address}==\"$IF2\", NAME=\"eno1\"" > /etc/udev/rules.d/70-persistent-net.rules
cat /etc/udev/rules.d/70-persistent-net.rules
sed -i 's/enp0s8/eno1/g' /etc/network/interfaces
sed -i 's/192.168.0.100/192.168.0.'"$1"'/g' /etc/network/interfaces
cat /etc/network/interfaces