Linux 101 : Routing, adding routes, checking routes - ip route -



Displaying the routes:

To check the routes and the interfaces our packets take when talking to a specific machine, we could use the below command for a host with the IP - 10.15.1.7 -:


The above results show that we would go to the host - 10.15.1.7 - via the gateway address - 10.1.1.1 - through the - eth0 - interface.

To communicate locally Linux uses the loopback address - lo - as we can see below:


Assigning an IP address to an interface:

To assign an IP address for example - 10.168.45.22 - with a netmask of - 24 - to the interface - eth0 -, we use the below command
:


Adding a route to the routing table:

The below command adds a route that instructs our IP address
 to go through the interface - eth1- and the gateway - 10.164.32.12 if there is a need to send any requests to any host in the following network -10.16.20.0/24 -:


We could check if  the routing table has been updated with the new entry using the below command:

Comments

Leave as a comment:

Archive