一般我們新copy的虛擬機或新克隆的虛擬機第一次啟動時都會出現沒有ip地址的情況:
[
root@zejin243 network-scripts]# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:16 errors:0 dropped:0 overruns:0 frame:0
TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:960 (960.0 b) TX bytes:960 (960.0 b)
重啟網絡沒有一點反應
查看/etc/udev/rules.d/70-persistent-net.rules文件
[
root@zejin243 network-scripts]# 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 0x8086:0x100f (e1000) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:d4:dc:3f", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:dd:9b:b4", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:73:aa:48", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:09:43:5a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"
-----
eth0 與 eth2的硬件地址已經被我的另外的虛擬機使用了,故我們用eth3的,如果不知道哪些已經被用了,直接把此文件刪除,重啟linux,就會只有一行了。
編輯ip配置文件,加粗的部分要對應上。
[
root@zejin243 network-scripts]# vi ifcfg-
eth3
DEVICE="
eth3"
IPADDR=192.168.1.243
NETMASK=255.255.255.0
NETWORK=192.168.1.0
GATEWAY=192.168.1.1
DNS2=202.96.134.133
DNS1=114.114.114.114
HWADDR="
00:0c:29:09:43:5a"
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
BROADCAST=192.168.1.255
ONBOOT=yes
NAME=eth3
[
root@zejin243 network-scripts]# service network restart
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth3: Determining if ip address 192.168.1.243 is already in use for device eth3...
[ OK ]
如果還出現類似Device eth3 does not seem to be present的提示,那么直接刪除/etc/udev/rules.d/70-persistent-net.rules文件,重啟,系統會自動生成/etc/udev/rules.d/70-persistent-net.rules,一般來說會生成一個新的硬件地址,然后把里面的硬件地址復制到ip配置文件中即可。