WireGuard - what connection sheme is more secure and/or more correct

Every manual or install script that i found is oriented for 1 NIC systems, if i understand it right:WAN -> router(NAT) ->LAN->Wireguard server->LAN(noVLANs or VLANS)

is this correct to port forward packets directly from wan to lan(even if this is a only i port and one ip) or more correct(and more difficult to setup) this scheme:

WAN -> router(NAT) -> WireGuard server(DMZ VLAN) -> LAN (internal VLANs)??

And if somebody have expirience in this kind of setup, please share you kowledge or give a link to articles.I try to setup a 2 NIC on my Ubuntu server for this but it was not so easy as i think,i had a problem with routes,default routes,additional routing tables etc., and maybe it not so necessary at all?

Posted Oct 2, 2019, 1:18 PM UTC

25
[deleted]•

[removed]

1
artagel•

Yea I have it running at home on a VM with 2 NICs. One is in a inside VLAN and the other is on an Internet VLAN. I then route all my traffic to the VM as a default route (via DHCP config) for clients on the subnet.

You need to turn on ip forwarding. Also you need to ensure your default route on the vm is out your internet interface, and your internal vlan is specifically routed to the inside Interface(For traffic back to the clients). Then you need to configure NAT (Iptables or whatever method you like) to the wireguard Interface for traffic sourced from your inside VLAN subnet.

After that bring wireguard up and it should be working. Wireguard will initiate traffic out the Internet side, and then your wg Interface comes up and your NAT rule kicks in.

1
hellofaduckOP•

Oh, so complicated as i thinking about it :)) thank you for detailed answer! i try to configure as you say when have free time for this!!

1
artagel•

Operating System

Ubuntu 18.04.3 LTS

IPv4 Forwarding

Enable IPv4 Forwarding

sudo echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.d/99-sysctl.conf
sudo sysctl -p /etc/sysctl.d/99-sysctl.conf

Make sure you also allow forwarding in this file. I'm not 100% o which one is used in Ubuntu 18.

vi /etc/ufw/sysctl.conf
net.ipv4.ip_forward=1

Configure netplan

Configure netplan to take DHCP from Internet interface, and from internal interface Note, I have my internal interface statically reserved in my DHCP server to 10.0.3.2, and 10.0.3.1 is the VLAN's gateway. The rest of the hosts on the internal VLAN get a 10.0.3.x address with a default route of 10.0.3.2 (not 10.0.3.1), in order to route through my wireguard gateway.

sudo vi /etc/netplan/01-netcfg.yaml 

network:
  version: 2
  renderer: networkd
  ethernets:
    ens160:
      dhcp4: yes
      dhcp6: yes
    ens192:
      dhcp4: yes
      dhcp4-overrides:
        use-routes: false
      routes:
         - to: 10.0.0.0/8
           via: 10.0.3.1
           on-link: true
netplan --debug apply

Wireguard Config

Note that I don't have my wireguard VPN add ANY routes.

[Interface]
PrivateKey = <redacted>
Address = 10.64.0.57/32,fc00:bbbb:bbbb:bb01::1:38/128
DNS = 193.138.218.74

[Peer]
PublicKey = <redacted>
AllowedIPs = 0.0.0.0/0,::0/0
Endpoint = 38.131.126.42:51820

Configure NAT

Add NAT rules at the beginning of the following file. 10.0.3.0/24 is my Internal LAN.

vi /etc/ufw/before.rules

*nat
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -s 10.0.3.0/24 -o name_of_wg_int -j MASQUERADE
COMMIT

Restart ufw

systemctl restart ufw

Turn on VPN

wg-quick up vpn-us16

Test it

curl wtfismyip.com/json
{
   "YourFuckingIPAddress": "38.131.126.67",
   "YourFuckingLocation": "New York, NY, United States",
   "YourFuckingHostname": "38.131.126.67",
   "YourFuckingISP": "DediPath",
   "YourFuckingTorExit": "false",
   "YourFuckingCountryCode": "US"
}

1
hellofaduckOP•

Thank you for you time, try to implement this in my setup!

1