【问题标题】:Powershell remoting with ip-address as target以 ip 地址为目标的 Powershell 远程处理
【发布时间】:2011-09-29 01:38:00
【问题描述】:

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

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

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

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

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

Enter-PSSession -Computername 192.168.123.123 -credentials $cred 

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

编辑2
当我尝试使用 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.

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

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

【问题讨论】:

  • Enable-PSRemoting 没有 -ComputerName 参数。你的意思是Enter-PSSession
  • 呃,是的。我很困惑 :) 我会编辑它。
  • 尝试命令时收到的错误信息是什么?

标签: powershell remoting powershell-remoting


【解决方案1】:

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

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

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

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

此外,如果此连接中涉及的两台计算机不在同一个 AD 域中,则默认身份验证机制将不起作用。阅读“help 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.

【讨论】:

  • 感谢唐的回答。这清除了我的大部分无知。我现在无法测试它,但我会尽快测试。如果我理解的一切都是正确的,那么我需要做的就是按照kb 配置 WinRM 来监听 https-requests,对吧?
  • 是的,还可以使用 TrustedHosts 列表并明确提供凭据。您可能还会发现您必须启用基本身份验证而不是 Kerberos。
  • 是的,启用基本身份验证改变了问题。可悲的是,在我按照说明和各种教程和操作方法进行操作后,我收到了拒绝访问的消息。我不知道为什么我没有访问。当我尝试通过主机名连接时,凭据有效。没关系...我找到了一个不需要 PSRemoting 的解决方案。但感谢您的帮助。我现在更好地理解远程处理过程,我认为这不是 WinRM 设置拒绝我的访问。
  • 对我来说是 ip address:port 是问题所在。我更改为主机名:端口并且它有效。谢谢
【解决方案2】:

尝试这样做:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force

【讨论】:

  • 这也不起作用。该值已设置为“*”。但是有一些策略或设置阻止客户端通过 ip 连接。我需要更改该设置,而不是受信任的主机(我已经知道受信任的主机设置)
  • 这个命令应该用在源(工作站-远程)还是目标(虚拟机-远程)上?
【解决方案3】:

我在我的基础架构中测试您的断言,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 工作,您最好在通往服务器的途中查看防火墙设置。 Installation and Configuration for Windows Remote Management 可以帮助你。 WinRM 正在等待的 TCP 端口是:

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

WinRM 2.0:默认 HTTP 端口为 5985。


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

Set-Item WSMan:\localhost\Client\TrustedHosts *

【讨论】:

  • 我也无法从内部网络通过 IP 连接。我从我们的 DC 中尝试过它,它仅在我使用目标主机名时才有效。我将编辑我的错误消息。
【解决方案4】:

这些家伙已经给出了简单的解决方案,你应该看看帮助 - 这很好,看起来一口气很多,但实际上阅读起来很快:

get-help about_Remote_Troubleshooting | more

【讨论】:

  • 您知道,如果您使用“帮助 about_remote_troubleshooting”,您可以跳过“|更多”部分:)。
【解决方案5】:

在你的机器上*运行'Set-Item WSMan:\localhost\Client\TrustedHosts -Value "$ipaddress"

*运行 PSSession 的机器

【讨论】:

  • 如果您需要多个 IP 地址在受信任的主机中,请添加 -Concat
【解决方案6】:

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

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

【讨论】:

    【解决方案7】:

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

    Enter-PSSession -Computername NameOfComputerIveAddedToMyHostFile -credentials $cred 
    

    【讨论】:

      【解决方案8】:

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

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

      winrm invoke Restore winrm/Config
      

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

      winrm quickconfig
      

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

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

      再次尝试远程连接

      Reference

      Configure winrm for HTTPS

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-02
        • 2020-07-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-09
        • 2014-11-19
        相关资源
        最近更新 更多