User Tools

Site Tools


networking:routing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
networking:routing [2023/09/16 09:52] – [Show routing] oscarnetworking:routing [2023/09/16 11:13] (current) oscar
Line 61: Line 61:
    192.168.178.0/24 dev enp1s0 proto kernel scope link src 192.168.178.243 metric 100     192.168.178.0/24 dev enp1s0 proto kernel scope link src 192.168.178.243 metric 100 
 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. 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:
 +<code>
 +# ip link show
 +--------------
 +1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
 +    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 +2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
 +    link/ether 30:1a:11:9a:a3:64 brd ff:ff:ff:ff:ff:ff
 +3: wlp2s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DORMANT group default qlen 1000
 +    link/ether 8e:57:51:ea:b6:70 brd ff:ff:ff:ff:ff:ff permaddr 30:35:a6:3b:78:0b
 +</code>
 +
 +===== Add a route =====
 +An route can be added by:
 +  # ip route add <network>/<netmask> via <gateway> dev <interface>
 +
 +Where ip route add takes the following options:
 +
 +  * **<network>** is the network that you want to add a route to.
 +  * **<netmask>** is the netmask for the network.
 +  * **<gateway>** is the static Linux gateway for the network defined by the <network>/<netmask>.
 +  * **<interface>** is the Linux interface that will be used to send packets to the network.
 +
 +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/24 dev eth0
 +
 +In this example route traffic via 192.168.2.254 gateway for 192.168.2.0/24 network:
 +  # ip route add 192.168.2.0/24 via 192.168.2.254 dev eth0
 +
 +In other words, the above command will add a static route to the network 192.168.2.0/24. The route will use the gateway 192.168.2.254 and the Linux network interface eth0.
 +
 +===== 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/24 dev eth0
 +
 +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:
 +<code>
 +# 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 
 +</code>
 +This output shows that the interface enp1s0 used to reach the IP address 10.83.200.242, the metric is 1000, and the gateway IP is 192.168.178.1. You can verify this using the following command assuming that netmask is /24 for 10.83.200.0 network:
 +
networking/routing.1694857969.txt.gz · Last modified: by oscar