Introduction
In this article, we will discuss routing traffic through different table interfaces, specifically focusing on the use of the wlan0 and wg0 interfaces. By default, traffic is routed through the wlan0 interface, while the wg0 interface is manually configured. We will cover the key concepts and subtitles related to this topic, providing a detailed context and explanation.
Understanding the Interfaces
The wlan0 interface is a wireless local area network (WLAN) interface that is used as the default interface for routing traffic. This interface is automatically configured by the system and does not require manual intervention. On the other hand, the wg0 interface is a WireGuard interface that is manually configured for use as a virtual private network (VPN) connection.
Configuring the Interfaces
To configure the wg0 interface, you will need to manually edit the WireGuard configuration file. This file contains the necessary settings for establishing a VPN connection, including the private and public keys, endpoint, and allowed IPs. Once the configuration file has been edited, you can bring up the wg0 interface using the following command:
sudo wg-quick up wg0
Routing Traffic through the Interfaces
To route traffic through the wg0 interface, you will need to modify the routing table. By default, traffic is routed through the wlan0 interface. However, you can create a new routing table that specifies the wg0 interface as the outgoing interface for all traffic. This can be done using the following command:
sudo ip rule add from all iif wg0 table 100
In this command, the from all option specifies that the rule applies to all traffic, while the iif wg0 option specifies that the incoming interface is the wg0 interface. The table 100 option specifies the routing table to use, which in this case is a new table that we will create.
Creating a New Routing Table
To create a new routing table, you will need to edit the /etc/iproute2/rt_tables file. This file contains a list of all routing tables on the system. To add a new table, you will need to add a line to this file that specifies the table number and the table name. For example, to add a new table with the number 100 and the name wg0, you can use the following command:
echo '100 wg0' >> /etc/iproute2/rt_tables
Once the new routing table has been added, you can specify the outgoing interface for the table using the following command:
sudo ip route add default via dev wg0 table wg0
In this command, the default via option specifies the default route for the table, while the dev wg0 option specifies the outgoing interface.
- The
wlan0interface is the default interface for routing traffic, while thewg0interface is a WireGuard interface that is manually configured. - To route traffic through the
wg0interface, you will need to modify the routing table using theip ruleandip routecommands. - To create a new routing table, you will need to edit the
/etc/iproute2/rt_tablesfile and specify the outgoing interface for the table using theip routecommand.