What is the problem if you define a route of last resort instead of default gateway on layer two devices?
ip default-gateway 10.10.10.254
ip route 0.0.0.0 0.0.0.0 10.10.10.254
Why we need to define that on layer two device? It works without gateway right?
A layer 2 device (such as a switch without layer 3 routing capabilities) behaves like a standard IP host. You, therefore, have to specify a default gateway so that it knows where to send packets destined for hosts not located on the subnet to which the device belongs.
Basically both commands do the same thing.
Without a default-gateway your Vlan interface, by default Vlan1 can not communicate with devices outside of his local subnet.
For instance if I have a NMS that resided on a subnet different than that from Vlan1 you need a router to forward packets to and from the NMS subnet.
* Please rate posts.
the 'ip default-gateway' command is necessary if you need to communicate with the switch from another network. Let's say you are in subnet 192.168.1.0/24, and the switch IP address is 192.168.2.0/24, then, without that command, you would not be able to communicate with the switch. When your switch is configured to route with IP, which effectively would make it a Layer 3 switch, it would not need to have a default gateway set, that is when you could use the 'ip route' command.
Does that make sense ?
Well both commands have similar effects
we need to define this command if you need to send traffic to other networks or subnets other then your own subnet of switch.
To send traffic to your subnet you dont need both these commands on the layer 2 switch.
Hope this answers your query.
Feel free to ask any Questions
Thank you all for the answers.
I am agree that ip route is a last resort for layer 3 devices running ip routing protocols, default-gateway is for layer two, but i found catalyst 4500 series configured with two or three vlans and not default gateway defined, instead they have ip route 0.0.0.0 0.0.0.0 10.10.10.254 and i can communicate with them, but they are not running any routing protocol. They have native vlan to communicate each other cat devices and in that vlan we have layer three devices to route the packets for vlans. Maybe the performance is affected but not the communication because is running anyway with that configuration!