Inter-VLAN routing moves IP traffic between VLANs. Use it when hosts in separate subnets need to communicate while keeping their Layer 2 broadcast domains apart.
A VLAN interface, also called a switch virtual interface (SVI), gives a VLAN a Layer 3 address. In this lab, hosts use that address as their default gateway, and the switch routes traffic to the other subnet.
See the VLAN guide for access ports and tagged trunks. This guide adds VLAN interface addresses, host gateways and checks for routed traffic.
About the Lab
This guide follows Humza Altaf’s GNS3 lab using community SONiC 202205. The original PDF is revision 1.0, dated 6 October 2023. The outputs below are from that lab, which has not been re-run for this page.
The original switch and host commands and ping results are preserved. Step 2 adds an IPv6 check, an address re-check and the save that the original guide recommends. Step 6 adds interface, route and forwarding checks. Step 7 corrects the instruction for S2 and adds checks on both switches, and Step 8 supplies the missing PC2, PC3 and PC4 commands. The hostname tip, the gateway and ARP checks and the extra pings are also additions. Summaries and excerpts are labeled where they appear.
Step 7 departs from the original guide on one point. The guide says to repeat S1’s configuration on S2, which would put the same two gateway addresses on both switches, so this page keeps both addresses on S1 and gives S2 only the Layer 2 configuration.
Lab Topology
Ethernet0 connects S1 to S2 and carries VLANs 100 and 200 tagged. Ethernet4 is untagged in VLAN 100, while Ethernet8 is untagged in VLAN 200 on each switch.
| Host | IP address | Default gateway | VLAN | Connected switch | Switch interface |
|---|---|---|---|---|---|
| PC1 | 192.168.100.2/24 | 192.168.100.1 | 100 | S1 | Ethernet4 |
| PC2 | 192.168.200.2/24 | 192.168.200.1 | 200 | S1 | Ethernet8 |
| PC3 | 192.168.100.3/24 | 192.168.100.1 | 100 | S2 | Ethernet4 |
| PC4 | 192.168.200.3/24 | 192.168.200.1 | 200 | S2 | Ethernet8 |
PC3 and PC4 reach the gateway addresses on S1 over the trunk, which carries both VLANs to S2.
| Switch | VLAN interface | Recorded address |
|---|---|---|
| S1 | Vlan100 | 192.168.100.1/24 |
| S1 | Vlan200 | 192.168.200.1/24 |
Use separate consoles for S1, S2 and all four hosts. Both switches boot with the hostname sonic. Run sudo config hostname S1 on S1 and sudo config hostname S2 on S2, then log out and log back in so that each prompt shows the new name. The save in Step 2 keeps the new name after a reboot. Ethernet12 appears in the mapping for reference and is not connected in this topology. Interface names are written without the space that the PDF table puts before the number.
| GNS3 interface | SONiC interface | Use in this lab |
|---|---|---|
| Ethernet0 | Ethernet0 | Tagged trunk between S1 and S2 |
| Ethernet1 | Ethernet4 | Untagged host connection in VLAN 100 |
| Ethernet2 | Ethernet8 | Untagged host connection in VLAN 200 |
| Ethernet3 | Ethernet12 | Unused |
Step 1. Check the Interfaces
Start on S1 and identify the trunk and both access ports. Ethernet0, Ethernet4 and Ethernet8 should be administratively and operationally up before testing traffic.
show interfaces statusHistorical output is summarized below with selected rows and columns from the screenshot. All three connected interfaces were up.
| Interface | Speed | MTU | Vlan | Oper | Admin |
|---|---|---|---|---|---|
| Ethernet0 | 1G | 9100 | routed | up | up |
| Ethernet4 | 1G | 9100 | routed | up | up |
| Ethernet8 | 1G | 9100 | routed | up | up |
Administrative status shows whether an interface is enabled. If its operational state is down, check the GNS3 link and the device at the other end.
In SONiC 202205, routed in the Vlan column means only that the port is neither a VLAN member nor a PortChannel member. It does not show whether the port has an address, and the addresses are checked in Step 2.
Step 2. Remove the Routed Port Addresses
The SONiC virtual switch first boots with the t1 sample configuration for its default Force10-S6000 hardware SKU, which gives each port a /31 address. SONiC 202205 will not add a port to a VLAN while it is still a routed interface, so check and remove the addresses first.
show ip interfacesOnly the three connected ports are included in this historical address summary. Other rows and columns in the screenshot are omitted.
| Interface | IPv4 address/mask |
|---|---|
| Ethernet0 | 10.0.0.0/31 |
| Ethernet4 | 10.0.0.2/31 |
| Ethernet8 | 10.0.0.4/31 |
The IPv6 check below is an addition to the PDF. Look for configured IPv6 addresses on the same three ports before continuing.
show ipv6 interfacesRemove the three IPv4 addresses with the original commands below. If your starting configuration differs, remove the addresses actually configured on those interfaces.
sudo config interface ip remove Ethernet0 10.0.0.0/31
sudo config interface ip remove Ethernet4 10.0.0.2/31
sudo config interface ip remove Ethernet8 10.0.0.4/31Remove any configured IPv6 address on these ports with the same config interface ip remove command. An automatic fe80:: link-local address that you did not configure can stay.
Save the configuration now. The original guide recommends saving after every two or three commands.
sudo config save -yRecheck the ports with the added block below. Ethernet0, Ethernet4 and Ethernet8 should no longer appear in show ip interfaces. In show ipv6 interfaces, they should show only an fe80:: link-local address or not appear at all. The t1 preset adds no IPv6 addresses, so this check matters only if the configuration has been changed.
show ip interfaces
show ipv6 interfacesStep 3. Create the VLANs
Check the VLAN table before creating VLANs 100 and 200. The historical display contains no VLAN rows.
show vlan briefCreate the two VLANs with the original commands. Their gateway addresses and member ports are configured in later steps.
sudo config vlan add 100
sudo config vlan add 200Step 4. Assign the Member Ports
Assign Ethernet4 to VLAN 100 untagged and Ethernet8 to VLAN 200 untagged. Add Ethernet0 to both as a tagged member for the trunk.
sudo config vlan member add -u 100 Ethernet4
sudo config vlan member add -u 200 Ethernet8
sudo config vlan member add 100 Ethernet0
sudo config vlan member add 200 Ethernet0
show vlan briefThe block above joins the member commands and the display command from two separate PDF screenshots. The recorded output is reproduced below.
+-----------+--------------+-----------+----------------+-------------+
| VLAN ID | IP Address | Ports | Port Tagging | Proxy ARP |
+===========+==============+===========+================+=============+
| 100 | | Ethernet0 | tagged | disabled |
| | | Ethernet4 | untagged | |
+-----------+--------------+-----------+----------------+-------------+
| 200 | | Ethernet0 | tagged | disabled |
| | | Ethernet8 | untagged | |
+-----------+--------------+-----------+----------------+-------------+Both address fields are blank at this stage. The VLANs have Layer 2 membership but no configured gateway addresses.
Step 5. Assign the Gateway Addresses
Add the gateway address to each VLAN interface on S1. These are the addresses the hosts will use for traffic outside their own subnet.
sudo config interface ip add Vlan100 192.168.100.1/24
sudo config interface ip add Vlan200 192.168.200.1/24Write the interface names as Vlan100 and Vlan200, exactly as in the commands. The original note says the name starts with a capital V, which is right, but its example VLAN100 fails. SONiC 202205 accepts only the exact prefix Vlan, so the command prints its usage text and stops with Error: 'interface_name' is not valid. Valid names [Ethernet/PortChannel/Vlan/Loopback].
In SONiC 202205, config interface ip add also creates the VLAN_INTERFACE entry for the VLAN, and orchagent turns that entry into a router interface in the default virtual router unless the entry names a VRF. The router interface uses the switch’s system MAC address, which is the address that hosts learn for their gateway.
Step 6. Check the VLAN Interfaces
Display the VLAN table after assigning the gateway addresses. S1’s recorded output is reproduced below.
show vlan brief+-----------+------------------+-----------+----------------+-------------+
| VLAN ID | IP Address | Ports | Port Tagging | Proxy ARP |
+===========+==================+===========+================+=============+
| 100 | 192.168.100.1/24 | Ethernet0 | tagged | disabled |
| | | Ethernet4 | untagged | |
+-----------+------------------+-----------+----------------+-------------+
| 200 | 192.168.200.1/24 | Ethernet0 | tagged | disabled |
| | | Ethernet8 | untagged | |
+-----------+------------------+-----------+----------------+-------------+Interface and route checks below are additions to the PDF. On S1, confirm both addresses and a connected route for each subnet before testing the hosts.
show ip interfaces
show ip routeThe PDF has no output for these commands. In show ip interfaces, Vlan100 and Vlan200 should show their addresses with up/up in the Admin/Oper column. In show ip route, each subnet should appear as a connected route, as in the illustration below, which leaves out the uptime.
C>* 192.168.100.0/24 is directly connected, Vlan100
C>* 192.168.200.0/24 is directly connected, Vlan200| Check | Expected interface | Expected address or prefix |
|---|---|---|
| VLAN interface address | Vlan100 | 192.168.100.1/24 |
| VLAN interface address | Vlan200 | 192.168.200.1/24 |
| Connected route | Vlan100 | 192.168.100.0/24 |
| Connected route | Vlan200 | 192.168.200.0/24 |
On the SONiC virtual switch, the Linux kernel forwards the lab traffic between the VLAN interfaces, so Linux IPv4 forwarding must be enabled. SONiC 202205 enables it at boot, and the added check below should print net.ipv4.ip_forward = 1.
sudo sysctl net.ipv4.ip_forwardOn a hardware switch, the ASIC routes the traffic, so this flag does not show how the switch forwards packets.
Step 7. Configure S2 for Layer 2 Only
The original guide says to repeat Steps 1 through 6 on S2. Repeat Steps 1 through 4 on S2 and skip Step 5, so that S2 has no VLAN interface addresses. S2 boots with the same t1 addresses as S1, so the Step 2 commands are the same.
Repeating Step 5 would give S2 the same two addresses as S1 in the same VLANs. Both switches would then answer ARP requests for 192.168.100.1 and 192.168.200.1, and each host would keep the MAC address of whichever switch it heard from first. The pings would still succeed, often with the request routed by one switch and the reply by the other, so the duplicate addresses would go unnoticed. With the addresses on S1 only, S1 routes for the hosts on both switches, because the trunk carries both VLANs to S2.
The original guide shows no output from S2, and the recorded pings would look the same with either configuration, because each path crosses the same number of routers in both, one between VLANs and none within a VLAN. Every recorded host address, gateway and ping result fits this correction.
Check both switches with the added commands below. On S1, show ip interfaces should list Vlan100 and Vlan200, and show ip route should list both subnets as directly connected. On S2, neither command should show them, and show vlan brief should show the same members as on S1 with a blank IP Address column.
show interfaces status
show vlan brief
show ip interfaces
show ip routeAfter Step 4, show interfaces status shows trunk for Ethernet0, Ethernet4 and Ethernet8, because SONiC 202205 prints trunk for any VLAN member. Use show vlan brief to check which ports are tagged and which are untagged.
Step 8. Configure the Hosts
Assign each host the address, prefix and gateway in the topology table. The original PC1 command and reply are reproduced below.
PC1> ip 192.168.100.2/24 192.168.100.1
Checking for duplicate address...
PC1 : 192.168.100.2 255.255.255.0 gateway 192.168.100.1PC1’s historical sh ip display below includes every field from the screenshot. Its gateway line confirms that the command set the intended gateway.
PC1> sh ip
NAME : PC1[1]
IP/MASK : 192.168.100.2/24
GATEWAY : 192.168.100.1
DNS :
MAC : 00:50:79:66:68:00
LPORT : 10010
RHOST:PORT : 127.0.0.1:10011
MTU : 1500Configure the other hosts with the added commands below, using the topology addresses. Each gateway belongs to the same /24 subnet as its host.
PC2> ip 192.168.200.2/24 192.168.200.1
PC3> ip 192.168.100.3/24 192.168.100.1
PC4> ip 192.168.200.3/24 192.168.200.1Run the original address-display command on each host. Compare both its prefix and gateway with the table before testing another VLAN.
show ipCheck the Gateways and ARP
Gateway pings are additions to the PDF. Test each one before attempting inter-VLAN traffic. PC1 and PC2 reach S1 directly, while PC3 and PC4 also cross S2 and the trunk, so a failure here points to an access port, VLAN membership or the trunk rather than to routing.
PC1> ping 192.168.100.1
PC2> ping 192.168.200.1
PC3> ping 192.168.100.1
PC4> ping 192.168.200.1After the gateway ping, run the added arp command in each VPCS console within two minutes, because VPCS keeps ARP entries for 120 seconds. Each line shows a MAC address, an IP address and the seconds left before the entry expires, and the gateway entry should show S1’s MAC address on all four hosts.
arpOn S1, the added command below prints that MAC address on its link/ether line.
ip link show Vlan100Vlan100 and Vlan200 use the same MAC address on S1. A different MAC address in a host’s gateway entry means another device answered ARP for the gateway.
Checking ARP on the switch is also an addition. On S1, which holds the gateway interfaces, inspect the host entries after generating traffic.
show arpIn show arp, the Iface column shows the member port where S1 learned each host’s MAC address, and the Vlan column shows the VLAN ID. PC1 should appear on Ethernet4 in VLAN 100 and PC2 on Ethernet8 in VLAN 200, while PC3 and PC4 should appear on Ethernet0 in VLANs 100 and 200. Those two entries show that S1 reaches the hosts on S2 over the trunk, while the gateway MAC address in each host’s arp output shows that S1 is their gateway. Missing entries call for checks of host addressing, link state and VLAN membership before changing routes.
Historical Ping Results
All three blocks below reproduce the original ping commands and replies. The reply times will vary in another run.
PC1 to PC4
PC1 to PC4 crosses from VLAN 100 to VLAN 200. All five replies have TTL 63. VPCS sends its replies with TTL 64, so one router lowered it by one on the way back.
PC1> ping 192.168.200.3
84 bytes from 192.168.200.3 icmp_seq=1 ttl=63 time=10.800 ms
84 bytes from 192.168.200.3 icmp_seq=2 ttl=63 time=2.539 ms
84 bytes from 192.168.200.3 icmp_seq=3 ttl=63 time=5.459 ms
84 bytes from 192.168.200.3 icmp_seq=4 ttl=63 time=5.335 ms
84 bytes from 192.168.200.3 icmp_seq=5 ttl=63 time=5.670 msPC1 to PC3
Within VLAN 100, PC1 pings PC3 without crossing into another subnet. Every reply in this block has TTL 64, so no router handled the replies.
PC1> ping 192.168.100.3
84 bytes from 192.168.100.3 icmp_seq=1 ttl=64 time=5.675 ms
84 bytes from 192.168.100.3 icmp_seq=2 ttl=64 time=5.430 ms
84 bytes from 192.168.100.3 icmp_seq=3 ttl=64 time=5.329 ms
84 bytes from 192.168.100.3 icmp_seq=4 ttl=64 time=5.341 ms
84 bytes from 192.168.100.3 icmp_seq=5 ttl=64 time=5.740 msPC4 to PC3
Traffic from PC4 to PC3 crosses from VLAN 200 to VLAN 100. The five replies carry TTL 63. With S1 as the only gateway, the request crosses the trunk from S2 to S1 in VLAN 200 and returns to S2 in VLAN 100, and the reply takes the same path in reverse.
PC4> ping 192.168.100.3
84 bytes from 192.168.100.3 icmp_seq=1 ttl=63 time=18.984 ms
84 bytes from 192.168.100.3 icmp_seq=2 ttl=63 time=7.371 ms
84 bytes from 192.168.100.3 icmp_seq=3 ttl=63 time=7.831 ms
84 bytes from 192.168.100.3 icmp_seq=4 ttl=63 time=9.281 ms
84 bytes from 192.168.100.3 icmp_seq=5 ttl=63 time=7.975 msAll three tests succeeded in the recorded lab. TTL 63 shows one routed hop, but not which switch routed it.
Confirm the Complete Configuration
Run these additional pings to test PC2’s same-VLAN and inter-VLAN connectivity, then the reverse of PC1 to PC4. No results for these commands are recorded in the PDF.
PC2> ping 192.168.200.3
PC2> ping 192.168.100.2
PC4> ping 192.168.100.2Confirm each host’s address and gateway, gateway ARP resolution and the switch’s connected routes alongside the ping results. The first ping should show TTL 64 and the other two TTL 63. The three recorded tests do not include PC2, so these pings complete the check.
Before Production Use
A hardware switch’s first configuration depends on its platform and image. Check show ip interfaces and show ipv6 interfaces before adding its ports to a VLAN.
In SONiC 202205, config vlan member add refuses a port that is still a routed interface and stops with an error such as Error: Ethernet0 is a router interface!. The port stops being a routed interface when its last IPv4 or IPv6 address is removed, which is why Step 2 checks both address families. It stays a routed interface even with no addresses if it is bound to a VRF or has IPv6 link-local-only mode enabled.
Proxy ARP is disabled in the recorded VLAN tables. In SONiC it makes a VLAN interface answer ARP requests for other hosts in its own subnet, which this routing test does not need.
Save the completed configuration on both switches. sudo config save -y writes the running configuration to /etc/sonic/config_db.json.
sudo config save -yReboot the switches in a test environment and repeat the address, route, ARP and connectivity checks.
This lab has one gateway for each VLAN, on S1, so traffic between the VLANs stops if S1 fails, and traffic between VLANs on S2 crosses the trunk twice. SONiC 202205 does not support VRRP. Its redundant gateway option is MCLAG, where both peers carry the same VLAN interface address and the standby peer takes the active peer’s MAC address. MCLAG needs the iccpd container, which community SONiC includes only in images built with INCLUDE_ICCPD=y, so check that the image has it before planning on MCLAG.
Check the supported platforms and feature support for your exact hardware and SONiC image. Community SONiC 202205 does not run spanning tree, so a second link between S1 and S2 in the same VLANs would create a Layer 2 loop. If you need several physical links between the switches, use the PortChannel guide.
The many benefits of SONiC, once exclusive to hyperscalers, are now within reach for enterprise clients. Contact our team of seasoned networking experts to learn why right now is a transformative time in the industry as we move closer to wider SONiC adoption.
Humza Altaf
Hardware Nation
Humza Altaf
Network Engineer
Humza is a network engineer at Hardware Nation Labs, where his enthusiasm for Open Networking drives his work. With a blend of deep expertise and innovative approaches, he tests and designs robust, scalable networks of the future. His practical experience includes configuring and deploying a range of protocols such as LACP, VLANs, MPLS, and VRRP. At his previous role, he was part of a SONiC testing team, further honing his skills in network setup and troubleshooting. Humza is also adept at network analysis with tools like Wireshark, enhancing his ability to manage complex network environments.