I have following config:
two interfaces eth0
connected via ISP1 and wlan0
connected via ISP2 to the internet. Both connections have different IP addresses and allow internet connectivity.
I setup two wireguard interfaces wg0
and wg1
. wg0
should always go via eth0
(which is default anyway), and wg1
should always go via wlan0
interface.
The problem that I have is that I use same remote server-peer (eg. peer wan ip 11.11.11.11
) to connect to both wg0
and wg1
at the same time. So, when packet arrives on wg1
it probably tries to send it back via eth0
instead of wlan0
. I tried to add static routing rules, but the thing is that I do not need to always route 11.11.11.11
via wlan0
, since if connection comes from eth0
it should also send it via eth0
.
Is there some way to say - connection to wg1
should always communicate via wlan0
?
Other solution that I can see is possible here (and not sure if it would work), is to setup link aggregation for eth0
and wlan0
, but I read that it is not possible to aggregate different physical connections? It would be the best if I could have then single wg0
interface available with whichever interface is up and running (eth0
or wlan0
).
This is current config:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 02:81:1e:50:c6:18 brd ff:ff:ff:ff:ff:ff
inet 192.168.100.200/24 brd 192.168.100.255 scope global eth0
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 0e:41:58:01:16:9e brd ff:ff:ff:ff:ff:ff
inet 192.168.0.134/24 brd 192.168.0.255 scope global wlan0
valid_lft forever preferred_lft forever
4: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
link/none
inet 10.9.0.1/24 scope global wg0
valid_lft forever preferred_lft forever
5: wg1: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
link/none
inet 10.9.1.1/24 scope global wg0-client
valid_lft forever preferred_lft forever
UPDATE
Adding the output of the command listed in the comments:
ip route
default via 192.168.100.1 dev eth0 onlink
10.9.0.0/24 dev wg0 proto kernel scope link src 10.9.0.1
10.9.1.0/24 dev wg1 proto kernel scope link src 10.9.1.1
192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.134
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.200
ip rule
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
ip route show table local
local 10.9.0.1 dev wg0 proto kernel scope host src 10.9.0.1
broadcast 10.9.0.255 dev wg0 proto kernel scope link src 10.9.0.1
local 10.9.1.1 dev wg1 proto kernel scope host src 10.9.1.1
broadcast 10.9.1.255 dev wg1 proto kernel scope link src 10.9.1.1
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1
local 192.168.0.134 dev wlan0 proto kernel scope host src 192.168.0.134
broadcast 192.168.0.255 dev wlan0 proto kernel scope link src 192.168.0.134
local 192.168.100.200 dev eth0 proto kernel scope host src 192.168.100.200
broadcast 192.168.100.255 dev eth0 proto kernel scope link src 192.168.100.200
ip route show table main
default via 192.168.100.1 dev eth0 onlink
10.9.0.0/24 dev wg0 proto kernel scope link src 10.9.0.1
10.9.1.0/24 dev wg1 proto kernel scope link src 10.9.1.1
192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.134
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.200
and wireguard configs:
wg0.conf
[Interface]
Address = 10.9.0.1/24
PrivateKey = xxx
ListenPort = 51820
PostUp = sysctl net.ipv4.conf.%i.forwarding=1 net.ipv4.conf.$(ip r l 0/0 | mawk '{print $5;exit}').forwarding=1
PostUp = sysctl net.ipv6.conf.$(ip r l 0/0 | mawk '{print $5;exit}').accept_ra=2
PostUp = sysctl net.ipv6.conf.%i.forwarding=1 net.ipv6.conf.$(ip r l 0/0 | mawk '{print $5;exit}').forwarding=1
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -s 10.9.0.0/24 -o $(ip r l 0/0 | mawk '{print $5;exit}') -j MASQUERADE
PostUp = ip6tables -A FORWARD -i %i -j ACCEPT; ip6tables -t nat -A POSTROUTING -o $(ip r l 0/0 | mawk '{print $5;exit}') -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -s 10.9.0.0/24 -o $(ip r l 0/0 | mawk '{print $5;exit}') -j MASQUERADE
PostDown = ip6tables -D FORWARD -i %i -j ACCEPT; ip6tables -t nat -D POSTROUTING -o $(ip r l 0/0 | mawk '{print $5;exit}') -j MASQUERADE
# Client 1
[Peer]
PublicKey = yyy
AllowedIPs = 10.9.0.2/32
wg1.conf
[Interface]
Address = 10.9.1.1/24
PrivateKey = zzz
PostUp = sysctl net.ipv4.conf.wg1.forwarding=1 net.ipv4.conf.wlan0.forwarding=1
PostUp = sysctl net.ipv6.conf.wlan0.accept_ra=2
PostUp = sysctl net.ipv6.conf.wg1.forwarding=1 net.ipv6.conf.wlan0.forwarding=1
PostUp = iptables -A FORWARD -i wg1 -j ACCEPT; iptables -t nat -A POSTROUTING -s 10.9.1.0/24 -o wlan0 -j MASQUERADE
PostUp = ip6tables -A FORWARD -i wg1 -j ACCEPT; ip6tables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
#PostUp = ip route add 11.11.11.11/32 via 192.168.0.1 dev wlan0
PostDown = iptables -D FORWARD -i wg1 -j ACCEPT; iptables -t nat -D POSTROUTING -s 10.9.1.0/24 -o wlan0 -j MASQUERADE
PostDown = ip6tables -D FORWARD -i wg1 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o wlan0 -j MASQUERADE
#PostDown = ip route del 11.11.11.11/32
[Peer]
PublicKey = qqq
AllowedIPs = 10.9.1.0/24
Endpoint = 11.11.11.11:7777
# Uncomment the following, if you're behind a NAT and want the connection to be kept alive.
PersistentKeepalive = 25
wg command status:
interface: wg0
public key: ddd
private key: (hidden)
listening port: 51820
peer: yyy
endpoint: 11.11.11.11:51000
allowed ips: 10.9.0.2/32
latest handshake: 1 minute, 48 seconds ago
transfer: 11.99 MiB received, 397.40 MiB sent
interface: wg1
public key: ggg
private key: (hidden)
listening port: 35999
peer: qqq
endpoint: 11.11.11.11:7777
allowed ips: 10.9.1.0/24
transfer: 0 B received, 525.95 KiB sent
persistent keepalive: every 25 seconds
wg0.conf
/wg1.conf
files please also provide them (you should redact the keys). If it's done otherwise, please provide how it's done.nft
ornftables
command.