【问题标题】:Windows Azure VM EndpointsWindows Azure 虚拟机端点
【发布时间】:2012-10-02 20:50:00
【问题描述】:

我是 Windows Azure 的新手,网络知识有限。我有一个在 Windows azure 上运行的 VM,它被配置为具有虚拟网络。因此,在 Dashboard 下,机器会有以下信息:

Public virtual IP address (VIP): 168.62.210.xx
Internal IP Address: 10.1.1.4

我在那台机器上运行了一个自定义服务器,它将侦听端口 2641。在端点下,我有:

Name   Protocol Public Port Private Port Load Balanced
Handle TCP      2641        2641         NO

我假设会有一个 NAT 基本上将传入流量从 168.62.210.xx:2641 路由到 10.1.1.4:2641,反之亦然(从 10.1.1.4 到 168.62.210.xx)?

有没有办法验证该端口是否工作?

在linux上,nc -z 168.62.210.xx 2641; echo $?的输出为1(表示端口未打开)。

如果我设置服务器,我假设我必须将服务器绑定到 10.1.1.4 而不是 168.62.210.xx?

任何帮助将不胜感激。

谢谢,

【问题讨论】:

    标签: windows azure port endpoint


    【解决方案1】:

    您是否在 VM 上的 Windows 防火墙上打开了端口 (2641)?

    【讨论】:

    • 嗯,这不是在我们添加端点时自动完成的吗?我关闭了防火墙并且通信通过了,所以防火墙阻止了它。
    • 不,添加端点只允许流量(通过网络)流动。编辑端点不会更改 Windows Server 防火墙设置(不会更改操作系统)。使用虚拟机(在 IaaS 环境中),您负责完全管理操作系统。 Windows Azure 管理门户可以帮助您配置一些网络选项,但不能帮助您配置 VM 的操作系统。
    • 你确定你的Linux机器可以通过2641端口上网吗?假设您在 Windows Azure 中的 VM 是 Windows Server 机器,而不是 Linux 机器(它不会在虚拟网络中),您是否尝试过使用 netstat -ano 等命令查看是否有进程在端口 2641 上侦听?找到“:2641”?对于防火墙,请在端口 2641 上添加入站规则。您可以使用具有高级安全性的 Windows 防火墙来执行此操作。
    【解决方案2】:

    请确保您已在与 vm 网络接口关联的网络安全组中配置入站和出站安全规则。

    类似于 azure 门户网站上列出的图片:

    在azure中配置网络规则的另一种方法是调用Azure PowerShell SDK,你可以使用下面的代码sn-ps

    # 0. set the target resource group name and target vm name
    $ResourceGroupName = "ocoslab-eric" # set your own resource group
    $VMName = "vm-eric-demo" # set your own vm name
    
    # 1. get the vm information
    $VM = Get-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $VMName
    
    # 2. get the network interface information
    $NICID = $VM.NetworkInterfaceIDs[0]
    $NICName = ([regex]"/.*/(.*?)$").Match($NICID).Groups[1].Value
    $NICResourceGroupName = ([regex]"/resourceGroups/(.*?)/").Match($NICID).Groups[1].Value
    $NIC = Get-AzureRmNetworkInterface -Name $NICName -ResourceGroupName $NICResourceGroupName
    
    # 3. get or create the associated security network group
    If ($NIC.NetworkSecurityGroup -eq $null) {
        $NSG = New-AzureRmNetworkSecurityGroup -Name 'custom-nsg' -Location $VM.Location -ResourceGroupName $ResourceGroupName
        $NIC.NetworkSecurityGroup = $NSG
    } Else {
        $NSGId = $NIC.NetworkSecurityGroup.Id
        $NSGName = ([regex]"/.*/(.*?)$").Match($NSGId).Groups[1].Value
        $NSGResourcGroup = ([regex]"/resourceGroups/(.*?)/").Match($NSGId).Groups[1].Value
        $NSG = Get-AzureRmNetworkSecurityGroup -Name $NSGName -ResourceGroupName $NSGResourcGroup
        $NIC.NetworkSecurityGroup = $NSG
    }
    
    # 4. create security rule to allow the port and associate with the security network group
    # Parameter explanation:
    #   a.  -Name                       Specifies the name of a network security rule configuration
    #   b.  -Access                     Specifies whether network traffic is allowed or denied. psdx_paramvalues Allow and Deny.
    #   c.  -Protocol                   Specifies the network protocol that a rule configuration applies to. 
    #                                   - Tcp
    #                                   - Udp
    #                                   - Wildcard character (*) to match both 
    #   d.  -Direction                  Specifies whether a rule is evaluated on incoming or outgoing traffic. psdx_paramvalues Inbound and Outbound.
    #   e.  -SourceAddressPrefix        Specifies a source address prefix. psdx_paramvalues
    #                                   - A CIDR
    #                                   - A source IP range
    #                                   - A wildcard character (*) to match any IP address.
    #   f.  -SourcePortRange            Specifies a source port or range. This value is expressed as an integer, as a range between 0 and 65535, or as a wildcard character (*) to match any source port.
    #   g.  -DestinationAddressPrefix   Specifies a destination address prefix. psdx_paramvalues
    #                                   - A Classless Interdomain Routing (CIDR) address
    #                                   - A destination IP address range
    #                                   - A wildcard character (*) to match any IP address  
    #   h.  -DestinationPortRange       Specifies a destination port or range. psdx_paramvalues
    #                                   - An integer
    #                                   - A range of integers between 0 and 65535
    #                                   - A wildcard character (*) to match any port
    #   i.  -Priority                   Specifies the priority of a rule configuration. psdx_paramvalues An integer between 100 and 4096. The priority number must be unique for each rule in the collection. The lower the priority number, the higher the priority of the rule.
    
    Add-AzureRmNetworkSecurityRuleConfig  -NetworkSecurityGroup $NSG `
                    -Name 'custom_rule_name' `
                    -Access Allow `
                    -Protocol Tcp `
                    -Direction Inbound `
                    -SourceAddressPrefix Internet `
                    -SourcePortRange * `
                    -DestinationAddressPrefix * `
                    -DestinationPortRange 3389 `
                    -Priority 100 | Out-Null
    
    # 5 finally, set the NetworkSecurityGroup and NetworkInterface state
    Set-AzureRmNetworkSecurityGroup -NetworkSecurityGroup $NSG | Out-Null
    Set-AzureRmNetworkInterface -NetworkInterface $NIC | Out-Null
    
    Write-Host "Done"
    

    并且,对于完整的代码示例可下载位,请访问How to manage port for Azure Virtual Machine by PowerShell

    【讨论】:

      猜你喜欢
      • 2014-01-31
      • 2015-12-30
      • 1970-01-01
      • 2014-03-08
      • 2014-08-30
      • 1970-01-01
      • 2012-08-04
      • 2016-05-26
      • 1970-01-01
      相关资源
      最近更新 更多