Linux: Route ip traffic through an interface

When setting up a subnet network, as with a VPN, you will want to route all IP traffic for that subnet.

If the interface for the subnet is called exampleIface and it is attached to IP address 10.1.1.21 where the subnet mask is FF:FF:FF:00, then to route all 10.1.1.x traffic through that interface use the command:

ip route add 10.1.1.0/24 dev exampleIface via 10.1.1.21

9 / 2024