vmware虚拟机实现双网卡固定ip

时间:2021-03-08 13:37:28

vmware 可以添加两个网卡
一个网卡连接外网:使用NAT
一个网卡用于内网连接,使用主机模式
如何添加两个网卡
1.vmware虚拟机实现双网卡固定ip
2.vmware虚拟机实现双网卡固定ip
3.vmware虚拟机实现双网卡固定ip
虚拟机内部设置
假定条件:你内部网卡配置是正确的
进入网卡设置文件夹

/etc/sysconfig/network-scripts
cp ifcfg-eth0 ifcfg-eth2 
//ifcfg-eth2可以设置为自己喜欢的形式

修改你增加的配置:

[root@localhost network-scripts]# vim ifcfg-eth2

DEVICE=eth2
#DEFROUTE=yes
#PEERROUTES=yes
#IPV4_FAILURE_FATAL=no
#HWADDR=00:0C:29:84:35:09
HWADDR=00:0C:29:7C:00:34
//HWADDR是你刚才设置的MAC
#TYPE=Ethernet
#UUID=fc55680e-fd46-4575-a21b-03928b6b5f9f
ONBOOT=on
#NM_CONTROLLED=yes
BOOTPROTO=static
//IP是静态,你可以设置一个IP
IPADDR=192.168.21.135
NETMASK=255.255.255.0
NAME=eth2

重新加载重启
service network restart
或者/etc/init.d/network restart

Shutting down interface eth0:  Device state: 3 (disconnected)
                                                           [  OK  ]
Shutting down interface eth3:  Device state: 3 (disconnected)
                                                           [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  Active connection state: activating
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/20
state: activated
Connection activated
                                                           [  OK  ]
Bringing up interface eth3:  Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/21
                                                           [  OK  ]
[root@localhost network-scripts]# /etc/init.d/network restart
Shutting down interface eth0:  Device state: 3 (disconnected)
                                                           [  OK  ]
Shutting down interface eth3:  Device state: 3 (disconnected)
                                                           [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  Active connection state: activating
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/22
state: activated
Connection activated
                                                           [  OK  ]
Bringing up interface eth3:  Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/23
                                                           [  OK  ]

常见错误

Bringing up interface eth0:  Error: No suitable device found: no device found f
                                                           [FAILED]
Bringing up interface eth1:  Error: Connection activation failed: The connectio
                                                           [FAILED]
Bringing up interface eth2:  Error: No suitable device found: no device found f
                                                           [FAILED]

问题解决方法
找到网络配置规则

vim /etc/udev/rules.d/70-persistent-70-persistent-cd.rules
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:7c:00:34", ATTR{type}=="1", KERNEL=="eth*", NAME="eth3"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:7c:00:2a", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

确保你配置中的MAC地址和名字与ATTR{address}和NAME=”eth0”一一对应就可以了。