Linux-07. VBOX 复制 Linux 虚拟机-重置网卡规则

使用虚拟机克隆技术后,网卡的信息就会改变,为方便搭建我们的开发环境,此时重置网卡就很有必要了

  1. ip link show 登陆克隆后的虚拟机,检查网卡信息
[root@node rules.d]# ip link show
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:6c:e6:fe brd ff:ff:ff:ff:ff:ff
3: eth1:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:6f:47:74 brd ff:ff:ff:ff:ff:ff

# 从2: 3:中获取到两个mac地址:
2:link/ether 08:00:27:6c:e6:fe
3:link/ether 08:00:27:6f:47:74
# 记住这两个mac 地址,接下来的步骤会用到

  1. 编辑网卡设备配置
[root@node ~]# cd /etc/udev/rules.d/
[root@node rules.d]# ll
总用量 40
-rw-r--r--. 1 root root 1652 11月 12 2010 60-fprint-autosuspend.rules
-rw-r--r--. 1 root root 1060 11月 12 2010 60-pcmcia.rules
-rw-r--r--. 1 root root  316 10月 15 2014 60-raw.rules
-rw-r--r--. 1 root root  151 1月  26 20:11 60-vboxadd.rules
-rw-r--r--. 1 root root  535 1月   9 20:52 70-persistent-cd.rules
-rw-r--r--. 1 root root  917 1月  29 13:53 70-persistent-net.rules #编辑它
-rw-r--r--. 1 root root  320 1月  12 2015 90-alsa.rules
-rw-r--r--. 1 root root   83 10月 15 2014 90-hal.rules
-rw-r--r--. 1 root root  304 7月  24 2015 98-kexec.rules
-rw-r--r--. 1 root root   54 12月  8 2011 99-fuse.rules

[root@node rules.d]# vim 70-persistent-net.rules
# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:c3:c4:ca", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:93:4e:85", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:6c:e6:fe", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:6f:47:74", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"

# 由以上内容观察可知:该配置共配置了四个网卡信息,注意之前查询的mac地址,只有最后两个满足mac地址存在,将前两个注释,并把最后两个的名称对应更改:
# PCI device 0x8086:0x100e (e1000)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:c3:c4:ca", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100e (e1000)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:93:4e:85", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:6c:e6:fe", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:6f:47:74", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

更改计算机名

[root@node ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=node
NTPSERVERARGS=iburst

#HOSTNAME node=>node02

重启生效

[root@node ~]# reboot

……

# 重新登陆
[root@node02 ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:6C:E6:FE
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe6c:e6fe/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:62 errors:0 dropped:0 overruns:0 frame:0
          TX packets:77 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7588 (7.4 KiB)  TX bytes:7338 (7.1 KiB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:6F:47:74
          inet addr:192.168.56.3  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe6f:4774/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:133 errors:0 dropped:0 overruns:0 frame:0
          TX packets:100 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:15060 (14.7 KiB)  TX bytes:15839 (15.4 KiB)

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:12 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:720 (720.0 b)  TX bytes:720 (720.0 b)
          
[root@node02 ~]# ping 114.114.114.114
PING 114.114.114.114 (114.114.114.114) 56(84) bytes of data.
64 bytes from 114.114.114.114: icmp_seq=1 ttl=83 time=38.5 ms
64 bytes from 114.114.114.114: icmp_seq=2 ttl=64 time=38.7 ms
64 bytes from 114.114.114.114: icmp_seq=3 ttl=63 time=39.2 ms
^C
--- 114.114.114.114 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2353ms
rtt min/avg/max/mdev = 38.564/38.851/39.284/0.350 ms
[root@node02 ~]#

# 网卡测试,完成

成功!完!

你可能感兴趣的:(Linux-07. VBOX 复制 Linux 虚拟机-重置网卡规则)