虚拟机service network restart没有反应解决方法

时间:2022-06-02 05:52:36
一般我们新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)
 重启网络没有一点反应
[sz@zejin243 Desktop]$ service network restart
---没有一点反应
查看/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配置文件中即可。