Ubuntu Linux Add Static Route

To add a static route in Ubuntu Linux, you need to edit the /etc/network/interfaces file and add a line to define the static route.

For example, to add a static route for the network 192.168.1.0/24 via the gateway 192.168.2.1, you would add the following line to the /etc/network/interfaces file:

up route add -net 192.168.1.0/24 gw 192.168.2.1

This line is added in the interface configuration block for the network interface that you want to use as the source interface for the static route.

After adding the line, save the file and restart the networking service using the following command:

sudo service networking restart

You can verify that the static route has been added using the route command:

route -n

This will show the routing table and you should see the new static route listed.

Leave a Comment