How can I add a default gateway with the ip command, not the route command?

I want to set a default gateway using the ip route command, since I'm under the impression that ip is newer and preferred. If I'm not mistaken, ip is included in a minimal CentOS installation and not route.

What's the equivalent of route add default gw 192.168.1.254 eth0 using ip route add?


Solution 1:

Try ip route add default via <host> dev <dev>, e.g.:

ip route add default via 192.0.2.2 dev eth0

Or you can replace the existing default route:

ip route replace default via 192.0.2.1 dev eth0