Windows防火墙开放端口

时间:2015-11-11 18:13:46

标签: apache port windows-server-2012-r2 windows-firewall

我正在尝试在我自己的远程服务器上托管一个网站(在windows server2012上运行,我使用Apache作为我的Web服务器,但是另一个程序正在使用端口80(也需要运行)所以我将Apache配置为在端口8888上运行。

我假设我必须在Windows防火墙中创建一个新规则来打开端口8888,但我不知道该怎么做。

我已尝试按照本文http://www.rackspace.com/knowledge_center/article/managing-the-windows-server-2012-firewall,将端口8888替换为80并允许而不是阻止。我还尝试在端口8888上为TCP设置端口规则(如此处Firewall blocking/unblocking a port所示),但这些似乎都不起作用,并且打开端口检查工具仍将端口8888显示为已关闭。

谁能告诉我我做错了什么? 干杯, JónArnar

2 个答案:

答案 0 :(得分:0)

也许你真的不知道,但在Windows Server 2012和Windows 8操作系统中,有一个名为“New-NetFirewallRule”的新cmdlet。 此cmdlet提供了多种方法来添加新的防火墙规则。

打开PowerShell术语并输入以下内容:

    New-NetFirewallRule -DisplayName "Allow Port 80" -Direction Inbound -LocalPort 80 -Protocol TCP -Action Allow

希望它有所帮助!

答案 1 :(得分:0)

这是通过动态提供所有选项(即入站/出站,允许/拒绝,规则名称等)来打开防火墙端口的另一种方式。


$rulename = Read-Host -Prompt "Enter rule name: "
$portNumber = Read-Host -Prompt "Enter Port Number: "
$protchoice = $Host.UI.PromptForChoice('Protocol Type','Enter Protocol (TCP/UDP): ',('&TCP','&UDP'),0)
if($protchoice -eq 0)
    {
        $protchoice02 = 'TCP'
        $dirChoice = $Host.UI.PromptForChoice('Traffic Flow','Enter Traffic Flow direction (inbound/outbound): ',('&inbound','&outbound'),0)
        if($dirChoice -eq 0)
        {
         $dirChoices = 'Inbound'
         $allowdenyChoice = $Host.UI.PromptForChoice('Traffic Allowance','Allow/Deny Traffic (allow/deny): ',('&allow','&deny'),0)
         if($allowdenyChoice -eq '0')
         { 
          $allowdenyChoices = 'Allow'
          New-NetFirewallRule -DisplayName $rulename -Direction $dirChoices -LocalPort $portNumber -Protocol $protchoice02 -Action $allowdenyChoices
         }
         else
         {
         $allowdenyChoices = 'Deny'
         New-NetFirewallRule -DisplayName $rulename -Direction $dirChoices  -LocalPort $portNumber -Protocol $protchoice02 -Action $allowdenyChoices
         }
        }
        else
        {
          $dirChoices = 'Outbound'
          $allowdenyChoice = $Host.UI.PromptForChoice('Traffic Allowance','Allow/Deny Traffic (allow/deny): ',('&allow','&deny'),0)
          if($allowdenyChoice -eq '0')
          { 
           $allowdenyChoices = 'Allow'
           New-NetFirewallRule -DisplayName $rulename -Direction $dirChoices -LocalPort $portNumber -Protocol $protchoice02 -Action $allowdenyChoices
          }
          else
          {
           $allowdenyChoices = 'Deny'
           New-NetFirewallRule -DisplayName $rulename -Direction $dirChoices  -LocalPort $portNumber -Protocol $protchoice02 -Action $allowdenyChoices
          }
         }
       }
else
    { 
        $protchoice02 = 'UDP'
        $dirChoice = $Host.UI.PromptForChoice('Traffic Flow','Enter Traffic Flow direction (inbound/outbound): ',('&inbound','&outbound'),0)
        if($dirChoice -eq 0)
        {
         $dirChoices = 'Inbound'
         $allowdenyChoice = $Host.UI.PromptForChoice('Traffic Allowance','Allow/Deny Traffic (allow/deny): ',('&allow','&deny'),0)
         if($allowdenyChoice -eq '0')
         { 
          $allowdenyChoices = 'Allow'
          New-NetFirewallRule -DisplayName $rulename -Direction $dirChoices -LocalPort $portNumber -Protocol $protchoice02 -Action $allowdenyChoices
         }
         else
         {
          $allowdenyChoices = 'Deny'
          New-NetFirewallRule -DisplayName $rulename -Direction $dirChoices -LocalPort $portNumber -Protocol $protchoice02 -Action $allowdenyChoices
         }
        }
        else
        {
          $dirChoices = 'Outbound'
          $allowdenyChoice = $Host.UI.PromptForChoice('Traffic Allowance','Allow/Deny Traffic (allow/deny): ',('&allow','&deny'),0)
          if($allowdenyChoice -eq '0')
          { 
           $allowdenyChoices = 'Allow'
           New-NetFirewallRule -DisplayName $rulename -Direction $dirChoices -LocalPort $portNumber -Protocol $protchoice02 -Action $allowdenyChoices
          }
          else
          {
           $allowedenyChoices = 'Deny'
           New-NetFirewallRule -DisplayName $rulename -Direction $dirChoices -LocalPort $portNumber -Protocol $protchoice02 -Action $allowdenyChoices
          }
         }
       }