Route all traffic to one IP _only_ via wireguard
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi Eric, yes,
Quoted 1 line
I only want to use wg0 for x.x.x.x/32, and I want to use eth0 for everyth=
ing else<
this is correct.
No wg-quick used, as client-OS is openwrt.
I suspect a problem, that the IP of my endpoint is the IP, too, the traffic=
for I want to route via wg0.
Or, in other words, Endpoint=3D1.2.3.4, and I want all traffic to 1.2.3.4 f= rom my router to be routed via wg0.
I have found a working version, still under investigation/test:
wg0-client, wireguard_up.sh:
#!/bin/sh
ip link add wg0 type wireguard
wg setconf wg0 /etc/wireguard/wg0.conf
ip address add 172.16.18.31/16 dev wg0
ip link set mtu 1420 dev wg0
ip link set wg0 up
sleep 10 #sometimes helps with async ops
iptables -t nat -I POSTROUTING -o wg0 -j MASQUERADE
sleep 10 #sometimes helps with async ops
ping -c 3 172.16.0.1 #To force some traffic to server, persistent connectio= n to be established (??)
iptables -t nat -A OUTPUT -d 1.2.3.4 -j DNAT --to-destination 172.16.0.1 #w= g0 on server has 172.16.0.1
ping -c 3 1.2.3.4
wg0-client, wg0.conf:
[Interface]
PrivateKey =3D ....
ListenPort =3D 5555
[Peer]
PublicKey =3D ....
AllowedIPs =3D 172.16.0.0/16
Endpoint =3D 1.2.3.4:5555
PersistentKeepalive =3D 25
--------------------------------------------
Eric Light <[email protected]> schrieb am So, 29.4.2018:
Betreff: Re: Route all traffic to one IP _only_ via wireguard
An: "Eddie" <[email protected]>, "reiner otto" <[email protected]=
e>, [email protected]
Datum: Sonntag, 29. April, 2018 17:19 Uhr
=20
Hi Eddie and Reiner,=20
=20
I might be misunderstanding
the request, but...=20
=20
Quoted 1 line
the real goal is to tunnel only traffic with a specific destination IP via wireguard from client to server.
=20
Isn't this just asking the
same as:
=20
Quoted 1 line
I only want
to use wg0 for x.x.x.x/32, and I want to use eth0 for everything else
=20
If I'm
reading that right, I believe it's a simple matter of changing the scope of his AllowedIPs, so his traffic is routed via the correct interfaces. No iptables or packet marks required.=20
=20
Reiner -
have I misunderstood your question? I've assumed you're using wg-quick?=20
=20
E
=20
--------------------------------------------
Q: Why is this email five sentences or less?
A: http://five.sentenc.es
=20
Quoted 1 line · Eddie
I didn't think that AllowedIPs would
filter traffic like that.=C2=A0 But=20
Quoted 1 line
could
be wrong.=C2=A0 :-)
Quoted 2 lines
=20
Here's my take on your problem:
Quoted 2 lines
=20
Add "Table =3D off" and
"FwMark =3D 1234 (or other value)" to the wg config,
=20
Quoted 1 line
which will stop the routing tables
being updated and add the routing=20
Quoted 1 line
mark
to all encrypted packets.
Quoted 2 lines
=20
Then you will need a new ip rule table,
that runs ahead of "main" that=20
Quoted 1 line
selects all traffic with the fwmark from
wg and routes that directly to=20
Quoted 1 line
your
external interface.=C2=A0 Something like:
Quoted 1 line
=20
Quoted 4 lines
from all fwmark 1234 lookup net
=20
net:
default via <gateway ip> dev
<external interface>
Quoted 2 lines
=20
Then add a new rule to main, that routes
ip 1.2.3.4 out via the wg=20
Quoted 1 line
interface.
Quoted 2 lines
=20
Cheers.
Quoted 7 lines
=20
=20Quoted 4 lines · Eric Light
Hi Reiner!
I think the problem here is
your client's AllowedIPs section. If you only want to access one address, you only enter that target IP - not the whole internet space (0.0.0.0/0). That's why everything is being routed out via your wg0.
Quoted 3 lines
Quoted 3 lines
So you should change that
client AllowedIPs to 172.16.0.1/32, and that'll fix it. Alternatively, set it to /24 if you also want access to other devices within the corporate LAN... That's how I do it.
Quoted 2 lines
Quoted 2 lines
I
think that's all you need. Sorry if I've missed
something! :)
Quoted 5 lines
Quoted 1 line
E
Quoted 2 lines
--------------------------------------------
Quoted 1 line
Quoted 1 line
Q: Why is this email five sentences
or less?
Quoted 3 lines
Quoted 3 lines
On Sat, 28
Quoted 2 lines · reiner otto
Quoted 2 lines
My basic setup of wg works, I can ssh from/to
server or client.
Quoted 1 line
Quoted 1 line
Quoted 1 line
But the real
goal is to tunnel only traffic with a specific destination IP
Quoted 1 line
Quoted 1 line
Quoted 1 line
via wireguard from client
to server.
Quoted 1 line
Quoted 1 line
Quoted 1 line
I.e. a local
router, which allows direct access to the web,
Quoted 1 line
Quoted 1 line
Quoted 1 line
_BUT_ all traffic going to the
corporate server using wireguard only.
Quoted 2 lines
Quoted 2 lines
Corporate server (public 1.2.3.4) =3D=3D wireguard
server (172.16.0.1).
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I tried various settings on my
client, like
Quoted 1 line
Quoted 1 line
Quoted 1 line
ip route 1.2.3.4
dev wg0
Quoted 1 line
Quoted 1 line
Quoted 1 line
ip route 1.2.3.4 via
172.16.0.1
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
etc.
but nothing worked.Any
help really appreciated.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
---
wg0.conf on server (1.2.3.4):
Quoted 1 line
Quoted 1 line
Quoted 1 line
[Interface]
Quoted 1 line
Quoted 1 line
Quoted 1 line
ListenPort =3D
1234
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
PrivateKey =3D secret
[Peer]PublicKey =3D secret
Quoted 1 line
AllowedIPs =3D 172.16.0.0/16
Quoted 1 line
Quoted 1 line
Quoted 1 line
-
Quoted 1 line
Quoted 1 line
Quoted 1 line
wg0.conf on client
(172.16.18.31):
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
[Interface]
PrivateKey =3D secret
ListenPort =3D 1234
[Peer]PublicKey =3D secret
Quoted 1 line
AllowedIPs =3D 0.0.0.0/0
Quoted 1 line
Quoted 1 line
Quoted 1 line
Endpoint =3D 1.2.3.4:1234
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
_______________________________________________
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard
_______________________________________________
Quoted 6 lines
Quoted 5 lines
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard=20