 Let's take a look at the routing tables inside Linux and we'll use the command route to view the routing tables and to edit the routing tables So route on its own Shows the routing table for the current machine So I'm running on my client at the moment I run the route command and it shows me my routing table and the table in this case has three rows or three entries into it And we'll explain that in a moment First thing with a lot of the networking commands route and others They will show the results in a try to be a human-friendly form versus the the raw form and the human-friendly form Often will convert attempt to convert IP addresses to domain names and maybe present a a simple Name rather than the actual IP address And that's okay sometimes, but generally when I'm looking at the network setup I'd like to see the raw IP addresses and With a lot of networking commands route Included if you add the minus n option It shows you the raw or the numeric values rather than the human-friendly values And if you understand enough about IP addresses, it's probably sufficient to look at the raw values So you'll often see I use the minus n option with some commands without Explanation it's not all commands route is one of them The difference being instead of writing default here the human-friendly name it gives this special all-zeros address and Here instead of star It's got another all-zeros address. So I'm going to use that minus n option. I'll do that again without minus n for my client it shows me a routing table and The two top two first columns are very useful. They say in order to reach some destination Send to some gateway or router gateway is another word for router So if I want to reach a particular destination, and it's usually not one destination, but a subnetwork Then send to a particular router The others are useful But those first two if you can understand then then that's maybe the most important the mass goes with the destination Then there's maybe some flags like whether the route is up and whether we use a gateway you and G some measure of The the cost of using that route how often it's used And he may be the other most important is at the end the interface that we use the reference is usually not used They describe further in the man page for route describes, of course the the commands in depth the options and give some examples and Describes the output to see the different flags inside so in our network setup It is like this. We have a client a Router and a server so across two different internal subnets both All three of those Linux VMs have a nap interface which connects to really virtual box Which then connects them out to the real internet. So let's have a look at the routing table for My client Three entries. What's the first one say this four zeros destination is a special special value Not with respect to IP networking but with respect to this route command. What it means in the destination column is that It's like star meaning matches any value so and And the way that routing tables are used is the the longest prefix match so the most The closest match of these three destinations will be the one that's taken You can often think of this is the default route if the others don't match then if it's all zeros here then it will match definitely So this is the default route saying if there's any destination which really doesn't match the next two Then send to a router 10.0.2.2 and using to face EMP zero s3 Which if we look at our network diagram From the client if we want to send to a destination, which doesn't match the next to which will come to Send to 10.0.2.2 Although it's not shown on this picture That is actually the special IP address that virtual box uses 10.0.2.2 You think is here. This is the virtual box internal route and use EMP zero s3 Let's look at the other two routes and then come back to that one and we'll see why it makes sense And we'll go to the bottom if we want to reach network one nine two one six eight one dot zero any one that starts with one nine two one six eight dot one and we know it's a Subnet a network address because this is the mass that goes with the destination Although it comes in the third column. I think it goes with the destination then send to No gateway I read this don't send to a router if we don't send to a router then we the only other options to send direct This is saying if there's anyone on one nine two one six eight one dot zero We don't need to send to a router. We can send to that Direct to them via the land because this is the same subnet as what we are on In our picture Network a is the network one nine two one six eight one dot zero The client and router are on that network That third routing table entry was saying anyone else on that same land We don't need to send to a router. We can send direct to them if there was another computer connected to network a one nine two one six eight one 53 The client would send direct to them not via router So there's no router or gateway in that case. That's what the all zeros mean in the gateway column Similar in the second entry anyone on ten zero two zero Send direct and this is using interface EMP zero s3 And this is really the network between the client and virtual box router Not shown here, but there's actually virtual box creates its own network for the Between that client and this router interface If you want to send send a ten zero two two, for example, send direct to them don't send via router And then we read the first row and think well if it doesn't match One nine two one six eight one dot zero and it doesn't match ten zero two zero Then it will match this meaning anyone else Anyone else send a ten zero two two Which is Our virtual box router would send to here and if the destination was the real IP address out on the internet Then the router would then forward it on to the real destination We have a bit of a problem We should have our network set up such that if client wants to send to one nine two one six eight two dot 22 it should send via our router And At this stage we don't have that route present in the client routing table It's been deleted. I'll add it in a moment to demonstrate how to add a route, but let's just look at the server and The server routing table. I'll just change the fonts A little bit larger This is the server. So from the other end point The server which is on the subnet one nine two one six eight two dot zero Network B It also is on this special subnet to a ten dot zero dot two dot zero and can send to the virtual box router at ten dot zero dot two dot two And the server should be able to reach the client on one nine two one six eight one dot zero Let's have a look at its routing table Starting from the bottom Is a good way to read this Because the routing table is not processed in order. It's based upon the longest match I'll look at the bottom one first to reach anyone on our subnet ten one nine two one six eight two dot zero Send direct that's the fourth row Send via s eight To reach anyone on ten zero two zero also send direct And send via s three The second row and the fourth row are really for matching If there's someone on network B send direct If there's someone on this special network between us and the virtual box router send direct And there shouldn't be anyone else there in our setup Except the virtual box router So that's the two directly attached subnets And we'll often see when we're directly attached to a particular subnet will have such a route The first or the third one now if anyone is on an one nine two one six eight Dot zero zero subnet send a one nine two one six eight two dot two Via s eight and messes via a gateway or a router How does that work? If the destination is a one nine two one six eight two dot Something they're of these four destinations the closest match is the fourth one And we'll send direct Even though one nine two one six eight two dot something matches the third one The fourth entry is the closest and that's how the routing table works. It uses the the longest matching prefix the closest value So if the destination is one nine two one six eight two dot something send direct If it was say one nine two one six eight one dot something Then the fourth one obviously doesn't match The third entry is the closest match and we'd send to the gateway two dot two And that's that entry is the one that allows our Server to know about getting to network a If we're at two dot twenty two the server and we want to send to say one dot eleven one nine two one six eight one dot eleven Then the destination one nine two one six eight one dot eleven matches The third row and it tells us to send to router one nine two one six eight two dot two Which is the router in the middle We would send our packet to the router the router would then do its look up and direct the packet on forward the packet onto the client So that's the routing table entry we need to reach that other subnet And that's what we we need to add an equivalent one to the client to get it to work And the first one is for any other destination Which is not a one nine two one six eight dot Anything and it's not ten dot zero dot two dot anything Anything else will send to the virtual box special router ten zero two two and that will go out to the internet in most cases our default route so What do we do to add a route to our client to get Our fourth entry is such that if the client Wants to reach one nine two one six eight two dot something network be We should send to the router one nine two one six eight one dot one Via interface en p zero s eight. We want to add a route route entry for that So let's do that for the client And to change the network configuration. We need to have admin rights. I'll use sudo We use the route command, but with some options. We want to add a route And The destination network one nine two one six eight dot two dot Zero Let's all right, and let's keep going and net mask of which is actually the the third Column in our table two five five two five five. What should it be? Let's go back to our Our desired setup, we're saying to reach one nine two six once one nine two one six eight One dot something so I've made a mistake already that and we're using a net mask of A slash 24 let's go back and fix my mistake. It's not Sorry, we're on the client. That is correct. Let's be clear here. We're on the client We want to reach network b one nine two one six eight two dot something then we Add the route to that destination network And the gateway is going to be one nine two one six eight one dot one So the net mask is a slash 24 And the gateway one nine two one six eight one dot one the router ip address And we say what interface do we use? What device enp zero s Eight and that is referring to from the client's perspective which interface is it's going to use to send by So let's have a look at that command To add a routing table entry we use route add destination network. That's the destination column one nine two one six eight two dot zero And the subnet mask two five five two five five two five five dot zero, which is the third column and the gateway one nine two one six eight one dot one and the device And we need password And we've added that and i'll use our routing table to show that that routing table entry is there So that's how to add a routing table entry If we compare our client and that should work And how can we test that works we can use p From our client and try to contact our server And we get a response So our communications is working suggesting our routing table is working well So we added this row here If we compare and it works fine. It's fine. Uh, if we compare it to the server the server was slightly different this row was to zero dot zero Let's go back and explain that and see the meaning of this We're saying from the client if we want to reach one dot zero send direct If we want to reach two dot zero send to one dot one for the internal networking A more general approach would be to say if we want to reach one dot zero send direct if we want to reach any other Subnet which starts with one nine two one six eight zero dot zero send to the router Now that's not necessary in this case. It Was included in the server to cover the case where if we extended beyond The server for example, we added network c over here or In the other direction a network d over this way Then the routing table entries would still work So that's why we see a slightly different routing table entry between server and client But both of them work in this simple internal network If we did want to delete at a particular entry It's almost the same as adding Use the same values But d here and it's gone and I'll add it back in so our network works So we can add and delete routing table entries To see more options on manipulating the routing table and viewing more details have a look at the man page for route And that allows you to do some basic configuration of your internal network So you have an internet with correct routing tables