Skip to contentSkip to conversation

Force a specific IP for outgoing WG traffic with SNAT?

DISCUSSION Roman Mamedov 2 participants 3 messages Feb 16, 2023 – Mar 17, 2023

lore
Share & tools
lore
#0 lore raw

Hello,

I'm trying to move all my WG communication with peers to a non-primary IP of my server.

It has IPs added like this:

inet6 2001:db8::ca6c/128 scope global deprecated
valid_lft forever preferred_lft 0sec
inet6 2001:db8::1/128 scope global nodad
valid_lft forever preferred_lft forever

What I tried:

  ip6tables -t nat -I POSTROUTING -d 2000::/3 -p udp --dport 51820 -j SNAT --to-source 2001:db8::ca6c

Also tried to filter by --sport, and also briefly without a port filter at all.

This has zero effect, as shown by tcpdump all the WG traffic still originates from 2001:db8::1

Does anyone have an idea why is that? Thanks

Signature · 2 lines
With respect,
Roman
#1 lore raw
Quoted 17 lines · Roman Mamedov

Hello,

I'm trying to move all my WG communication with peers to a non-primary IP of my server.

It has IPs added like this:

inet6 2001:db8::ca6c/128 scope global deprecated
valid_lft forever preferred_lft 0sec
inet6 2001:db8::1/128 scope global nodad
valid_lft forever preferred_lft forever

What I tried:

ip6tables -t nat -I POSTROUTING -d 2000::/3 -p udp --dport 51820 -j
SNAT --to-source 2001:db8::ca6c

Quoted 6 lines

Also tried to filter by --sport, and also briefly without a port filter at all.

This has zero effect, as shown by tcpdump all the WG traffic still originates from 2001:db8::1

Does anyone have an idea why is that? Thanks

Did you try filtering based on fwmark ?

CONFIGURATION FILE FORMAT
The configuration file format is based on INI. There are two
top level sections -- Interface and Peer. Multiple Peer sections may be specified, but only one Interface section may be specified.

The Interface section may contain the following fields:

• PrivateKey — a base64 private key generated by wg
genkey. Required.

• ListenPort — a 16-bit port for listening. Optional; if
not specified, chosen randomly.

• FwMark — a 32-bit fwmark for outgoing packets. If set
to 0 or "off", this option is disabled. May be specified in hexadecimal by prepending "0x". Optional.

HTH

Signature · 3 lines
Ashish

"It could be that the purpose of your life is only to serve as a warning to others." (Ashleigh Brilliant)
#2 lore raw
Quoted 12 lines · On Sat, 18 Mar 2023 01:13:53 +0530 Ashish SHUKLA <[email protected]> wrote:

Did you try filtering based on fwmark ?

CONFIGURATION FILE FORMAT
The configuration file format is based on INI. There are two
top level sections -- Interface and Peer. Multiple Peer sections may be specified, but only one Interface section may be specified.

The Interface section may contain the following fields:

• PrivateKey — a base64 private key generated by wg
genkey. Required.

Quoted 6 lines

• ListenPort — a 16-bit port for listening. Optional; if
not specified, chosen randomly.

• FwMark — a 32-bit fwmark for outgoing packets. If set
to 0 or "off", this option is disabled. May be specified in hexadecimal by prepending "0x". Optional.

I was not aware there was such an option. For now the task described in the original message is no longer required, I will try fwmark next time when it might be. Thanks!

Signature · 2 lines
With respect,
Roman