Routing Traffic from/to Web App through eth0 Instead of tun0 (VPN) on Debian
In some cases, you may need to route traffic coming to and going from a web app through eth0 instead of the default tun0 VPN connection on a Debian system. This article will provide a detailed explanation of how to accomplish this task.
Understanding the Basics
By default, Debian systems route all traffic through the tun0 interface when a VPN connection is established. However, there may be situations where you want to exclude certain traffic from the VPN, such as traffic to and from a specific web app. To do this, you need to modify the routing table on your Debian system.
Checking the Current Routing Table
Before making any changes, it's a good idea to check the current routing table. You can do this by running the following command:
# ip route
This will display a list of all the current routes on your system. Take note of the default route, which is usually the last entry in the list.
Adding a New Route
To add a new route that sends traffic to and from your web app through eth0 instead of tun0, you need to use the ip route command again. The syntax for adding a new route is as follows:
# ip route add [destination] via [gateway] dev [interface]
In this case, the destination would be the IP address of your web app, the gateway would be the IP address of your default gateway, and the interface would be eth0. For example, if your web app has an IP address of 192.168.1.100, your default gateway has an IP address of 192.168.1.1, and your eth0 interface has an IP address of 192.168.1.2, the command would look like this:
# ip route add 192.168.1.100/32 via 192.168.1.1 dev eth0
This command adds a new route that sends all traffic to and from the IP address 192.168.1.100 through the eth0 interface instead of the tun0 interface.
Verifying the New Route
To verify that the new route has been added correctly, you can run the ip route command again. The new route should be listed in the output.
Removing the New Route
If you need to remove the new route for any reason, you can use the ip route del command. The syntax for removing a route is similar to adding a route, but with the del keyword instead of add. For example, to remove the route we added earlier, you would use the following command:
# ip route del 192.168.1.100/32 via 192.168.1.1 dev eth0
Routing traffic from/to a web app through eth0 instead of tun0 on a Debian system is a straightforward process that involves modifying the routing table. By adding a new route that sends traffic to and from the web app through eth0, you can exclude that traffic from the VPN connection. Remember to verify the new route and remove it when it's no longer needed.
References
- Debian Handbook: IP routing
- Arch Linux Wiki: IP routing
- Red Hat Documentation: Basic configuration of IPv4 routing