Think before you speak, read before you think.

CentOS 7 更改 interface name

by

in

习惯于用 eth0 eth1 ,不习惯 em1, enp0s3,在 kickstart 文件中写如下脚本,使用 eth0, eth1

# grub 的配置,关键是内核启动参数 net.ifnames=0 biosdevname=0

cat << __EOT__ > /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet net.ifnames=0 biosdevname=0"
GRUB_DISABLE_RECOVERY="true"
__EOT__

# 生成实际使用的 grub2.cfg
grub2-mkconfig -o /boot/grub2/grub.cfg

# 删掉不喜欢的 interface name
rm -f /etc/sysconfig/network-scripts/ifcfg-em*
rm -f /etc/sysconfig/network-scripts/ifcfg-en*

# 创建 eth0, eth1 模板
cat << __EOT__ > /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO="static"
IPV6INIT="no"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
IPADDR=192.168.x.x
NETMASK=255.255.255.0
GATEWAY=192.168.x.1
__EOT__

cat << __EOT__ > /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO="static"
IPV6INIT="no"
NM_CONTROLLED="yes"
ONBOOT="no"
TYPE="Ethernet"
__EOT__

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *