简体   繁体   中英

windows firewall open port

I'm trying to host a website on my own remote server (running on windows server2012, I'm using Apache as my web server but port 80 is being used by another program (which also needs to be running) so I configured Apache to run on port 8888.

I assume I have to make a new rule in Windows Firewall to open port 8888, but I'm not sure how to do that.

I've tried follow this article http://www.rackspace.com/knowledge_center/article/managing-the-windows-server-2012-firewall , substituting port 8888 for 80 and allowing instead of blocking. I also tried setting up a port rule for TCP on port 8888 (as shown here Firewall blocking/unblocking a port ) but neither of those seem to work and open port check tools still show port 8888 as closed.

Can anyone tell me what I'm doing wrong? cheers, Jón Arnar

Maybe you don't really know that but in Windows Server 2012 and Windows 8 operating systems, there is a new cmdlet wich is called "New-NetFirewallRule". This cmdlet provides myltiple ways to add new firewall rules.

Open a PowerShell term and type in the following :

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

Hope it helped!

Here is another way of opening the firewall port by giving all options dynamically ie inbound/outbound, allow/deny, name of rule etc.


$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
          }
         }
       }  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM