On Linux, change the default gateway using the route command without having to restart the network.

In a Linux system, the route command can be used to modify the default gateway without the need to restart the network.

Here are the steps to modify the default gateway using the route command:

  1. Open the terminal window and log in as a root user or a user with sudo privileges.
  2. View the current routing table information using the following command:
route -n
  1. Locate the line for the current default gateway, usually with a destination address of 0.0.0.0 and the gateway address being the IP address of the current default gateway.
  2. Delete the current default gateway using the following command.
route del default gw <当前默认网关的IP地址>
  1. Use the following command to add a new default gateway:
route add default gw <新的默认网关的IP地址>
  1. Use the following command to check the routing table information again to confirm that the default gateway has been successfully changed:
route -n

After completing the above steps, you have successfully used the route command to modify the default gateway, and the changes will take effect without needing to restart the network.

bannerAds