Sobes.tech
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:

  1. ip route command — 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
  1. route command — an older but still used tool:
sudo route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1
  1. Editing configuration files — to make routes persistent after reboot:
  • In Debian/Ubuntu: /etc/network/interfaces or files in /etc/network/interfaces.d/
  • In RedHat/CentOS: files in /etc/sysconfig/network-scripts/route-<interface>
  1. Using system services — such as NetworkManager or systemd-networkd for managing routes through their configurations.

  2. 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.