About Linux's default gateway

  
                        Linux installed system IP, this should be the basic skills of the system administrator, but different network structures have different ip try, you know?
1. A network card situation
This is nothing to say, estimated the earth Everyone knows: address, netmask, gateway and then netwok restart, get it.
2. The situation of two network cards
1). The situation of a gateway
This situation is also simple, a network card is set to an ip, One of the network cards is not ok with the gateway. In this way, when the Internet is connected with the gateway, this machine can communicate with the network without the gateway. This situation is more common when using Linux as a router or proxy gateway.
2). The situation of two gateways
This situation is relatively complicated, complicated to two network cards are not set the default gateway :) This happens, the two network segments of this Linux connection are not A network segment! It is also possible to access other different network segments through the two network segments connected. In this case, no matter which side the gateway is set, it will affect the network segment connected to another network segment. This is what I want most today. The problem mentioned. In this case, if you want to connect multiple network segments, you must first set the correct ip on the correct network card, and the rest of the work is done to the route. Use the route command to connect to the Internet or think The gateway that is connected to the Internet is set as the default gateway, which solves one network segment. The other segment and all the network segments to which it is connected must be routed one by one. Example
Default Gateway:
route add default gw 224.224.224.224 eth0
Add route:
route add -net 192.168.115.0/24 gw 192.168.1.254 eth1
Students who have not learned routing knowledge may not understand the route is 啥To connect to the 115 segment, go to 1.254. This is because, when adding the route, specify the next hop, only specify the gateway connected to the machine:)
3). The situation of the three network cards
and The two cards are similar. If your demand is, a network segment is connected to the Internet through two different networks, and there is such a linux in the middle. Personally, it seems that there is no other than using iptables to divide different Internet networks according to different IP addresses. Solution:)
Divergent thinking: knowing why you still know why. For a gateway of two network cards, only set a network card with a gateway? Because Linux will automatically set the route for you! It will set the gateway you set to Default route. At this time, if you set up two gateways. Linux can help you randomly choose the default route, it may not be the one that can't access the Internet or the one you don't want. Then expand it. In fact, Linux is a complete router! It just Very low-key default cancellation routing function. If you are learning about routing, there are not so many routers, to do some advanced experiments, like ospf, pgp, etc., may wish to install a few more linux you will have unexpected surprises. Write When I feel that linux is very yellow and very violent, I suddenly want to show more of it. But if I don't want to run the question, I will leave it to the next one: Actually linux routing, my customer experience!
Copyright © Windows knowledge All Rights Reserved