How to add a static route in Ubuntu?
To add a static route on an Ubuntu system, you can follow these steps:
- Open a terminal window and enter the following command to view the current system’s routing table information:
ip route
- Identify the destination network and gateway address for the static route you want to add, and then use the following command to add the static route:
sudo ip route add 目的网络/子网掩码 via 网关地址
For example, if you want to add a static route to route the destination network 192.168.1.0/24 through the gateway address 192.168.0.1, you can use the following command:
sudo ip route add 192.168.1.0/24 via 192.168.0.1
- To verify that the newly added static route has been successfully added, you can check the routing table information again using the following command.
ip route
In this way, you can add a static route on Ubuntu system. It is important to note that the static route added in this manner will be cleared after a system reboot. If you need to permanently save the static route, you can add the static route information to the network configuration file.