After adding VLAN interfaces to my server, I discovered that using the interfaces independently (eg
curl --interface enp1s0.10 example.com) wouldn’t work. Because the default route on the system is via
enp1s0, the router drops the packet since the gateway for
enp1s0 has no route back to the source of the packet (at least I think that’s what’s happening ¯\_(ツ)_/¯). To make sure packets exit the system from the correct interface we need to add a new route table for each VLAN. We can do this using the
post-up commands after defining the interfaces in
An example VLAN interface might look like:
The interface gets its own route table (
table 10 for simplicity I’ve numbered these to match the VLAN tag). On that table we add a route to the
10.10.0.0/24 network from the
enp1s0.10 with source address
10.10.0.5, and set the default route via
10.10.0.1. We then add two rules to use this table for all packets to or from the interface’s address.
Once the interface is up we can now use the VLAN interfaces directly.
The new route table can be shown with:
And the routing rules with: