What are the steps for configuring static routes in Linux?
The steps to configure static routes in a Linux system are as follows:
- Open the terminal and log in with administrator privileges (you can use the sudo or su command).
- Use the ‘route’ or ‘ip route’ command to check the routing table of the current system and confirm the current routing situation.
- To add a static route using the ip route add command, the syntax is: ip route add destination network/subnet mask via next hop IP address. For example, ip route add 192.168.1.0/24 via 192.168.0.1.
- To delete a static route, you can use the “ip route del” command with the syntax “ip route del
via “. For example: “ip route del 192.168.1.0/24 via 192.168.0.1”. - Use the “ip route” command to check the updated routing table and confirm whether the static routes have been correctly added or removed.
- Static routes configuration can be permanently saved using a configuration file, with the file path usually being /etc/sysconfig/network-scripts/route-eth0 (the exact path may vary depending on the system version).
Please note: Static routes are manually configured routes that need to be manually added and deleted, and they are lost after a system reboot. If you need permanent route configurations, consider using dynamic routing protocols.