networking:routing
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| networking:routing [2023/09/16 09:34] – created oscar | networking:routing [2023/09/16 11:13] (current) – oscar | ||
|---|---|---|---|
| Line 45: | Line 45: | ||
| * Priority: 32766, Selector: match anything, Action: lookup routing table main (ID 254). The main table is the normal routing table containing all non-policy routes. This rule may be deleted and/or overrid‐ den with other ones by the administrator. | * Priority: 32766, Selector: match anything, Action: lookup routing table main (ID 254). The main table is the normal routing table containing all non-policy routes. This rule may be deleted and/or overrid‐ den with other ones by the administrator. | ||
| * Priority: 32767, Selector: match anything, Action: lookup routing table default (ID 253). The default table is empty. It is reserved for some post-processing if no previous default rules selected the packet. This rule may also be deleted | * Priority: 32767, Selector: match anything, Action: lookup routing table default (ID 253). The default table is empty. It is reserved for some post-processing if no previous default rules selected the packet. This rule may also be deleted | ||
| + | ===== Show routing ===== | ||
| + | The following commands can be used to show the routing tables. They have exact the same output: | ||
| + | |||
| + | # ip route show | ||
| + | # ip route list | ||
| + | # ip route list table main | ||
| + | < | ||
| + | # ip route show | ||
| + | --------------- | ||
| + | default via 192.168.178.1 dev enp1s0 proto dhcp src 192.168.178.243 metric 100 | ||
| + | 169.254.0.0/ | ||
| + | 192.168.178.0/ | ||
| + | </ | ||
| + | Each entry is nothing but an entry in the routing table (Linux kernel routing table). For example, the following line represents the route for the local network. All network packets to a system in the same network are sent directly through the device enp1s0: | ||
| + | | ||
| + | Our default route is set via enp1s0 interface i.e. all network packets that cannot be sent according to the previous entries of the routing table are sent through the gateway defined in this entry i.e 192.168.178.1 is our default gateway. | ||
| + | |||
| + | ===== Show network interfaces ===== | ||
| + | Here is how to list all network interfaces on your Linux machine: | ||
| + | < | ||
| + | # ip link show | ||
| + | -------------- | ||
| + | 1: lo: < | ||
| + | link/ | ||
| + | 2: enp1s0: < | ||
| + | link/ether 30: | ||
| + | 3: wlp2s0: < | ||
| + | link/ether 8e: | ||
| + | </ | ||
| + | |||
| + | ===== Add a route ===== | ||
| + | An route can be added by: | ||
| + | # ip route add < | ||
| + | |||
| + | Where ip route add takes the following options: | ||
| + | |||
| + | * **< | ||
| + | * **< | ||
| + | * **< | ||
| + | * **< | ||
| + | |||
| + | Let us see some examples. Open the terminal app under Linux and type the following command to sent all packets to the local network 192.168.1.0 directly through the device eth0:, enter: | ||
| + | # ip route add 192.168.1.0/ | ||
| + | |||
| + | In this example route traffic via 192.168.2.254 gateway for 192.168.2.0/ | ||
| + | # ip route add 192.168.2.0/ | ||
| + | |||
| + | In other words, the above command will add a static route to the network 192.168.2.0/ | ||
| + | |||
| + | ===== Set default route ===== | ||
| + | All network packets that cannot be sent according to the previous entries of the routing table are sent through the following default gateway: | ||
| + | # ip route add default via 192.168.1.254 | ||
| + | |||
| + | ===== Delete route ===== | ||
| + | Type the following command to delete route: | ||
| + | # ip route delete 192.168.1.0/ | ||
| + | |||
| + | Let us delete default route too: | ||
| + | # ip route delete default | ||
| + | |||
| + | ===== Check Route ===== | ||
| + | You can also use ip command to find the route to the IP address. The following command will show the interface, metric, and gateway that is used to reach the IP address named 1.1.1.1 and 10.83.200.242: | ||
| + | < | ||
| + | # ip route get 10.83.200.242 | ||
| + | ---------------------------- | ||
| + | 10.83.200.242 via 192.168.178.1 dev enp1s0 src 192.168.178.243 uid 0 | ||
| + | cache | ||
| + | </ | ||
| + | This output shows that the interface enp1s0 used to reach the IP address 10.83.200.242, | ||
networking/routing.1694856845.txt.gz · Last modified: by oscar
