With wireguard, is it possible to create a tunnel that will only allow traffic in one direction? For example heres the following scenario: Given PC-s: A, B, C. A should be able to reach (ping, telnet, etc) B and C, B should be able to reach C, but not backwards. I figured the AllowedIPs will let me do that but I was mistaken, as it needs to be added on both sides, and it will be bidirectional
The current solution I've found is to set up iptables on each PC and defining every rule about every connection, what to drop and what to accept, but I figured there might be a better solution for this.
Update: With iptables, I was able to figure it out following @grawity_u1686's comment:
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
11 924 ACCEPT 0 -- wg0 * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
12 1008 DROP 0 -- wg0 * 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
3 252 ACCEPT 0 -- wg0 * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
9 756 DROP 0 -- wg0 * 10.0.0.3 10.0.0.2
0 0 ACCEPT 0 -- * wg0 10.0.0.1 10.0.0.2
0 0 ACCEPT 0 -- * wg0 10.0.0.1 10.0.0.3
26 2184 ACCEPT 0 -- * wg0 10.0.0.2 10.0.0.3
0 0 ACCEPT 0 -- wg0 * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Update, with nftables it's also working:
table inet filter {
chain INPUT {
type filter hook input priority 0; policy accept;
iifname "wg0" ct state related,established accept
iifname "wg0" drop
}
chain FORWARD {
type filter hook forward priority 0; policy accept;
iifname "wg0" ct state related,established accept
iifname "wg0" ip saddr 10.0.0.3 ip daddr 10.0.0.2 drop
oifname "wg0" ip saddr 10.0.0.1 ip daddr 10.0.0.2 accept
oifname "wg0" ip saddr 10.0.0.1 ip daddr 10.0.0.3 accept
oifname "wg0" ip saddr 10.0.0.2 ip daddr 10.0.0.3 accept
iifname "wg0" ct state related,established accept
}
chain OUTPUT {
type filter hook output priority 0; policy accept;
}
}