Essential Windows Commands

From CTWUG Wiki
Jump to: navigation, search

Very often when new users are having problems, its very hard for admins to find the problem. By learning these basic commands, you can help yourself and help your admin find the cause of your problem much quicker. Below is a list some basic, but very usefull Windows command prompt tools.

PING

Test a network connection - if successful, ping returns the ip address.

Syntax

PING [options] destination_host

Options

-w timeout          Timeout in milliseconds to wait for each reply.
-i TTL              Time To Live.
-v TOS              Type Of Service.
-a                  Resolve addresses to hostnames.
-n count            Number of echo requests to send.
-t                  Ping the destination host until interrupted.
-l size             Send buffer size.
-f                  Set Don't Fragment flag in packet.
-r count            Record route for count hops.
-s count            Timestamp for count hops.
-j host_list        Loose source route along host_list.
-k host_list        Strict source route along host_list.
destination_host    The name of the remote host
  • A response of "Request timed out" means there was no response to the ping attempt in the default time period of one second.

If the latency of the response is more than one second. Use the -w option on the ping command to increase the time-out. For example, to allow responses within five seconds, use ping -w 5000.

  • A successful PING does NOT always return an %errorlevel% == 0. Therefore to reliably detect a successful ping - pipe the output into FIND and look for the text "TTL"
  • Note that "Reply" in the output of PING does not always indicate a positive response. You may receive a message from a router such as: Reply from 192.168.1.254: Destination Net Unreachable.


Four steps to test an IP connection with ping:

  1. Ping the loopback address to verify that TCP/IP is installed and configured correctly on the local computer.
    PING 127.0.0.1
  2. Ping the IP address of the local computer to verify that it was added to the network correctly.
    PING IP_address_of_local_host
  3. Ping the IP address of the default gateway to verify that the default gateway is functioning and that you can communicate with a local host on the local network.
    PING IP_address_of_default_gateway
  4. Ping the IP address of a remote host to verify that you can communicate through a router.
    PING IP_address_of_remote_host

TRACERT

Trace Route - TRACERT is useful for troubleshooting large networks where several paths can be taken to arrive at the same point, or where many intermediate systems (routers or bridges) are involved. This diagnostic tool determines the path taken to a destination by sending ICMP Echo Request messages with varying Time to Live (TTL) values to the destination.

Syntax

     TRACERT [options] target_name

Key

  target_name     The HTTP or UNC name of the host

Options:

-d        Do not resolve addresses to hostnames.
               (avoids performing a DNS lookup)
-h max_hops    Maximum number of hops to search for target.(default=30)
-j host-list   Trace route along given host-list. 
               up to 9 hosts in dotted decimal notation, separated by spaces.
-w timeout     Wait timeout milliseconds for each reply.


TTL (Time to Live) calculation TTL is effectively a count of the (maximum) number of links to the destination host. Each router along the path decrements the TTL in an IP packet by at least 1 before forwarding it.

When the TTL on a packet reaches 0, the router is expected to return an ICMP Time Exceeded message to the source computer.

Tracert determines the path by sending the first Echo Request message with a TTL of 1 and incrementing the TTL by 1 on each subsequent transmission until either the target host responds or the maximum number of hops is reached.

This process relys on intermediate routers to return ICMP Time Exceeded messages. However, some routers do not return Time Exceeded messages for packets with expired TTL values and are invisible to the tracert command. In this case, a row of asterisks (*) is displayed for that hop.


Examples

TRACERT www.ctwug.za.net
TRACERT 172.18.1.1

NSLOOKUP

Lookup IP addresses on a NameServer. This is usefull if you have an ip address and want to find the hostname(a name linked to that ip that has been configured on the DNS Server.

Syntax

Lookup the ip address of MyHost:                NSLOOKUP [-option] MyHost
  
Lookup ip address of MyHost on MyNameServer:    NSLOOKUP [-option] MyHost MyNameServer

Example:

C:\> nslookup www.ctwug.za.net

ROUTE

Manipulate network routing tables. Route packets of network traffic from one subnet to another by modifying the route table.

Syntax

Display route details:     ROUTE PRINT 

Add a route:               ROUTE [-p] ADD [destination_host] [MASK subnet_mask_value] [gateway] 

Change a route:            ROUTE [-f] CHANGE [destination_host] [MASK subnet_mask_value] [gateway] 

Delete a route:            ROUTE [-f] DELETE [destination_host] [MASK subnet_mask_value] [gateway] 
      

Options:

-f                         Clear (flush) the routing tables of all gateway entries.  
                           If this is used in conjunction with one of the commands, the tables are cleared prior to running the command.
destination_host           The address (or set of addresses) that you want to reach.
-p                         Create a persistent route - survives system reboots.
subnet_mask_value          The subnet mask value for this route entry. 
                           This defines how many addresses are there.
                           If not specified, it defaults to 255.255.255.255.
gateway                    The gateway.


  • Note that routes added to the table are not made persistent unless the -p switch is specified. Non-persistent routes only last until the computer is rebooted.
  • An IP address mask of 0.0.0.0 means everything. (rather like the *.* wildcard). In other words it says: When matching this pattern, don't worry about matching any of the bits - everything matches.

Example

  • Your ip range is 172.18.10.0/29
  • Your DEFAULT GATEWAY (gateway to your internet modem) is 172.18.10.1
  • Your router connecting you to CTWUG (aka your RB or Routerboard) ip is 172.18.10.6
  • You want your internet traffic to go via your DEFAULT GATEWAY (172.18.10.1) and your WUG TRAFFIC to go vir your RB (172.18.10.6)
  • The CTWUG network range is 172.18.0.0/16 and has a subnet mask of 255.255.0.0
route -p add 172.18.0.0 mask 255.255.0.0 172.18.10.6