How to set up the default route in Linux?

To set up the default route, you need to edit the network configuration file. In most Linux distributions, the network configuration file is located at /etc/network/interfaces or /etc/sysconfig/network-scripts/ifcfg-.

Here are the typical steps:

  1. Open the terminal and log in with root or sudo privileges.
  2. Locate the configuration file for the network interface you want to set as the default route. For example, if you want to set the default route for the eth0 interface, you will need to edit the /etc/network/interfaces file or the /etc/sysconfig/network-scripts/ifcfg-eth0 file.
  3. Open the file in a text editor and locate the line about routes. Here, you need to add or modify the value of the gateway or GATEWAY field to the IP address you want to set as the default route. For example, gateway 192.168.1.1.
  4. Save the file and close the editor.
  5. Restart the network service for the changes to take effect. Execute the following command in the terminal.
  6. For Debian/Ubuntu distributions: restart networking with sudo systemctl
  7. For Red Hat/CentOS distributions, restart the network service using “sudo systemctl restart network.”

In this way, you have set up the default route.

bannerAds