How to add a default route in CentOS 7
To add a default route in CentOS 7, follow these steps:
- Open the terminal and log in as a root user or a user with sudo privileges.
- Use the following command to view the current network configuration information of the system:
ip route show
- Find the IP address of the default gateway (default route), usually it is 0.0.0.0 or default. For example, if the IP address of the default gateway is 192.168.1.1.
- Add default route using the following command:
ip route add default via 192.168.1.1
192.168.1.1 is the default gateway IP address.
- Check the system’s network configuration again using the following command to confirm if the default route has been successfully added.
ip route show
Now, you have successfully added the default route. Please note that this configuration will be lost after a system reboot. To ensure that the configuration persists after a reboot, you can add the above command to the GATEWAY option in the network configuration file (such as /etc/sysconfig/network-scripts/ifcfg-eth0).