windows 如何与 Hyper-V 中的 VM 实例共享主机 VPN 连接?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/124378/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:22:12  来源:igfitidea点击:

How to share host VPN connection with VM instances in Hyper-V?

windowsnetworkinghyper-vconnectivity

提问by sergiopereira

I'm running my workstation on Server 2008 and a few servers in Hyper-V VM's on that server. I connect to my corporate LAN using VPN from the main OS (the host) but my VM's aren't seeing the servers in the corporate LAN. Internet and local access to my home network work fine. Each of the VMs has one virtual network adapter.

我在 Server 2008 上运行我的工作站,并在该服务器上的 Hyper-V VM 中运行几台服务器。我使用来自主操作系统(主机)的 VPN 连接到我的公司 LAN,但我的 VM 没有看到公司 LAN 中的服务器。Internet 和本地访问我的家庭网络工作正常。每个 VM 都有一个虚拟网络适配器。

What should I try to make it work?

我应该怎么做才能让它发挥作用?

Maybe I need to provide more details, please ask if needed.

也许我需要提供更多细节,如果需要请询问。

More details:

更多细节:

  • cannot start multiple VPN connections
  • not using NAT through the host
  • VM gets IP address from the home network router (DHCP)
  • 无法启动多个 VPN 连接
  • 不通过主机使用 NAT
  • VM 从家庭网络路由器 (DHCP) 获取 IP 地址

回答by mattlant

Like I said you need to setup some routes. Add a route to your Corp LAN via your Host as the gateway. Just the fact alone you telling me that it gets it from home DHCPP tells me that is the issue. Your VM's only see 1 default gateway, and that is to the internet. The VM's have no idea whatsoever that the Host has a VPN on it. Adding that route (on VM machines) causes any requests that your VM's make to the subnet of your corp network to route through your host rather than the home router.

就像我说的,你需要设置一些路由。通过您的主机作为网关添加到您的 Corp LAN 的路由。仅凭你告诉我它是从家里获取它的事实 DHCPP 就告诉我这就是问题所在。您的虚拟机只能看到 1 个默认网关,即互联网。虚拟机完全不知道主机上有 VPN。添加该路由(在 VM 机器上)会导致您的 VM 对公司网络子网的任何请求通过您的主机而不是家庭路由器进行路由。

Adding something like this:

添加这样的东西:

route ADD 10.0.0.0 MASK 255.0.0.0 192.168.1.30

on your VM'S would do this: Any requests made to the 10...* network would route through the computer with the IP address of 192.168.1.30. So replace the 10.0.0.0 and subnet with your corp lan, and the 192 ip with your hosts IP. That should take care of the issue.

在您的虚拟机上会这样做:对 10. 的任何请求.* 网络将通过 IP 地址为 192.168.1.30 的计算机进行路由。因此,将 10.0.0.0 和子网替换为您的 corp lan,将 192 ip 替换为您的主机 IP。那应该解决这个问题。

回答by zvikara

What type of VPN are you using? Ar you using the built-in windows VPN client, or do you have to install the client ?

您使用的是什么类型的 VPN?您是使用内置的 Windows VPN 客户端,还是必须安装客户端?

You could just set up the VPN client independently on every VM, providing you are allowed multiple simultaneous connections.

您可以在每个 VM 上独立设置 VPN 客户端,前提是您可以同时进行多个连接。

I don't think that setting up routes would work because then you will also need to set up routes on your company network.

我认为设置路由行不通,因为那样您还需要在公司网络上设置路由。

回答by mattlant

Let me make sure something clearer. You servers act as if they are physically seperated from your host. So with that in mind they need to be setup the same way as if they were seperated. That means that they need a route in their routing table. Why? Because right now their default route is to the internet via your gateway, NOT your host.

让我确定一些更清楚的事情。您的服务器就好像它们与您的主机在物理上分开一样。因此,考虑到这一点,它们需要以与分开的方式相同的方式进行设置。这意味着他们需要路由表中的路由。为什么?因为现在他们的默认路由是通过您的网关访问互联网,而不是您的主机。

In short, approach the problem the way you would if they were not VM's and they were real servers on your network.

简而言之,如果它们不是虚拟机并且它们是您网络上的真实服务器,请按照您的方式解决问题。

But as I aksed in my initial repsonse, Are they like VMWare bridged adapters. If they are what I say stands. If they are not, then thats a different story. FOr example, if they are setup in a NAT with your host, VPN should already work. Any other situation will require further investigation and more information.

但正如我在最初的回答中所问的那样,它们是否像 VMWare 桥接适配器。如果他们是我所说的立场。如果他们不是,那就是另一回事了。例如,如果它们与您的主机在 NAT 中设置,则 VPN 应该已经可以工作了。任何其他情况都需要进一步调查和更多信息。

回答by mattlant

Setup some routes in your routing tablke. It really depends on how its setup but if you can access your corp network fine on the host, then setup the routes in your vm machines.

在路由表中设置一些路由。这实际上取决于它的设置方式,但是如果您可以在主机上正常访问您的公司网络,那么请在您的虚拟机中设置路由。

Also, as I am not familiar with that VM, are the network adapters like VMWares bridged adapaters? If so you need to setup the route to route to your host.

另外,由于我不熟悉那个 VM,像 VMWares 桥接适配器这样的网络适配器吗?如果是这样,您需要设置路由到您的主机。