Linux – Change default router without network restart

linuxredhatrouting

I have an RHEL3 server on which I would like to change my default route. Every site I've seen that shows how to do this ends with doing "service network restart" or "/etc/init.d/network restart".

I've got applications running which I assume will not take kindly to having the ethernet interface restarted and I'm wondering if there's any less drastic to just remove the old route and add a new one without having to completely restart networking.

Best Answer

You can change your default route with 'ip' command. Before you read next - it's very likely that you'll lost connection to your server after using those commands. Be very careful. All changes with ip command are temporary (to next change, or reboot)

  • For help type:

ip route help

  • Example command to replace default gateway to IP:

ip route replace default via IP

  • Example command to remove default gateway and add IP:

ip route delete default

ip route add default via IP ...

  • You can also use device name:

ip route replace default dev ppp0