How to add routes in Linux and Windows

Source: Internet
Author: User
1. Add a route table
Route add 60.232.142.40 mask 255.255.255.248 192.168.100.250 Metric
3 if
2
Add a route record. All data packets destined for the 60.232.142.40/29 CIDR block go through the gateway of 192.168.100.250 through the interface card No. 2. The priority is 3. (What will happen ?)
Route
Add-P 60.232.142.40 mask 255.255.255.248 192.168.100.250 metric 3 if
2
It works the same as above, but it is a long-term route and will not be lost because of restarting the machine.

2. delete a route table
Route Delete
60.232.142.40
NOTE: If two route records have the same "destination network number", the two records will be deleted at the same time. If you only want to delete one of them, use Route
Add another one to the Add command.
From: http://whatislinux.net/how-to-add-a-static-ip-route-in-windows

3. modify a route record
Route
Change 157.0.0.0 mask 255.0.0.0 157.55.80.5 metric 2 if
2
The change parameter can only be changed to "Gateway" and "hop count" Linux to add route routes.

Adding a Linux route is very important for us. Sometimes the network is disconnected. Maybe you did not add or release the route. I hope it will help you!

Server IP (eth0)
[Root @ localhost
Net] # ifconfig
Eth0 link encap: Ethernet hwaddr
00: 0C: 29: E3: 9A: 15
Inet ADDR: 172.18.3.205 bcast: 172.18.3.255
Mask: 255.255.255.0
Inet6 ADDR: fe80: 20c: 29ff: fee3: 9a15/64
Scope: Link
Up broadcast running Multicast MTU: 1500 Metric: 1

RX packets: 4776 errors: 0 dropped: 0 overruns: 0 frame: 0
TX
Packets: 3348 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0
Txqueuelen: 1000
RX Bytes: 439384 (429.0 kib) TX Bytes: 390425 (381.2
Kib)
Interrupt: 11 base address: 0x1400
Lo link encap: Local
Loopback
Inet ADDR: 127.0.0.1 mask: 255.0.0.0
Inet6 ADDR:
: 1/128 scope: Host
Up loopback running MTU: 16436 Metric: 1

RX packets: 254 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 254
Errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0

RX Bytes: 22128 (21.6 kib) TX Bytes: 22128 (21.6 kib)



View original route information
[Root @ localhost net] # route-n
Kernel IP routing
Table
Destination gateway genmask flags metric ref use
Iface
172.18.3.0 0.0.0.0 255.255.255.0 u 0 0 0
Eth0
169.254.0.0 0.0.0.0 255.255.0.0 u 0 0 0 eth0

========================================================== ============================




Add Default Gateway
[Root @ localhost net] # route add default GW
172.18.3.50
[Root @ localhost net] # route
Kernel IP routing
Table
Destination gateway genmask flags metric ref use
Iface
172.18.3.0*255.255.255.0 u 0 0 0
Eth0
169.254.0.0*255.255.0.0 u 0 0 0
Eth0
Default 172.18.3.50 0.0.0.0 ug 0 0 0 eth0

========================================================== ====================



Add an IP address (eth0: 1)
[Root @ localhost net] # ifconfig eth0: 1
192.168.168.119 netmask 255.255.255.0 up
[Root @ localhost net] #
Ifconfig
Eth0 link encap: Ethernet hwaddr 00: 0C: 29: E3: 9A: 15

Inet ADDR: 172.18.3.205 bcast: 172.18.3.255 mask: 255.255.255.0
Inet6
ADDR: fe80: 20c: 29ff: fee3: 9a15/64 scope: Link
Up broadcast running
Multicast MTU: 1500 Metric: 1
RX packets: 5071 errors: 0 dropped: 0
Overruns: 0 frame: 0
TX packets: 3569 errors: 0 dropped: 0 overruns: 0
Carrier: 0
Collisions: 0 FIG: 1000
RX Bytes: 466532 (455.5
Kib) TX Bytes: 416538 (406.7 kib)
Interrupt: 11 base address: 0x1400

Eth0: 1 link encap: Ethernet hwaddr 00: 0C: 29: E3: 9A: 15
Inet
ADDR: 192.168.168.119 bcast: 192.168.168.255 mask: 255.255.255.0
Up
Broadcast running Multicast MTU: 1500 Metric: 1
Interrupt: 11 Base
Address: 0x1400
Lo link encap: local loopback
Inet
ADDR: 127.0.0.1 mask: 255.0.0.0
Inet6 ADDR: 1/128 scope: Host

Up loopback running MTU: 16436 Metric: 1
RX packets: 258 errors: 0
Dropped: 0 overruns: 0 frame: 0
TX packets: 258 errors: 0 dropped: 0
Overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX Bytes: 22480
(21.9 kib) TX Bytes: 22480 (21.9 kib)

View route information
[Root @ localhost
Net] # route-n
Kernel IP routing table
Destination Gateway
Genmask flags metric ref use iface
172.18.3.0 0.0.0.0
255.255.255.0 u 0 0 0 eth0
192.168.168.0 0.0.0.0
255.255.255.0 u 0 0 0 eth0
169.254.0.0 0.0.0.0
255.255.0.0 u 0 0 0 eth0
0.0.0.0 172.18.3.50
0.0.0.0 ug 0 0 0 eth0

========================================================== ======================================



Add a route entry to host 192.168.168.110 (via eth0: 1)
[Root @ localhost net] #
Route add-host 192.168.168.110 Dev eth0: 1
[Root @ localhost net] #
Route
Kernel IP routing table
Destination gateway genmask
Flags metric ref use iface
192.168.168.110*255.255.255.255 uh 0
0 0 eth0
172.18.3.0*255.255.255.0 u 0 0
0 eth0
192.168.168.0*255.255.255.0 u 0 0 0
Eth0
169.254.0.0*255.255.0.0 u 0 0 0
Eth0
Default 172.18.3.50 0.0.0.0 ug 0 0 0 eth0

========================================================== ======================================



Add a route entry to host 192.168.168.120 (via ip192.168.168.119)

[Root @ localhost net] # route add-host 192.168.168.120 GW
192.168.168.119
[Root @ localhost net] # route
Kernel IP routing
Table
Destination gateway genmask flags metric ref use
Iface
192.168.168.120 192.168.168.119 255.255.255.255 ugh 0 0
Eth0
192.168.168.110 * & nb

SP; 255.255.255.255 uh 0 0
0 eth0
172.18.3.0*255.255.255.0 u 0 0 0
Eth0
192.168.168.0*255.255.255.0 u 0 0 0
Eth0
169.254.0.0*255.255.0.0 u 0 0 0
Eth0
Default 172.18.3.50 0.0.0.0 ug 0 0 0 eth0

========================================================== ==============================

Route added to the network (via eth0)
[Root @ localhost net] # route add-net 192.168.3.0
Netmask 255.255.255.0 Dev eth0
[Root @ localhost net] # route
Kernel IP
Routing table
Destination gateway genmask flags metric ref
Use iface
192.168.168.120 192.168.168.119 255.255.255.255 ugh 0 0
Eth0
192.168.168.110*255.255.255.255.255 uh 0 0 0
Eth0
192.168.3.0*255.255.255.0 u 0 0 0
Eth0
172.18.3.0*255.255.255.0 u 0 0 0
Eth0
192.168.168.0*255.255.255.0 u 0 0 0
Eth0
169.254.0.0*255.255.0.0 u 0 0 0
Eth0
Default 172.18.3.50 0.0.0.0 ug 0 0 0 eth0


Route entry added to the network (via ip172.18.3.50)
[Root @ localhost net] # route add-Net
192.168.4.0 netmask 255.255.255.0 GW 172.18.3.50
[Root @ localhost net] #
Route
Kernel IP routing table
Destination gateway genmask
Flags metric ref use iface
192.168.168.120 192.168.168.119 255.255.255.255
Ugh 0 0 0 eth0
192.168.168.110*255.255.255.255 uh 0
0 0 eth0
192.168.4.0 172.18.3.50 255.255.255.0 ug 0 0
0 eth0
192.168.3.0*255.255.255.0 u 0 0 0
Eth0
172.18.3.0*255.255.255.0 u 0 0 0
Eth0
192.168.168.0*255.255.255.0 u 0 0 0
Eth0
169.254.0.0*255.255.0.0 u 0 0 0
Eth0
Default 172.18.3.50 0.0.0.0 ug 0 0 0 eth0

========================================================== ====================================

Parameter differences-host and Host IP,-net and network number

========================================================== ====================================


The meaning of each field in the output result is:

Destination indicates the destination IP address of the route

Gateway indicates the host name or IP address used by the gateway. The output "*" indicates that no gateway exists.
Genmask indicates the network mask of the route

Flags indicates a route entry. The available flag indicates that the route is starting. h indicates that the target is a host, G indicates that the gateway is used, r indicates that the dynamic route is reset. D indicates that the route is dynamically installed, M indicates modifying the route ,! Indicates that the route is denied.

Metric indicates the sales volume of the route.
Ref indicates the number of other routes that depend on the current status of the current route.
Use indicates the number of route table entries used.

Iface indicates the destination network for the packet sent by the route to be transferred from: http://lzhxiaoyu.blog.51cto.com/10707/291323

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.