Ping Hyper-V 虚拟交换机 IPv4

Ping Hyper-V 虚拟交换机 IPv4

我想要一个在 Hyper-V 主机上运行的 IPv4 服务,只有虚拟机可以通过虚拟交换机访问。

Hyper-V Server 2016(删除了 IPv6 公共前缀)

Ethernet adapter vEthernet (Public Switch):

   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter
   Physical Address. . . . . . . . . : 00-25-90-2E-11-AC
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   IPv6 Address. . . . . . . . . . . : <removed>:3826:3af6(Preferred)
   Link-local IPv6 Address . . . . . : fe80::ad2c:f032:3826:3af6%3(Preferred)
   Autoconfiguration IPv4 Address. . : 169.254.58.246(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . : fe80::29c:2ff:fea9:fdd0%3
   DHCPv6 IAID . . . . . . . . . . . : 352331152
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-1F-C4-64-14-00-25-90-2E-11-AE
   DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                       fec0:0:0:ffff::2%1
                                       fec0:0:0:ffff::3%1
   NetBIOS over Tcpip. . . . . . . . : Enabled

PS C:\users\Administrator> get-netfirewallrule FPS-ICMP4-ERQ-In  | select *


Name                    : FPS-ICMP4-ERQ-In
ID                      : FPS-ICMP4-ERQ-In
DisplayName             : File and Printer Sharing (Echo Request - ICMPv4-In)
Group                   : @FirewallAPI.dll,-28502
Enabled                 : True
Profile                 : Domain, Private, Public
Platform                : {}
Direction               : Inbound
Action                  : Allow
EdgeTraversalPolicy     : Block
LSM                     : False
PrimaryStatus           : OK
Status                  : The rule was parsed successfully from the store. (65536)
EnforcementStatus       : NotApplicable
PolicyStoreSourceType   : Local
Caption                 :
Description             : Echo Request messages are sent as ping requests to other nodes.
ElementName             : File and Printer Sharing (Echo Request - ICMPv4-In)
InstanceID              : FPS-ICMP4-ERQ-In
CommonName              :
PolicyKeywords          :
PolicyDecisionStrategy  : 2
PolicyRoles             :
ConditionListType       : 3
CreationClassName       : MSFT|FW|FirewallRule|FPS-ICMP4-ERQ-In
ExecutionStrategy       : 2
Mandatory               :
PolicyRuleName          :
Priority                :
RuleUsage               :
SequencedActions        : 3
SystemCreationClassName :
SystemName              :
DisplayGroup            : File and Printer Sharing
LocalOnlyMapping        : False
LooseSourceMapping      : False
Owner                   :
Platforms               : {}
PolicyStoreSource       : PersistentStore
Profiles                : 7
RuleGroup               : @FirewallAPI.dll,-28502
StatusCode              : 65536
PSComputerName          :
CimClass                : root/standardcimv2:MSFT_NetFirewallRule
CimInstanceProperties   : {Caption, Description, ElementName, InstanceID...}
CimSystemProperties     : Microsoft.Management.Infrastructure.CimSystemProperties

虚拟机 Centos 7

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:15:5d:00:e2:0a brd ff:ff:ff:ff:ff:ff
    inet 172.16.0.249/22 brd 172.16.3.255 scope global noprefixroute dynamic eth0
       valid_lft 13592sec preferred_lft 13592sec
    inet6 <removed>:4120:3820/64 scope global noprefixroute dynamic 
       valid_lft 86314sec preferred_lft 14314sec
    inet6 fe80::b73a:6e98:36ff:d902/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

# ping6 fe80::ad2c:f032:3826:3af6%eth0
PING fe80::ad2c:f032:3826:3af6%eth0(fe80::ad2c:f032:3826:3af6%eth0) 56 data bytes
64 bytes from fe80::ad2c:f032:3826:3af6%eth0: icmp_seq=1 ttl=64 time=0.725 ms

# ping6 <removed>:3826:3af6
PING <removed>:3826:3af6(<removed>:3826:3af6) 56 data bytes
64 bytes from <removed>:3826:3af6: icmp_seq=1 ttl=64 time=0.755 ms

# ping 169.254.58.246
PING 169.254.58.246 (169.254.58.246) 56(84) bytes of data.
^C
--- 169.254.58.246 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 999ms

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.3.254    0.0.0.0         UG    100    0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
172.16.0.0      0.0.0.0         255.255.252.0   U     100    0        0 eth0
172.17.0.0      0.0.0.0         255.255.255.0   U     0      0        0 docker0

# arp -n
Address                  HWtype  HWaddress           Flags Mask            Iface
172.16.1.118             ether   00:15:5d:00:e2:0e   C                     eth0
172.16.3.254             ether   00:9c:02:a9:fd:d0   C                     eth0
172.16.0.226             ether   00:25:90:2e:11:ae   C                     eth0
169.254.58.246           ether   00:25:90:2e:11:ac   C                     eth0

# ping 172.16.0.226
PING 172.16.0.226 (172.16.0.226) 56(84) bytes of data.
64 bytes from 172.16.0.226: icmp_seq=1 ttl=128 time=1.23 ms
64 bytes from 172.16.0.226: icmp_seq=2 ttl=128 time=0.708 ms

172.16.0.226 是 Hyper-V 主机的 LAN 适配器

我在 Hyper-V 主机上进行了数据包捕获,并看到 ping 请求传入。您可以在上方看到表格具有正确的 MAC。Hyper-V 有一条允许 ICMPv4 ping 的规则

总结一下:

  • 可以 ping 虚拟交换机 IPv6 公共和本地链路
  • 可以 ping Hyper-V LAN 适配器 IPv4
  • 无法 ping Hyper-V IPv4 本地链路
  • Hyper-V 主机接收 ICMPv4 数据包
  • Hyper-V 主机防火墙设置为允许 ping(我认为?——参见上文)

答案1

事实证明,我在错误的接口上设置了 IP 地址。IP 应该设置在与交换机关联的适配器上,而不是交换机上。

New-NetIPAddress -IPAddress 172.16.1.116 -PrefixLength 22 -DefaultGateway 172.16.3.254 -InterfaceAlias Ethernet -SkipAsSource $false
Set-DnsClientServerAddress -interfaceindex 11 -serveraddresses 172.16.3.254,fe80::29c:2ff:fea9:fdd0
New-NetIPAddress -IPAddress 169.254.169.254 -PrefixLength 16 -InterfaceAlias Ethernet -SkipAsSource $true

相关内容