Route command details and usage examples

Source: Internet
Author: User

1.   Use of the background requires access to two networks, one is the environment of the deployment environment, the environment is not on the outside network, the external network environment is likely to be a wireless network. If both are connected, it is likely that one side will not work, that is, outside the network or intranet, often need to use the cumbersome "Disable network connection", "Enable network connection" operation to the internal and external network switching, is very troublesome.   To solve this problem, you can use the route command to make both the internal and external network available.  2. The   Route Command Route command is a network command that displays and modifies entries in the local IP routing table. The syntax of the  route command is as follows:  route [-f] [-p] [command [Destination] [Mask Netmask] [Gateway] [metric metric]] [if Interface]] The commands commonly used by the route command are as follows:  1) route Delete: delete route; 2) route print: Print route destination;3) route add: Add route; 4) Route change: Changes an existing route.   General use of the route delete, route add, route print three commands to resolve all the functionality of the route.  2.1 Print routing information          Print routing information using the command: route print.  ===========================================================================interface List0x1  MS TCP Loopback interface0x2 4f D1  realtek rtl8168c (P)/8111c (p) pci-e Gigabit Ethernet NIC-Packet Scheduler miniport 0x50004 XX  wan (ppp/slip) interface====================================================================== ================================================================================active routes:network Destination        netmask          gateway       Interface metric          0.0.0.0          0.0.0.0   116.69.106.119 116.69.106.119       1          0.0.0.0          0.0.0.0    192.168.2.226    192.168.2.79       20&NB Sp   115.168.64.94 255.255.255.255   116.69.106.119 116.69.106.119       1    116.69.106.119 255.255.255.255        127.0.0.1       127.0.0.1       50  116.255.255.255 255.255.255.255   116.69.106.119 116.69.106.119       50      &N Bsp 127.0.0.0        255.0.0.0        127.0.0.1       127.0.0.1       1    &NBsp 192.168.2.0    255.255.255.0     192.168.2.79    192.168.2.79       20     192.168.2.79 255.255.255.255        127.0.0.1       127.0.0.1   &NBS P   20    192.168.2.255 255.255.255.255     192.168.2.79    192.168.2.79     &N Bsp 20        224.0.0.0        240.0.0.0     192.168.2.79    192.1 68.2.79       20        224.0.0.0        240.0.0.0   116.69.10 6.119 116.69.106.119       1 255.255.255.255 255.255.255.255   116.69.106.119 116.69.106.119 & nbsp     1 255.255.255.255 255.255.255.255     192.168.2.79    192.168.2.79     & nbsp 1Default Gateway:    116.69.106.119==================================================================== =======persisTent Routes: none The first column is the network destination address. Lists all the network segments that the router is connected to.   The second line of the Netmask column provides the subnet mask for the network segment itself, not the subnet mask of the network card that is connected to the network segment. This basically allows the router to determine the address class of the destination network.   The third column is the gateway. Once the router determines which destination network it wants to forward this packet to, the router will look at the list of gateways. The network Guan tells the router which IP address the packet should be forwarded to to reach the destination network. The   Fourth column interface column tells the router which NIC is connected to the appropriate destination network. Technically, the interface column tells the router only the IP address assigned to the NIC. The NIC connects the router to the destination network. However, the router is smart enough to know which physical NIC the address is bound to.   The fifth column is measurement. Measurement itself is a science. The smaller the value, the higher the confidence   The following is what each line of content represents: Network Destination      netmask           Gateway         Interface      metric  0.0.0.0                    0.0.0.0          116.69.106.119  116.69.106.119   &NB Sp  1      This means that the data sent to any segment of the network is sent to a default gateway via the native Interface 116.69.106.119:116.69.106.119, which has a management distance of 1, the administrative distance refers to the confidence of the information in the path selection process, the smaller the management distance, the higher the credibility.   Second line content: Network Destination      netmask          gateway     &NBSP ;   Interface      metric  0.0.0.0                    0.0.0.0          192.168.2 .226  192.168.2.79      20    This means that the data sent to any segment of the network is sent to the gateway 192.168.2.226 through the native interface 192.168.2.79, but because the row's administrative distance (Metric) is larger than the first row, that is, the second row has no confidence in the first row, so the first line of the gateway is selected by default.   Third line of content: Network Destination      netmask          gateway     &NBSP ;   Interface          metric  115.168.64.94           255.255.2 55.255    116.69.106.119 116.69.106.119       1  fourth line content: Network Destination     &N Bsp Netmask          gateway         Interface           Metric  116.69.106.119          255.255.255.255    127.0.0.1        127.0.0.1             50      means sending from your own hostTo their own host of the packet, if the use of their own host IP address, with the use of loopback address the same effect, through the same path is routed, that is, if I have their own site, I want to browse their own site, The input localhost in the IE geology column is the same as 116.69.106.119, although localhost is parsed to be 127.0.0.1.     Fifth line of content: Network Destination      netmask          gateway         Interface          metric  116.255.255.255          255.255.255.255    116.69.106.119 116.69.106.119       50    Here the destination address is a local broadcast address, the system for such a packet processing method is to put this machine 116. 69.106.119 as a gateway, send a local broadcast frame, this frame will be filtered by the router.    Sixth line of content: Network Destination      netmask          gateway   &NBSP ;     Interface          metric  127.0.0.0                   255.0.0.0          127.0.0.1       127.0.0.1     & nbsp     1 2.2 the command to delete the routing information is:  route Delete network destination address [mask][Subnet mask]    For example, to remove a network destination address of 192.168.2.0, the subnet mask is 255.255.255.0 route, available:  route Delete 192.168.2.0 mask 255.255.0.0    When you delete a route, you can also use fuzzy matching, such as when you want to delete all routes in the IP routing table that starts with 115:  route Delete 115* 2.3 add routing information           Add routing information using the following command:  route Add network Destination address mask subnet mask gateway [metric] [measured value]    For example, to add a route to the destination address of a 10.41.0.0 with a 255.255.0.0 subnet mask, a 10.27.0.1 gateway, and a measured value of 7, use the following command:  route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 Metric 73.   Application example   to debug the environment for example, need to access the intranet for debugging, the intranet address is 5.0.217.47. In addition to a wireless, you can sisu network automatically assigned a 192.168.2.110. Plug in the intranet network cable, and successfully connected Sisu network, at this time the intranet is through, but the external network connection is not on. Use the ipconfig and route print commands in the command window to print out the current information:  route print======================================================= ====================interface list0x1  ms TCP Loopback interface0x2 4f D1  realtek rtl8168c (P)/8111C (P) pci-e Gigabit Ethernet NIC-Packet Scheduler Miniport 0x3 2c E7 all  atheros ar5006x Wireless Network Adapter-Packet Scheduler Mini Port  ======================================================================================================================================================active Routes:Network Destination        netmask          gateway       Interface Me tric          0.0.0.0          0.0.0.0        5.0.21 7.1      5.0.217.47       10          0.0.0.0          0.0.0.0      192.168.1.1   192.168.1.110       25      &NBS P 5.0.217.0 255.255.255.192       5.0.217.47      5.0.217.47       10  &NB Sp    5.0.217.47 255.255.255.255        127.0.0.1       127.0.0.1       10    5.255.255.255 255.255.255.255       5.0.217.47      5.0.217.47       10        127.0.0.0        255.0.0.0        127.0.0.1       127 .0.0.1       1      192.168.1.0    255.255.255.0    192.168.1.110   192.168.1.110       25    192.168.1.110 255.255.255.255        127.0.0.1 &NB Sp     127.0.0.1       25    192.168.1.255 255.255.255.255    192.168.1.110 &nbs P 192.168.1.110       25        224.0.0.0        240.0.0.0   &NB Sp   5.0.217.47      5.0.217.47       10        224.0.0.0   &NBSP ;    240.0.0.0    192.168.1.110   192.168.1.110       25 255.255.255.255 255.255.255.255       5.0.217.47      5.0.217.47       1 255.255.255.25 5 255.255.255.255    192.168.1.110   192.168.1.110       1Default Gateway:       192.168.1.1= ==========================================================================persistent Routes: None  Ipconfig windows IP configurationethernet Adapter Local connection:        connection-specific DNS Suffix. :        IP address .....: 5.0.217.47        Subnet Mask .... .....: 255.255.255.192        Default Gateway ..... . : Ethernet Adapter Wireless network connection:        connection-specific DNS Suffix. :        IP address ....: 192.168.1.110        Subnet Mask. ......: 255.255.255.0        Default Gateway ...... . : 192.168.1.1 by the first line of the result of the route Print command can be seen, only so access to the external network, because the default is through the 5.0.217.1 intranet gateway out.   In order to achieve the need to simultaneously access the internal and external network, only need to delete 0.0.0.0 of the route, add two routes, 5The address at the beginning is routed through the 5.0.217.1 gateway, while the rest of the addresses are 192.168.1.110 out through the wireless gateway. Refer to the following:  route delete 0.0.0.0route add 0.0.0.0 mask 0.0.0.0 192.168.1.1route Add 5.0.0.0 mask 255.0.0.0 5.0.217.1  This When running the route print command, you can see the following results: Route print========================================================================== =interface list0x1  ms TCP Loopback interface0x2 xx 4f d1  realtek rtl8168c (P)/8111c (p) pci-e Gigabit E Thernet NIC-Packet Scheduler Miniport 0x3 2c E7  atheros ar5006x Wireless Network Adapter-Packet Scheduler miniport =============== =============================================================================================================== ========================active routes:network Destination        netmask          gateway       Interface metric          0.0.0.0          0.0.0.0      192.168.1.1   192.168.1.110       1      &NBSP   5.0.0.0        255.0.0.0        5.0.217.1      5.0.217.47 &N Bsp     1        5.0.217.0 255.255.255.192       5.0.217.47      5 .0.217.47       10       5.0.217.47 255.255.255.255        127.0.0. 1       127.0.0.1       10    5.255.255.255 255.255.255.255       5 .0.217.47      5.0.217.47       10        127.0.0.0        255.0.0.0        127.0.0.1       127.0.0.1       1    & nbsp 192.168.1.0    255.255.255.0    192.168.1.110   192.168.1.110       25  &nbs P 192.168.1.110 255.255.255.255        127.0.0.1       127.0.0.1       25& nbsp &nBsp 192.168.1.255 255.255.255.255    192.168.1.110   192.168.1.110       25        224.0.0.0        240.0.0.0       5.0.217.47      5.0.217.47 &nbs P     10        224.0.0.0        240.0.0.0    192.168.1.110 &nbs P 192.168.1.110       25 255.255.255.255 255.255.255.255       5.0.217.47     & nbsp;5.0.217.47       1 255.255.255.255 255.255.255.255    192.168.1.110   192.168.1.110       1Default Gateway:       192.168.1.1================================== =========================================persistent routes: none    Can see the default is through the wireless 192.168.1.110 out, at this time both inside and outside the network can be used at the same time  Note:Route Delete 0.0.0.0
route add 0.0.0.0 mask 0.0.0.0 192.168.1.1-p
route Add 5.0.0.0 mask 255.0.0.0 5.0.217.1-p


after these two commands add-P, perfect, or restart after the failure,, pro-test! Pro-Test!

Route command details and usage examples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.