# WireGuard for SNO behind NAT

**URL:** <https://forum.storj.io/t/wireguard-for-sno-behind-nat/5372>\
**Category:** troubleshooting\
**Tags:** cgnat\
**Created:** [March 23, 2020, 6:38pm UTC](https://forum.storj.io/t/wireguard-for-sno-behind-nat/5372 "2020-03-23T18:38:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SlavikCA](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/slavikca/32/66_2.png) [@SlavikCA](https://forum.storj.io/u/SlavikCA)\
**Post date:** [March 23, 2020, 6:38pm UTC](https://forum.storj.io/t/wireguard-for-sno-behind-nat/5372/1 "2020-03-23T18:38:58Z")

</div>

My ISP (Telus) is not really CGNAT, but blocks any incoming connections, which is almost same thing.  
So, I can’t configure Port Fowarding.

But I have VPS with unlimited traffic near by. So, I want to proxy StorJ traffix though it.  
I tried to configure WireGuard to do that. But I can’t make it work.

Does anyone has experience / knowledge on how to do it?

Here is how I want to do it:

Windows StorJ @ residence with Telus ISP **\<=Wireguard=\>** Linux VPS @ Azure **\<==\>** Internet

I can’t figure out WireGuard configuration for the Linux VPS. Looks like I need some iptables config…

---

<div class="post-metadata">

**Author:** ![xyphos10](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/xyphos10/32/60_2.png) [@xyphos10](https://forum.storj.io/u/xyphos10)\
**Post date:** [March 23, 2020, 6:54pm UTC](https://forum.storj.io/t/wireguard-for-sno-behind-nat/5372/2 "2020-03-23T18:54:13Z")

</div>

Hello, you can try the following;

# Accept Desired Traffic

iptables -I INPUT 1 -i CHANGETOINTERFACENAME -p udp --dport VPNPORT -j ACCEPT  
iptables -A INPUT -i wg0 -p all -j ACCEPT

# Enable NAT on vpn traffic

iptables -t nat -I POSTROUTING -s VPNNETWORK -o CHANGETOINTERFACENAME -j MASQUERADE

# Port Forward Rules

iptables -t nat -A PREROUTING -d YOURVPSPUBLICIP -p tcp --dport 28967 -j DNAT --to-destination MACHINEINTERNALVPNIP:28967

---

<div class="post-metadata">

**Author:** ![fmoledina](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/fmoledina/32/6739_2.png) [@fmoledina](https://forum.storj.io/u/fmoledina)\
**Post date:** [March 24, 2020, 4:18am UTC](https://forum.storj.io/t/wireguard-for-sno-behind-nat/5372/3 "2020-03-24T04:18:18Z")

</div>

This makes me curious. I’m with Telus and for me only port 80 is blocked. Maybe 25 too but I’ve never tested that. I’m running a lot of services and forwarding many ports without issues. This includes port 443 for my reverse proxy, and multiple higher ports for VPNs, apps like Storj, etc.

Where are you located?

---

<div class="post-metadata">

**Author:** ![SlavikCA](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/slavikca/32/66_2.png) [@SlavikCA](https://forum.storj.io/u/SlavikCA)\
**Post date:** [March 26, 2020, 3:49pm UTC](https://forum.storj.io/t/wireguard-for-sno-behind-nat/5372/4 "2020-03-26T15:49:44Z")

</div>

@fmoledina, I’m in Richmond, BC. And I found, that all of my ipv4 ports blocked. Interestingly, I found, that my ipv6 ports are open, but that’s is of little help for StorJ.

I tried @xyphos10 settings above. It didn’t work.  
I asked the same question on [StackOverflow](https://stackoverflow.com/questions/60843809/how-to-expose-my-behind-the-nat-web-server-via-wireguard-on-public-vps) now.

But I made it to work with `Wireguard` + [`rinetd`](https://manpages.debian.org/unstable/rinetd/rinetd.8.en.html):

1. `Wireguard` enables VPS to communicate with StorJ node-behind-NAT
2. `rinetd` running on VPS is forwarding TCP from WAN to Wireguard, a sort of “publishing” or opening StorJ ports to the WAN.

Here is the dashboard of my new behind-the-NAT StorJ node:  
[http://storj.slavikf.com/](http://storj.slavikf.com/)  
Yes, I know, that some people consider opening it as a security risk. I want to test & see what happens.

---

<div class="post-metadata">

**Author:** ![xyphos10](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/xyphos10/32/60_2.png) [@xyphos10](https://forum.storj.io/u/xyphos10)\
**Post date:** [March 26, 2020, 4:03pm UTC](https://forum.storj.io/t/wireguard-for-sno-behind-nat/5372/5 "2020-03-26T16:03:46Z")

</div>

Hmm not sure why it did not work, I have a similar config running on two machines at it works not problem. I used pivpn to create the wireguard configs though.

Here is my full script for iptables

#!/bin/bash

# Flush existing rules

iptables -P INPUT ACCEPT  
iptables -P FORWARD ACCEPT  
iptables -P OUTPUT ACCEPT  
iptables -t nat -F  
iptables -F  
iptables -X  
iptables-save \> /etc/iptables/rules.v4

# Accept loopback traffic

iptables -A INPUT -i lo -p all -j ACCEPT

# Accept return traffic

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Set default INPUT policy to DROP

iptables -P INPUT DROP

# Set default FORWARD policy to ACCEPT

iptables -P FORWARD ACCEPT

# Set default OUTPUT policy to ACCEPT

iptables -P OUTPUT ACCEPT

# Accept Desired Traffic

iptables -I INPUT 1 -i eth0 -p udp --dport 20443 -j ACCEPT #allow vpn traffice to vps  
iptables -A INPUT -i wg0 -p all -j ACCEPT

# Enable NAT on vpn traffic

iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

# Port Forward Rules

iptables -t nat -A PREROUTING -d PUBLIC-IP-HERE -p tcp --dport 28967 -j DNAT --to-destination 10.8.0.2:28967

iptables-save \> /etc/iptables/rules.v4

---

<div class="post-metadata">

**Author:** ![victorelec14](https://storj.bcdn.literatehosting.com/user_avatar/forum.storj.io/victorelec14/32/71_2.png) [@victorelec14](https://forum.storj.io/u/victorelec14)\
**Post date:** [July 20, 2021, 7:31pm UTC](https://forum.storj.io/t/wireguard-for-sno-behind-nat/5372/6 "2021-07-20T19:31:08Z")

</div>

Hello @SlavikCA , I have the same problem as you, have you found a solution?

Are you using the rules that recommend @xyphos10 ?
