操作步骤

首先,我们需要向两个虚拟机添加 3 个网卡,如下所示。

1. 添加网络适配器

打开虚拟机的设置窗口。
(确保虚拟机已关闭)

点击添加

从所有可用选项中选择网络适配器

我们可以选择任何网络连接,因为它无关紧要。
我们将不得不提前更改这些内容。
只需确保选中“开机时连接”框

完成后点击完成。

按照相同的步骤向 VM 添加 1 个 NIC。

2. 创建局域网段

完成后,就可以创建 LAN 网段并将其添加到虚拟机中了。

选择任何一个网络适配器,如下所示。
我们应该看到网络连接类型为“LAN Segments”。
单击它后会弹出一个不同的窗口

在此窗口中,我们必须创建 2 个 LAN 段,即 LAN 1 和 LAN 2,如下所示。
单击“添加”以创建相同的内容,完成后单击“确定”以保存更改。

现在我们需要为我们创建的所有 3 个网络适配器选择网络连接类型。

3. 分配网络连接类型

对于网络适配器,选择 LAN 1,如下所示。

注意:接下来单击高级并查看此 NIC 的 MAC 地址并将其保存在记事本中,因为您在前面的步骤中需要它

MAC 地址:00:0C:29:A3:F5:E6

对于网络适配器 2,选择 LAN 2,如下所示。

MAC 地址:00:0C:29:A3:F5:F0

对于网络适配器 3,选择 LAN 3,如下所示。

MAC 地址:00:0C:29:A3:F5:FA

对机器 2 重复上述相同的步骤,如下所示

对于网络适配器,选择 LAN 1,如下所示。

MAC 地址:00:0C:29:51:AA:CD

对于网络适配器 2,选择 LAN 2,如下所示。

MAC 地址:00:0C:29:51:AA:D7

对于网络适配器 3,选择 LAN 3,如下所示。

MAC 地址:00:0C:29:51:AA:E1

所以我们现在准备进入下一步。

4.分配IP地址

检查连接到 Internet 的 Windows 机器的 IP。
如我们所见,我们的 IP 地址详细信息是:

IP 地址:192.168.1.xx
网络掩码 =255.255.255.0
网关 = 192.168.1.1

Linux 1

登录到 Linux 1 虚拟机 并验证它是否包含我们添加的 3 个 NIC

[root@test ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:A3:F5:E6
          inet6 addr: fe80::20c:29ff:fea3:f5e6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:756 errors:0 dropped:0 overruns:0 frame:0
          TX packets:831 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:71519 (69.8 KiB)  TX bytes:63525 (62.0 KiB)
          Interrupt:19 Base address:0x2024
eth1      Link encap:Ethernet  HWaddr 00:0C:29:A3:F5:F0
          inet6 addr: fe80::20c:29ff:fea3:f5f0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:33 errors:0 dropped:0 overruns:0 frame:0
          TX packets:74 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5981 (5.8 KiB)  TX bytes:11003 (10.7 KiB)
          Interrupt:16 Base address:0x20a4
eth2      Link encap:Ethernet  HWaddr 00:0C:29:A3:F5:FA
          inet6 addr: fe80::20c:29ff:fea3:f5fa/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:964 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1205 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:80476 (78.5 KiB)  TX bytes:61790 (60.3 KiB)
          Interrupt:17 Base address:0x2424
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:16436  Metric:1
          RX packets:649 errors:0 dropped:0 overruns:0 frame:0
          TX packets:649 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:56376 (55.0 KiB)  TX bytes:56376 (55.0 KiB)

因此,如我们所见,所有 3 个 NIC 都可见。
现在,在开始为每个 NIC 分配 IP 地址之前,我们可以将添加的每个网络适配器与 MAC 地址进行匹配

对于网络适配器 -LAN 1 (172.168.0.0/24)
MAC 地址:00:0C:29:A3:F5:E6

注意:不要为专用网络提供任何 GATEWAY 或者 DNS

 [root@test ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
 DEVICE="eth0"
 NM_CONTROLLED=no
 ONBOOT=yes
 HWADDR=00:0C:29:A3:F5:E6
 TYPE=Ethernet
 BOOTPROTO=none
 IPADDR=172.168.0.2
 PREFIX=24
 DEFROUTE=yes
 IPV4_FAILURE_FATAL=yes
 IPV6INIT=no
 NAME="System eth0"
 USERCTL=no
 PEERDNS=yes 
 [root@test network-scripts]# cp ifcfg-eth0 ifcfg-eth1
 [root@test network-scripts]# cp ifcfg-eth0 ifcfg-eth2 

对于网络适配器 2 -- LAN 2 (10.10.10.0.0/24)
MAC 地址: 00:0C:29:A3:F5:F0

注意:不要为专用网络提供任何 GATEWAY 或者 DNS

 [root@test network-scripts]# vi ifcfg-eth1
 DEVICE="eth1"
NM_CONTROLLED=no
ONBOOT=yes
HWADDR=00:0C:29:A3:F5:F0
 TYPE=Ethernet
 BOOTPROTO=none
 IPADDR=10.10.10.2
 PREFIX=24
 DEFROUTE=yes
 IPV4_FAILURE_FATAL=yes
 IPV6INIT=no
 NAME="System eth1"
 USERCTL=no
 PEERDNS=yes 

对于网络适配器 3 -- LAN 3 (192.168.1.0/24)(连接到 Internet)
MAC 地址:00:0C:29:A3:F5:FA

 [root@test network-scripts]# vi ifcfg-eth2
 DEVICE="eth2"
 NM_CONTROLLED=no
 ONBOOT=yes
 HWADDR=00:0C:29:A3:F5:FA
 TYPE=Ethernet
 BOOTPROTO=none
 IPADDR=192.168.1.10
 PREFIX=24
 GATEWAY=192.168.1.1
 DNS1=8.8.8.8
 DEFROUTE=yes
 IPV4_FAILURE_FATAL=yes
 IPV6INIT=no
 NAME="System eth2"
 USERCTL=no
 PEERDNS=yes 
 

重启服务网络

 [root@test network-scripts]# service network restart
Shutting down interface eth0:                              [  OK  ]
 Shutting down interface eth1:                              [  OK  ]
 Shutting down interface eth2:                              [  OK  ]
 Shutting down loopback interface:                          [  OK  ]
 Bringing up loopback interface:                            [  OK  ]
 Bringing up interface eth0:                                [  OK  ]
 Bringing up interface eth1:                                [  OK  ]
 Bringing up interface eth2:                                [  OK  ]

在 Linux 2 上

[root@test1 ~]# ifconfig
eth1      Link encap:Ethernet  HWaddr 00:0C:29:51:AA:CD
          inet6 addr: fe80::20c:29ff:fe51:aacd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:801 errors:0 dropped:0 overruns:0 frame:0
          TX packets:789 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:64811 (63.2 KiB)  TX bytes:72377 (70.6 KiB)
          Interrupt:19 Base address:0x2024
eth2      Link encap:Ethernet  HWaddr 00:0C:29:51:AA:D7
          inet6 addr: fe80::20c:29ff:fe51:aad7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:21 errors:0 dropped:0 overruns:0 frame:0
          TX packets:48 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2470 (2.4 KiB)  TX bytes:7223 (7.0 KiB)
          Interrupt:16 Base address:0x20a4
eth3      Link encap:Ethernet  HWaddr 00:0C:29:51:AA:E1
          inet6 addr: fe80::20c:29ff:fe51:aae1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3461 errors:0 dropped:0 overruns:0 frame:0
          TX packets:158 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:244030 (238.3 KiB)  TX bytes:23210 (22.6 KiB)
          Interrupt:17 Base address:0x2424
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:16436  Metric:1
          RX packets:90 errors:0 dropped:0 overruns:0 frame:0
          TX packets:90 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:7200 (7.0 KiB)  TX bytes:7200 (7.0 KiB)

对于网络适配器 -LAN 1 (172.168.0.0/24)
MAC 地址:00:0C:29:51:AA:CD

注意:不要为专用网络提供任何网关或者DNS详细信息

 [root@test1 network-scripts]# vi ifcfg-eth1
 DEVICE=eth1
 NM_CONTROLLED=no
 ONBOOT=yes
 HWADDR=00:0c:29:51:aa:cd
 TYPE=Ethernet
 BOOTPROTO=none
 IPADDR=172.168.0.3
 PREFIX=24
 DEFROUTE=yes
 IPV4_FAILURE_FATAL=yes
 IPV6INIT=no
 NAME="System eth1"
 USERCTL=no
 PEERDNS=yes 
 [root@test1 network-scripts]# cp ifcfg-eth1 ifcfg-eth2
 [root@test1 network-scripts]# cp ifcfg-eth1 ifcfg-eth3 

用于网络适配器2—LAN 2(10.10.10.0.0/24)
MAC地址:00:0C:29:51:AA:D7

注意:不要为专用网络提供任何网关或者DNS详细信息

 [root@test1 network-scripts]# vi ifcfg-eth2
 DEVICE=eth2
 NM_CONTROLLED=no
 ONBOOT=yes
 HWADDR=00:0c:29:51:aa:d7
 TYPE=Ethernet
 BOOTPROTO=none
 IPADDR=10.10.10.3
 PREFIX=24
 DEFROUTE=yes
 IPV4_FAILURE_FATAL=yes
 IPV6INIT=no
 NAME="System eth2"
 USERCTL=no
 PEERDNS=yes 

对于网络适配器 3 -- LAN 3 (192.168.1.0/24)(连接到 Internet)
MAC 地址:00:0C:29:51:AA:E1

 [root@test1 network-scripts]# vi ifcfg-eth3
 DEVICE=eth3
 NM_CONTROLLED=no
 ONBOOT=yes
 HWADDR=00:0c:29:51:aa:e1
 TYPE=Ethernet
 BOOTPROTO=none
 IPADDR=192.168.1.11
 PREFIX=24
 GATEWAY=192.168.1.1
 DNS1=8.8.8.8
 DEFROUTE=yes
 IPV4_FAILURE_FATAL=yes
 IPV6INIT=no
 NAME="System eth3"
 USERCTL=no
 PEERDNS=yes 

重启网络服务

 [root@test1 network-scripts]# service network restart
Shutting down interface eth1:                              [  OK  ]
 Shutting down interface eth2:                              [  OK  ]
 Shutting down interface eth3:                              [  OK  ]
 Shutting down loopback interface:                          [  OK  ]
 Bringing up loopback interface:                            [  OK  ]
 Bringing up interface eth1:                                [  OK  ]
 Bringing up interface eth2:                                [  OK  ]
 Bringing up interface eth3:                                [  OK  ]

验证配置

在Linux1 上执行

 [root@test ~]# ping 172.168.0.3
 PING 172.168.0.3 (172.168.0.3) 56(84) bytes of data.
 64 bytes from 172.168.0.3: icmp_seq=1 ttl=64 time=0.513 ms
 64 bytes from 172.168.0.3: icmp_seq=2 ttl=64 time=0.639 ms
 ^C
 --- 172.168.0.3 ping statistics --
 2 packets transmitted, 2 received, 0% packet loss, time 1520ms
 rtt min/avg/max/mdev = 0.513/0.576/0.639/0.063 ms
[root@test ~]# ping 10.10.10.3
 PING 10.10.10.3 (10.10.10.3) 56(84) bytes of data.
 64 bytes from 10.10.10.3: icmp_seq=1 ttl=64 time=2.39 ms
 64 bytes from 10.10.10.3: icmp_seq=2 ttl=64 time=0.515 ms
 ^C
 --- 10.10.10.3 ping statistics --
 2 packets transmitted, 2 received, 0% packet loss, time 1551ms
 rtt min/avg/max/mdev = 0.515/1.453/2.392/0.939 ms
[root@test ~]# ping google.com
 PING google.com (74.125.236.167) 56(84) bytes of data.
 64 bytes from maa03s16-in-f7.1e100.net (74.125.236.167): icmp_seq=1 ttl=56 time=14.0 ms
 64 bytes from maa03s16-in-f7.1e100.net (74.125.236.167): icmp_seq=2 ttl=56 time=10.5 ms
 ^C
 --- google.com ping statistics --
 2 packets transmitted, 2 received, 0% packet loss, time 1049ms
 rtt min/avg/max/mdev = 10.584/12.334/14.085/1.754 ms

在Linux 2上执行

 [root@test1 ~]# ping 172.168.0.2
 PING 172.168.0.2 (172.168.0.2) 56(84) bytes of data.
 64 bytes from 172.168.0.2: icmp_seq=1 ttl=64 time=0.261 ms
 64 bytes from 172.168.0.2: icmp_seq=2 ttl=64 time=0.460 ms
 ^C
 --- 172.168.0.2 ping statistics --
 2 packets transmitted, 2 received, 0% packet loss, time 1127ms
 rtt min/avg/max/mdev = 0.261/0.360/0.460/0.101 ms
[root@test1 ~]# ping 10.10.10.2
 PING 10.10.10.2 (10.10.10.2) 56(84) bytes of data.
 64 bytes from 10.10.10.2: icmp_seq=1 ttl=64 time=1.12 ms
 64 bytes from 10.10.10.2: icmp_seq=2 ttl=64 time=0.628 ms
 ^C
 --- 10.10.10.2 ping statistics --
 2 packets transmitted, 2 received, 0% packet loss, time 1074ms
 rtt min/avg/max/mdev = 0.628/0.875/1.123/0.249 ms
[root@test1 ~]# ping google.com
 PING google.com (74.125.236.163) 56(84) bytes of data.
 64 bytes from maa03s16-in-f3.1e100.net (74.125.236.163): icmp_seq=1 ttl=56 time=9.69 ms
 64 bytes from maa03s16-in-f3.1e100.net (74.125.236.163): icmp_seq=2 ttl=56 time=10.3 ms
 ^C
 --- google.com ping statistics --
 2 packets transmitted, 2 received, 0% packet loss, time 1520ms
 rtt min/avg/max/mdev = 9.699/10.006/10.314/0.323 ms

配置说明

我们有 3 台机器,每台机器都有不同的 IP 范围,如下所示

连接到 Internet 的机器 1(Windows 主机)
IP 地址 192.168.1.xx
网关 192.168.1.1
网络掩码 255.255.255.0

机器 2 (Linux 1)
局域网 1 172.168.0.0/24
局域网 2 10.10.10.0/24
LAN 3 连接到 Internet 192.168.1.0/24

机器 3 (Linux 2)
局域网 1 172.168.0.0/24
局域网 2 10.10.10.0/24
LAN 3 连接到 Internet 192.168.1.0/24

配置后

  • Linux 1 和 Linux 2 应该互连到 172.168.0.0/24 和 10.10.10.0/24 的专用网络
  • Linux 1 和 Linux 2 应该连接到 Internet
  • 10.10.10.0/24 和 172.168.0.0/24 将能够相互发送/接收数据包
如何在 VMware Workstation 中配置专用网络
日期:2020-06-02 22:18:27 来源:oir作者:oir