2

What's the difference between these two commands?

ip route add default gw 192.168.0.1
ip route add default via 192.168.0.1

I've seen both being used to solve the same problem, but don't understand the difference...

Basically, I wanted to know the difference between gw & via

TAbdiukov
  • 111
  • 4
JoBe
  • 276
  • 1
  • 3
  • 13

1 Answers1

3

Neither of those work. To set the default route, the syntax is:

ip route add default via <gateway IP> dev <interface>

There is no gw keyword according to the man page so I'm not sure who wrote those as answers.

  • So ip route add via 192.168.0.1 is the correct, and the usage of gw is old and obsolete? – JoBe Dec 16 '19 at 13:19
  • Sorta. The old tool used a different syntax but became unmaintained which is code for insecure and a PITA to update as protocols and the kernel change. So someone created the IP tool and it uses this newer syntax. You can check out the abstract grammar in the man page, its basically got its own language to control networking, for better or worse. –  Dec 20 '19 at 19:18