how to open/close ports using DOS command

Posted on 2006-05-03
Last Modified: 2009-04-28
I know netstat to check current ports using in my workstation, but I do not know which command to control these ports?
Can anyone help? thanks/

Question by:robinyanwang
    LVL 12

    Accepted Solution

    type netstat /? at the prompt

    LVL 77

    Expert Comment

    by:Rob Williams
    There are a series of commands. For example to open a port:
       netsh firewall add portopening TCP 80 HTTP enable subnet
    Where service is HTTP, Port is 80, Protocol is TCP and allowed scope is the subnet

    Some useful articles
    A general overview:

    Condensed instruction/syntax:

    Very detailed instructions starting on page 37 of the following Microsoft document:
    LVL 3

    Expert Comment

    Open ports are associated with services running on your PC.  You need to find out what service uses that port, then shut off that service using the Services administrative tool, or by shutting down the third party application that opens the port.

    Netstat -an will show you your "listening" ports... the ones opened by services and apps.

    C:\>netstat -an

    Active Connections

      Proto  Local Address          Foreign Address        State
      TCP                 LISTENING
      TCP                LISTENING
      TCP                LISTENING
      TCP               LISTENING
      TCP               LISTENING

    LVL 9

    Expert Comment

    LVL 77

    Expert Comment

    by:Rob Williams
    robinyanwang, your question was "how to open/close ports using DOS command........I do not know which command to control these ports?"

    I don't understand how the answer you accepted, using netstat, answers your question of how to open or close ports. Netstat, as you yourself stated, simply displays protocol statistics.  Future readers look to the accepted answer as a solution. Selecting an incorrect answer is misleading for them. You may wish to; re-open the question, change the awarded points, or if no answer is acceptable, ask to have the question closed. You can do so by posting a question in the community support page.
    LVL 5

    Expert Comment

    Well, here's a problem that I'm having:

    When I use

    netsh firewall delete portopening tcp XXX
    or even
    netsh firewall add portopening tcp blab lbabl ablab

    and then I use the netstat utility to view the open ports, I still see the one (that I closed) listed.

    >netsh firewall add portopening tcp 91 randomport
    >netstat -a|find /n /i "91"


    But when I open the windows firewall GUI, I see the port that I added. (it's just not reflected by netstat).  Arg.

    I also agree (respectifully) with RobWill re:the accepted solution.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    NetScaler load balancer for Linux containers

    Get all the features you need to load balance your containerized microservices applications from NetSCaler CPX Express. Integrated with Google Kubernetes, Docker Swarm, and Apache Mesos container management systems.  Supported by Citrix. Free trial version. Deploy in minutes.

    What is IRC? IRC (Internet Relay Chat) is a form of communication between multiple users. It is available freely to anyone with inernet access. IRC is a great way to communicate with others e.g. There is an IRC channel for Ubuntu Linux, which is fo…
    #Citrix #Citrix Netscaler #HTTP Compression #Load Balance
    After creating this article (, I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
    After creating this article (, I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now