通常咱們本機測試一些Linux服務集羣時須要安裝多臺linux虛機,大多狀況是安裝一臺模板機進行復制。linux
在VirtualBox中進行復制後,咱們須要注意網卡變動。centos
修改內容包括mac地址,和IP相關配置。網絡
一,mac地址修改與VirtualBox提供的一致。ide
centos中mac地址的修改在/etc/udev/rules.d/70-persistent-net.rules文件中。oop
#
# 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 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:E5:A8:1A", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"spa
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:E5:A8:1A", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"rest
# PCI device 0x8086:0x100e (e1000) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:e5:a8:1a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"ip
修改你使用的網卡爲正確地址。generator
二,修改網卡IP配置
該文件在/etc/sysconfig/network-scripts/ifcfg-eth0 中,修改內容以下:
DEVICE=eth1
TYPE=Ethernet
UUID=5f39aa83-e8ef-480f-ba36-00a7ebaa76d2
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static或dhcp(動態分配就不須要手動設置網關,DNS這些信息)
HWADDR=08:00:27:9A:E5:AC
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPADDR=192.168.31.120
GATEWAY=192.168.31.1
DNS1=192.168.1.1
IPV6INIT=no
USERCTL=no
NAME="System eth1"
固然修改完成後不會當即生效,你能夠選擇重啓,或命令讓其生效。
重啓網絡
# service network restart
或者
# /etc/init.d/network restart
故障案例一:
ifconfig...沒有看到eth0.。而後重啓網卡又報下面錯誤。
故障現象:
service network restart
Shutting down loopback insterface: [ OK ]
Bringing up loopback insterface: [ OK ]
Bringing up interface eth0: Device eth0 does not seem to be present,delaying initialization. [FAILED]
首先,打開內容以下面例子所示:
# vi /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 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:8f:89:9
7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:50:bd:1
7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
記錄下,eth1網卡的mac地址00:0c:29:50:bd:17
接下來,打開/etc/sysconfig/network-scripts/ifcfg-eth0
將
DEVICE="eth0" 改爲 DEVICE="eth1" ,
將 HWADDR="00:0c:29:8f:89:97" 改爲上面的mac地址 HWADDR="00:0c:29:50:bd:17"
最後,重啓網絡