Configure Static Routes in CentOS

To configure static routes in CentOS, you can follow these steps:

  1. Open the terminal and login to the system with root privileges.
  2. Edit the network configuration file /etc/sysconfig/network-scripts/ifcfg-, where is your network interface name, such as eth0. You can use the command ifconfig to view the interface name.
  3. Add the following lines to the configuration file to set a static IP address and subnet mask:
  4. IPADDR=
    NETMASK=
  5. Replace and with the IP address and subnet mask you want to configure.
  6. Edit the routing configuration file /etc/sysconfig/network-scripts/route-, creating it if it does not already exist, where is the name of your network interface.
  7. Add the following line to the routing configuration file to configure a static route.
  8. Destination network via gateway on interface.
  9. Replace with the network address and subnet mask of the target network you want to add, with the gateway IP address of that target network, and with the name of the network interface.
  10. Save and exit the file.
  11. Restart the network service to apply the configuration.
  12. Restart the network using systemctl.

Once you have completed the above steps, your CentOS system will send packets based on the configured static routes. You can use the “ip route” command to verify if the static routes are correctly configured.

bannerAds