
Layer 2 vs Layer 3 Switch in Practice: Inter-VLAN Routing and When to Replace the Router
Where inter-VLAN routing should live, when a Layer 3 switch can take over from a router, and when to use static routes or OSPF.
Every network with more than one VLAN needs something to route between them. Our guide to the Layer 2 vs Layer 3 switch difference explains what each type of switch is. This guide covers the decisions that come next: where inter-VLAN routing should happen, when a Layer 3 switch can take over from a router, and whether to route with static routes or a dynamic protocol.
Why do VLANs need a router at all?
A VLAN is a separate broadcast domain, and in practice each VLAN gets its own IP subnet. Switches keep VLANs apart by design, using the frame tagging defined in IEEE 802.1Q, so a laptop in the staff VLAN cannot reach a printer in the device VLAN without a Layer 3 hop. Cisco's inter-VLAN routing guide puts it plainly: devices in different VLANs sit on different subnets, so a routing device is needed, and it can be external or inside the switch chassis (Cisco).
What are the ways to route between VLANs?
- Router on a stick: one 802.1Q trunk to a router with a subinterface per VLAN. Cheap and simple, but every routed packet crosses the same link twice, so that link and the router's forwarding capacity cap throughput.
- Firewall as gateway: each VLAN's gateway lives on the firewall. Every inter-VLAN flow is inspected and logged, which is good for security and costly for heavy east-west traffic such as backups or file shares.
- Layer 3 switch with an SVI per VLAN: the switch holds the gateway address for each VLAN and routes in hardware at line rate. Fast and scalable, but traffic between those VLANs no longer passes the firewall unless you design for it.
Many networks mix them. Routine VLANs such as staff, voice and printers are routed on the core switch, while guest, camera, payment and management networks keep their gateway on the firewall, where policy is enforced.
How does inter-VLAN routing work on a Layer 3 switch?
You create a routed VLAN interface, usually called an SVI (switched virtual interface), for each VLAN and give it an IP address. Hosts in that VLAN use the address as their default gateway. On Cisco Catalyst switches IP routing must also be enabled globally; without it, the Cisco guide notes, the switch can operate as a pure Layer 2 device.
The switch then treats each VLAN subnet as a directly connected route. Add a default route (0.0.0.0/0) pointing at the edge router or firewall, so traffic for everything else, including the internet, leaves through it. Access control lists on the SVIs decide which VLANs may talk to which.
One warning: routing on the switch takes the firewall out of inter-VLAN paths. If a VLAN must stay isolated, keep its gateway on the firewall, or apply ACLs on the switch. On platforms that support it, a separate VRF keeps sensitive subnets in their own routing table.
When can a Layer 3 switch replace a router?
Inside the network it often can, and should. If your router's main job is acting as gateway for internal VLANs and linking floors or buildings over your own fiber, a Layer 3 switch does that with more ports, lower latency and far higher forwarding capacity.
At the edge it usually cannot. Edge devices translate addresses for internet access, track connections statefully, terminate site-to-site and remote-access VPNs, and sometimes carry WAN circuits or full internet routing tables that switch hardware is not built for.
- Replace with a Layer 3 switch: the router only routes between internal VLANs, or between sites on your own Ethernet links.
- Keep a router or firewall: you need NAT, VPN, stateful inspection, non-Ethernet WAN circuits or full internet routing tables.
- Use both: the firewall owns the internet edge and the sensitive VLANs, and the switch routes everything else.
Should you use static or dynamic routing?
Static routes are entries you type: send this subnet to that next hop. They are predictable and cost no protocol overhead. Cisco notes that for very small networks static routing can be simpler and easier to manage, needing fewer resources (Cisco). One core switch with a default route to the firewall is the classic static design.
Dynamic routing protocols let switches and routers learn routes from each other and recompute them when a link fails. OSPF, a link-state protocol designed to run within a single autonomous system (RFC 2328), is the usual choice on campus networks. Move to dynamic routing when you have two or more Layer 3 switches, redundant links between buildings, or more subnets than you want to maintain by hand.
If you mix the two, mind administrative distance. Cisco gives static routes a distance of 1 and OSPF 110, so a static route wins over OSPF for the same prefix unless you raise its distance. Raising it on purpose is how floating static backup routes work.
What should you check on a Layer 3 switch data sheet?
- Routing features in the license you are buying. Some platforms reserve OSPF, BGP or VRFs for a higher software tier, and some entry Layer 3 models support static routes only.
- Route table and host (ARP) table sizes against your subnet and device counts, with room to grow.
- The number of SVIs and VLANs supported.
- How forwarding memory is split. Some platforms divide table space between MAC, route and ACL entries using templates, so check the one you will run.
- First-hop redundancy such as VRRP, if two core switches will share gateway duty.
- Uplink ports, such as SFP+ or SFP28, and matching transceivers and cables.
What does this look like in a data center?
In a modern data center, routing moves all the way to the top of the rack. In a leaf-spine fabric each leaf switch is the gateway for the servers below it and routes to every spine over equal-cost paths, usually with BGP or OSPF. There is no router on a stick and no stretched VLANs, unless an overlay such as VXLAN provides Layer 2 where it is needed. Our leaf-spine switches page covers the hardware.
Nexus Compute supplies new Layer 3 switches and edge firewalls through authorized distribution, with the manufacturer warranty confirmed on your quote. Send your VLAN list, uplink speeds and current router model through request a quote, and we will check the routing features and licensing against your design before dispatch.
Frequently asked questions
Can a Layer 3 switch replace a router?
Inside the network, yes. A Layer 3 switch routes between VLANs and between buildings in hardware, at higher throughput than most routers. At the internet edge it usually cannot, because it lacks NAT, stateful firewalling and VPN functions. Most designs keep a router or firewall at the edge and route internal traffic on the core switch.
What is router on a stick?
Router on a stick is an inter-VLAN routing design in which one 802.1Q trunk connects a switch to a router, with a subinterface for each VLAN. Traffic between VLANs travels up the trunk to the router and back down. It is simple and inexpensive, but limited by that single link and the router's forwarding capacity.
What is an SVI on a switch?
An SVI, or switched virtual interface, is a virtual routed interface for a VLAN on a Layer 3 switch. Giving it an IP address makes the switch the default gateway for hosts in that VLAN. With IP routing enabled, the switch then routes between its SVIs in hardware.
Should I use static routes or OSPF?
Use static routes for small networks with one core switch and one exit, where routes rarely change. Use OSPF when there are several Layer 3 switches, redundant links or many subnets, because it updates routes automatically after a failure. Many networks combine both, such as OSPF internally and a static default route to the firewall.
Is inter-VLAN routing on a switch less secure?
It can be, because traffic routed between VLANs on the switch bypasses the firewall. Apply access control lists on the switch's VLAN interfaces, or keep sensitive VLANs such as guest, payment and management networks routed on the firewall, where flows are inspected and logged.
Sources
Figures in this article are attributed to the sources below, as reported on the dates cited. Prices and availability change quickly; confirm current figures before you buy.
- IEEE 802.1Q (standards.ieee.org)
- Cisco: Configure inter vlan routing with cataly (cisco.com)
- Cisco: Kmgmt3843 understanding ospf in catalyst 1300x switches (cisco.com)
- RFC 2328 (rfc-editor.org)
Systems covered in this article
Planning a hardware investment?
Tell us what you're trying to build. A procurement specialist will help you specify and quote the right configuration within 48 business hours, no obligation.
