How to specify network cards when adding routes in Linux?

To add a route and specify the network interface in Linux, you can use the following command:

  1. Firstly, use the “ip route” command to view the current routing table and identify the suitable position to add your route.
  2. To add a route using the ip route add command, for example, if you want to add a route with a gateway of 192.168.1.1, a target network of 10.0.0.0/24, and specify the network interface as eth0, you can use the following command:
sudo ip route add 10.0.0.0/24 via 192.168.1.1 dev eth0

This will add a route in the routing table with the destination of 10.0.0.0/24, the gateway of 192.168.1.1, and data will be sent through the eth0 network interface.

  1. router configuration for network routing

Note: These commands require root privileges or the use of sudo to execute.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds