1. 程式人生 > >虛擬機器克隆之後網路配置--centros為例

虛擬機器克隆之後網路配置--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

參考文章: