Multiple Subnets
Jump to navigation
Jump to search
If a user wishes to use more than one subnet on a VPS, they will need specific routes set up. This is because you can only have one default gateway and packets with a source IP from the second subnet will attempt to be sent through this default gateway, which is invalid.
If we assume that this VPS is on subnets on 109.169.0.0/25 and 109.169.23.0/24, where the default gateway is setup to be 109.169.23.1, we can do the following to get 109.169.23.0/24 to work:
- Add a new route table to /etc/iproute2/rt_tables. This can be called 100 twentythree
- ip rule add from 109.169.23.0/24 table twentythree
- ip route add default via 109.169.23.1 table twentythree
Put the ip commands in /etc/rc.local to make these changes persistent.