We talked about routing during the network basics. The two hosts must have routes to connect to the TCP/IP protocol. Otherwise, the connection will fail!
Generally, as long as there is a network interface, this interface will generate a route. For example, the host in the bird's brother lab has an eth0 and lo, so:
[Root @ override top40 Desktop] # route [-nee]
[Root @ brief top40 Desktop] # route add [-net |-host] [domain or host] netmask [mask] [gw | dev]
[Root @ brief top40 Desktop] # route del [-net |-host] [domain or host] netmask [mask] [gw | dev]
Observed parameters:
-N: Do not use communication protocols or host names. use IP addresses or port numbers directly;
-Ee: use more detailed information to display
Add and delete (del) Route parameters:
-Net: indicates that the followed route is a domain;
-Host: The route connecting to a single host;
Netmask: Related to the domain. You can set netmask to determine the domain size;
Gw: Short for gateway, followed by the IP value, which is different from dev;
Dev: If you only want to specify the network card to connect, use this setting, followed by eth0, etc.
Example 1: simply observe the Routing Status
[Root @ brief top40 Desktop] # route-n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.10.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 192.168.10.30 0.0.0.0 UG 0 0 0 eth0
[Root @ brief top40 Desktop] # route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.10.0*255.255.255.0 U 0 0 0 eth0
169.254.0.0*255.255.0.0 U 0 0 0 eth0
Default server. cluster 0.0.0.0 UG 0 0 0 eth0
Observe the output results of route and route-n carefully in the above example. You can find that the parameter-n is mainly used to display IP addresses, the host name is displayed! That is to say, under the preset circumstances, the route will find the host name of the IP address. What if it cannot be found? It will show blunt (a little slow), so laruence usually uses route-n directly! As shown above, we also know default = 0.0.0.0/0.0.0.0. What do you need to know about the above information?
· Destination and Genmask: the two are network and netmask respectively! So these two domain names are combined to form a complete domain name!
· Gateway: Which gateway is used to connect the domain? If 0.0.0.0 is displayed, the route is directly transmitted by the local machine, that is, the route can be directly transmitted through the MAC address of the regional network. If an IP address is displayed, the route needs to pass through the router (Communication gate) can be sent out.
· Flags: there are multiple flag in total, which indicates the following significance:
O U (route is up): the route is started;
O H (target is a host): the target is a host (IP) rather than a domain;
O G (use gateway): packets need to be transmitted through an external host (gateway;
O R (reinstate route for dynamic routing): restores the flag of route information when dynamic routing is used;
O D (dynamically installed by daemon or redirect)
O M (modified from routing daemon or redirect): The route has been modified;
O! (Reject route): this route will not be accepted (used to resist insecure domains !)
· Iface: the interface for passing packets through this route.
In addition, observe the preceding route arrangement order, which is from small domains (192.168.10.0/24 is Class C) in sequence to large domains (169.254.0.0/16 Class B) the default route is 0.0.0.0/0.0.0.0 ). Then, when we want to determine how a network packet should be transmitted, the packet will be determined through this routing process! For example, I have only three routes in the header. If I want to transmit a packet to 192.168.10.20, I will first find the route for the domain name 192.168.10.0/24! So it is directly transmitted by eth0. What if it is sent to the Yahoo host? The IP address of the Yahoo host is 202.43.195.52.
1) Not 192.168.10.0/24,
2) The result is not 169.254.0.0/16.
3) When 0/0, OK! The packets are sent to the gateway host 192.168.10.30 through eth0! Therefore, routes are sequential. So when you repeatedly set multiple identical routes, for example, when two network cards on your host are set to IP addresses of the same domain, what will happen? The following situations may occur:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
That is to say, because the routes are arranged and transmitted in order, no matter which interface (eth0, eth1) receives the packets, the preceding eth0 will be transmitted, setting two IP addresses of the same domain on a host is meaningless! A little more. This is necessary unless it is a multi-host set up similar to a virtual host (Xen, VMware, and other software ~
Example 2: add and delete a route
[Root @ override top40 Desktop] # route del-net 169.254.0.0 netmask 255.255.0.0 dev eth0
# The above action can delete the domain 169.254.0.0/16!
# Note: When deleting a route table, you must write all the information displayed on the route table.
# Including netmask and dev parameters! Note:
[Root @ shorttop40 Desktop] # route add-net 192.168.100.0 netmask 255.255.255.0 dev eth0
# Use route add to add a route! Note that this route must be able to communicate with you.
# For example, if I give the following command, an error will be displayed:
# Route add-net 192.168.200.0 netmask 255.255.255.0 gw 192.168.200.254
# Because my environment only has the IP address 192.168.10.100, it cannot be associated with 192.168.200.254
# This CIDR Block uses MAC to communicate with each other! In this case, you can understand it !?
[Root @ override top40 Desktop] # route add default gw 192.168.10.30
Added the default routing method! Note that only one preset route is enough! In this place, if you want to reset your network, remember to use the commands below to reset your network.
#/Etc/init. d/network restart
If you want to delete and add a route, you have to refer to the above example. In fact, the materials in man route are very rich! Take a closer look! When the error "SIOCADDRT: Network is unreachable" occurs, it must be because the IP address followed by gw cannot communicate directly with your domain (Gateway is not in your domain), so check whether the input is incorrect! Come on!
# Route entry added by the route command. After the machine is restarted or the NIC is restarted, the route entry will not be lost. in linux, set the permanent route:
1. Add in/etc/rc. local
2. Add to the end of/etc/sysconfig/network
3./etc/sysconfig/static-router:
Any net x. x/24 gw y. y