Junior — Middle
What methods and tools would you use to configure static routing in a Linux system?
sobes.tech AI
Answer from AI
To configure static routing in Linux, the following methods and tools are commonly used:
ip routecommand — allows adding, changing, or deleting routes in the current session:
sudo ip route add 192.168.2.0/24 via 192.168.1.1 dev eth0
routecommand — an older but still used tool:
sudo route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1
- Editing configuration files — to make routes persistent after reboot:
- In Debian/Ubuntu:
/etc/network/interfacesor files in/etc/network/interfaces.d/ - In RedHat/CentOS: files in
/etc/sysconfig/network-scripts/route-<interface>
-
Using system services — such as
NetworkManagerorsystemd-networkdfor managing routes through their configurations. -
Scripts and automation — adding commands to startup scripts or using Ansible, Puppet for configuration management.
In summary, ip route is suitable for quick setup, while editing configuration files or using system network managers is better for persistent configuration.