69

我在我的 Server 2008 R2 上成功启用了 PSRemoting。我可以使用主机名作为目标从同一网络中执行远程 pssession。

当我尝试从任何计算机(在网络内或从另一个网络(例如通过 VPN))使用 IP 地址作为目标时,我失败了。我希望能够通过我的 VPN 连接使用远程处理,因为无法解析主机名,所以我必须使用 IP 地址。

我不想将名称添加到我的主机文件中,因为我们客户端的其他一些服务器具有相同的 dns 名称,我不想删除并再次插入名称 IP 地址关联然后再次。

我希望有人能告诉我如何允许通过 IP 调用 psremoting-target。

编辑:更具体地说,我希望能够运行这个:

Enter-PSSession -Computername 192.168.123.123 -credentials $cred 

-Computername但是,如果我将主机名传递给“ ” ,我只能运行该命令

Edit2
当我尝试使用 ip 而不是主机名(来自内部网络)登录时,我收到以下错误消息:

Enter-PSSession : Connecting to remote server failed with the following error message : The WinRM client cannot process
 the request. Default authentication may be used with an IP address under the following conditions: the transport is HT
TPS or the destination is in the TrustedHosts list, and explicit credentials are provided. Use winrm.cmd to configure T
rustedHosts. Note that computers in the TrustedHosts list might not be authenticated. For more information on how to se
t TrustedHosts run the following command: winrm help config. For more information, see the about_Remote_Troubleshooting
 Help topic.

Edit3:
我知道 WSMan 的可信主机设置,但这似乎不是问题。它已经设置为“*”(我在启用远程处理后立即这样做了),但我仍然无法使用 ip 作为目标计算机名连接到该服务器,但我可以使用主机名作为目标计算机名进行连接. 似乎 IIS 中的绑定之类的东西会阻止侦听器侦听针对 ip 号而不是主机名的请求。但是没有安装 IIS。我不知道在哪里寻找这样的设置。

2011-07-12 更新:
好的,我认为trustedhosts 设置不是问题,因为我可以通过主机名从我们的DC 连接,但如果我使用计算机参数的目标IP 地址则不能。
我想,问题一定是听者。也许侦听器不接受针对目标 IP 而不是目标主机名的请求。但我不知道如何改变它。

4

8 回答 8

56

错误消息为您提供了您需要的大部分内容。这不仅仅是关于 TrustedHosts 列表;意思是为了使用带有默认身份验证方案的 IP 地址,您还必须使用 HTTPS(默认情况下未配置)并提供显式凭据。我可以告诉你至少没有使用 SSL,因为你没有使用 -UseSSL 开关。

请注意,默认情况下未配置 SSL/HTTPS - 这是您必须采取的额外步骤。您不能只添加 -UseSSL。

默认的身份验证机制是 Kerberos,它希望看到真实的主机名,就像它们出现在 AD 中一样。不是 IP 地址,不是 DNS CNAME 昵称。有些人会启用基本身份验证,这不太挑剔 - 但您还应该设置 HTTPS,否则您会以明文形式传递凭据。Enable-PSRemoting 仅设置 HTTP。

将名称添加到您的主机文件将不起作用。这不是名称解析的问题。这是关于如何进行计算机之间的相互身份验证。

此外,如果此连接中涉及的两台计算机不在同一个 AD 域中,则默认身份验证机制将不起作用。阅读“帮助 about_remote_troubleshooting”以获取有关配置非域和跨域身份验证的信息。

来自http://technet.microsoft.com/en-us/library/dd347642.aspx上的文档

HOW TO USE AN IP ADDRESS IN A REMOTE COMMAND
-----------------------------------------------------
    ERROR:  The WinRM client cannot process the request. If the
    authentication scheme is different from Kerberos, or if the client
    computer is not joined to a domain, then HTTPS transport must be used
    or the destination machine must be added to the TrustedHosts
    configuration setting.

The ComputerName parameters of the New-PSSession, Enter-PSSession and
Invoke-Command cmdlets accept an IP address as a valid value. However,
because Kerberos authentication does not support IP addresses, NTLM
authentication is used by default whenever you specify an IP address. 

When using NTLM authentication, the following procedure is required
for remoting.

1. Configure the computer for HTTPS transport or add the IP addresses
   of the remote computers to the TrustedHosts list on the local
   computer.

   For instructions, see "How to Add a Computer to the TrustedHosts
   List" below.


2. Use the Credential parameter in all remote commands.

   This is required even when you are submitting the credentials
   of the current user.
于 2011-07-12T16:49:39.417 回答
29

尝试这样做:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force
于 2011-07-06T15:29:07.937 回答
5

我在我的基础架构中测试了您的断言,IP 地址不是问题,以下对我有用:

PS C:\Users\JPB> hostname
JPBCOMPUTER
PS C:\Users\JPB> Enter-PSSession -ComputerName 192.168.183.100 -Credential $cred
[192.168.183.100]: PS C:\Users\jpb\Documents>
[192.168.183.100]: PS C:\Users\jpb\Documents> hostname
WM2008R2ENT

如果您尝试跨 VPN 工作,您最好在通往服务器的途中查看防火墙设置。Windows 远程管理的安装和配置可以帮助您。WinRM 正在等待的 TCP 端口是:

WinRM 1.1 及更早版本:默认 HTTP 端口为 80。

WinRM 2.0:默认的 HTTP 端口是 5985。


编辑:根据您的错误,您可以在您的客户端计算机上进行测试:

Set-Item WSMan:\localhost\Client\TrustedHosts *
于 2011-07-06T03:29:43.217 回答
3

伙计们给出了简单的解决方案,你应该看看帮助 - 这很好,一次看起来很多,但实际上读起来很快:

get-help about_Remote_Troubleshooting | more
于 2011-07-06T22:54:46.387 回答
3

On your machine* run 'Set-Item WSMan:\localhost\Client\TrustedHosts -Value "$ipaddress"

*Machine from where you are running PSSession

于 2018-08-23T03:26:37.283 回答
2

在 Windows 10 上,确保 WinRM 服务正在运行以调用命令很重要

* Set-Item wsman:\localhost\Client\TrustedHosts -value '*' -Force *

于 2019-08-07T08:38:14.217 回答
1

对于那些不关心 Microsoft 施加的任意限制的人,您可以简单地将主机文件条目添加到您尝试连接的服务器的 IP,而不是使用它而不是 IP 来绕过此限制:

Enter-PSSession -Computername NameOfComputerIveAddedToMyHostFile -credentials $cred 
于 2021-01-21T16:46:38.803 回答
1

请在客户端尝试以下操作:

运行以下命令恢复监听配置:

winrm invoke Restore winrm/Config

运行以下命令以执行 Windows 远程管理服务及其侦听器的默认配置:

winrm quickconfig

再次配置 winrm 后,确保主机受信任:

Set-Item wsman:\localhost\Client\TrustedHosts -value "$ipaddress" -Force 

再次尝试远程连接

参考

为 HTTPS 配置 winrm

于 2022-02-25T18:42:06.900 回答