虚拟机克隆之后网络配置--centros为例

虚拟机克隆时,是将原来机器所有信息都克隆过去,包括相应网卡设备mac地址的漫画信息,这个需要修改的;
同时一下网络规则删除也使用于Linux中eth0和eth1之间的互相修复
【环境】VMware、centros、克隆
对虚拟机中的一台centros机器克隆完成之后,针对新建服务器网络设置包括以下几步:
修改相应的配置

1、修改主机名–需要修改文件

/etc/hosts
/etc/sysconfig/network

2、修改网卡配置

cat/etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=172.17.40.247
NETMASK=255.255.254.0
GATEWAY=172.17.40.1

—–其中DEVICE和ifcfg-ethx根据实际修改
可以通过ip addr 查看哪个网卡设备是ok的 (查看网卡状态 也可以使用ifconfig -a 或者ethtool ethx )

3、删除网络规则,里面有相应的mac信息,删除重启服务器会根据ifcfg-ethx来重新生成

/etc/udev/rules.d/70-persistent-net.rules
[root@weijin-dev0001 etc]# cat udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:93:7a:ec", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:93:31:f4", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
[root@weijin-dev0001 etc]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:93:7a:ec", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:93:31:f4", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

找到上面ok的网卡设备,在70-persistent-net.rules中找到对应的PCI device信息,将此网络规则删除,最后重启服务器,在验证,是否ok

网卡启动常用命令:

service network restart
ifup eth0
ifdown eth0

参考文章:

https://www.2cto.com/os/201308/236031.html

你可能感兴趣的:(虚拟机克隆之后网络配置--centros为例)