Wireguard proper server config

Hello Folks,

Since this is my first post on this forum, prior to ask about things, I’d like to say HI to you.

I am lacking some knownledge and I’d like to ask you for a help and understanding my case. I prepared small schematic (sorry about performance) of structure of my network. That’s first.

I am trying to get Wireguard working on my mt, but no luck. I tried all suggestions here and on yt posted but no luck.

Back in the days, when I managed old router (before mt) I just had to port forward, to my server with wireguard and all was fine. I suspect now is probably the same case.

Can you please give me some hints guys?

BR

Edit. I see packets flowing when I’m on wifi on my android device with following setting:

/ip firewall nat print
Flags: X - disabled, I - invalid; D - dynamic 
 0    ;;; defconf: masquerade
      chain=srcnat action=masquerade out-interface-list=WAN log=no log-prefix="" 
      ipsec-policy=out,none 

 1    chain=dstnat action=dst-nat to-addresses=192.168.1.1 to-ports=13231 
      protocol=udp dst-address=my.external.ip.address dst-port=13231 log=no log-prefix=""

But no luck with mobile data. No packets shown anywhere on firewall.

Hi back

Questions:

  • I assume your left device is a RB SXT sqG-5acD. It has an external IP 192.168.100.249 and an internal IP in the 192.168.1.0-range ?
  • which device do you intend to have acting as “server” (which conceptually does not exist on WG, there are only peers)
  • can you reach that device and port 12321 from outside ? How ?

What I find strange is that all ip-ranges are private ranges. What else is there to make sure you get to the real internet ?
What’s in front of the RB SXT ? Or are your IP-ranges here purely informational ?

Have you checked the documentation ? https://help.mikrotik.com/docs/display/ROS/WireGuard

Note: there will always be some traffic going out visible. Only when you see traffic coming back in, you will know it works.

Try using IP Cloud on the MT devices to ascertain your public IP at each end.

Hi! I guess I messed things up a bit.

Questions:

  • I assume your left device is a RB SXT sqG-5acD. It has an external IP 192.168.100.249 and an internal IP in the 192.168.1.0-range ? > Left device is not mine, it’s ISP property. I can’t access it. I can see this device on my MT in ‘Neighbour list’ as 192.168.100.1. It is acting as gateway for my router.
  • which device do you intend to have acting as “server” (which conceptually does not exist on WG, there are only peers) > The right one.
  • can you reach that device and port 12321 from outside ? How ?

What I find strange is that all ip-ranges are private ranges. What else is there to make sure you get to the real internet ?
What’s in front of the RB SXT ? Or are your IP-ranges here purely informational ? > The left device is communicating with some sort of repeater couple hundred meters away.

Okay, maybe still possible. YOu can see the left device but its routing not just modeming…
What one needs to do is access the ISP router and port forward the WIREGUARD LISTENING PORT TO YOUR private WANIP. ( A lanip from the ISP routers perspective )
If you dont have access directly you should ask your ISP to do it for you. UDP protocol!!

From my first post on this thread:

‘Back in the days, when I managed old router (before mt) I just had to port forward, to my server with wireguard and all was fine. I suspect now is probably the same case.’

It is.
It is not because it is old school, it does not work anymore :smiley:

What is not working anymore? Port forwarding? When I’ve had my old PC acting as server, running wireguard server within my lan, the trick was to port forward udp 51820.

Two things changed from then:

  • no old PC with wireguard → now wireguard is on MT


  • no old router → my new mikrotik is now my router

When I check my external IP address on ipchicken, for instance, it’s always the same - it’s static IP.

I am a bit confused.
What device do you use as “entry point” to reach the Wireguard port (which ultimately needs to be forwarded one way or the other towards your MT router) ?
Is port forwarding functioning there ?

Sorry, I think I don’t understand your question. Perhaps this graphic will tell more.

OK, much clearer :smiley:

On new MT router, add firewall rule to allow port 51820
/ip/firewall/filter add chain=input action=accept protocol=udp in-interface-list=WAN dst-port=51820 log=no (or yes, your choice)
Move that rule above the input drop rule which blocks everything coming from WAN (or !LAN, depends if you changed it or not).

And then setup Wireguard as per instructions of Wiki.

(1) The important learning point being is that if the MT is the public facing router or even if its behind another router, (but is the server to start the connection) one has to ALLOW the listening port traffic to hit the router itself (hence INPUT CHAIN RULE) to initially establish the tunnel.
If you know the IP address traffic is coming in you can narrow it down but generally since its for establishing a VPN tunnel and the credentials will be checked, its secure in the form presented.

(2) If, on the Server Side, the peer users will be going out to the internet using the WANIP of the server, there has to be a route in place to ensure that Wireguard traffic (peer originated outbound) returning from the internet being provided on the server side is sent to the other end of the tunnel (back to the peer). This also applies to returning traffic from any interactions with subnets on the LANSIDE of the server router (perhaps the peer users are using a printer on the server side).

(3) The rest of the setup is done on the wireguard settings themselves…
I have mine setup so that I can actually reach the PEER router and configure it via winbox for example.
THat entails more work…

@holvoetn thanks for the tip, but I knew about it and I’ve done it - no success.

I think I literally did everything what was suggested in this thread: http://forum.mikrotik.com/t/mikrotik-wireguard-server-with-road-warrior-clients/148392/1

Don’t know where I really stuck. It must be something in firewall config - port forwarding or routing I guess - since not long time ago I was able to run wireguard and connect to it from remote location…

Edit. I think about it again and I recon I don’t need to port forwarding like I did with my old setup. I just need to access my MT from outside, but unable to do so.

Can you post your current configuration ?
/export hide-sensitive file=whatever

Then we can have a look.

There you go: https://pastebin.pl/view/1817c65c

Posting your config between Code-tags is easier for everyone …

# oct/10/2021 20:57:46 by RouterOS 7.1rc4
# software id = BSM0-IT8B
#
# model = RBD53iG-5HacD2HnD
# serial number = E7290XXXXXXX
/interface bridge
add admin-mac=08:55:31:XX:XX:XX auto-mac=no comment=defconf name=bridge
/interface wireless
set [ find default-name=wlan1 ] band=2ghz-b/g/n channel-width=20/40mhz-XX \
    country=poland disabled=no distance=indoors frequency=auto installation=\
    indoor mode=ap-bridge ssid=czosnek wireless-protocol=802.11
set [ find default-name=wlan2 ] band=5ghz-a/n/ac channel-width=\
    20/40/80mhz-XXXX disabled=no distance=indoors frequency=auto \
    installation=indoor mode=ap-bridge ssid=czosnek_5 wireless-protocol=\
    802.11
/interface wireguard
add listen-port=13231 mtu=1420 name=wgmt
/disk
set usb1 disabled=no
set usb1-part1 disabled=no
set usb1-part2 disabled=no
set usb1-part3 disabled=no name=disk1
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
/interface wireless security-profiles
set [ find default=yes ] authentication-types=wpa2-psk eap-methods="" mode=\
    dynamic-keys supplicant-identity=MikroTik
/ip pool
add name=default-dhcp ranges=192.168.1.2-192.168.1.254
/ip dhcp-server
add address-pool=default-dhcp interface=bridge lease-time=1d name=defconf
/interface bridge port
add bridge=bridge comment=defconf interface=ether2
add bridge=bridge comment=defconf interface=ether3
add bridge=bridge comment=defconf interface=ether4
add bridge=bridge comment=defconf interface=ether5
add bridge=bridge comment=defconf interface=wlan1
add bridge=bridge comment=defconf interface=wlan2
/ip neighbor discovery-settings
set discover-interface-list=all
/interface list member
add comment=defconf interface=bridge list=LAN
add comment=defconf interface=ether1 list=WAN
add comment=Wireguard interface=wgmt list=LAN
/interface wireguard peers
add interface=wgmt public-key="XXX="
/ip address
add address=192.168.1.1/24 comment=defconf interface=bridge network=\
    192.168.1.0
add address=10.20.50.1/24 comment=Wireguard interface=wgmt network=10.20.50.0
/ip dhcp-client
add comment=defconf interface=ether1 use-peer-dns=no use-peer-ntp=no
/ip dhcp-server network
add address=192.168.1.0/24 comment=defconf gateway=192.168.1.1
/ip dns
set allow-remote-requests=yes servers=1.1.1.1,1.0.0.1
/ip dns static
add address=192.168.88.1 comment=defconf name=router.lan
/ip firewall filter
add action=accept chain=input comment=Wireguard dst-port=13231 \
    in-interface-list=LAN protocol=udp
add action=accept chain=input dst-port=13231 in-interface-list=WAN protocol=\
    udp
add action=accept chain=input comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
    invalid
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input comment=\
    "defconf: accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
add action=drop chain=input comment="defconf: drop all not coming from LAN" \
    in-interface-list=!LAN
add action=accept chain=forward dst-address=192.168.1.1 dst-port=13231 \
    in-interface=ether1 protocol=udp
add action=accept chain=forward comment="defconf: accept in ipsec policy" \
    ipsec-policy=in,ipsec
add action=accept chain=forward comment="defconf: accept out ipsec policy" \
    ipsec-policy=out,ipsec
add action=fasttrack-connection chain=forward comment="defconf: fasttrack" \
    connection-state=established,related hw-offload=yes
add action=accept chain=forward comment=\
    "defconf: accept established,related, untracked" connection-state=\
    established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
    connection-state=invalid
add action=drop chain=forward comment=\
    "defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat \
    connection-state=new in-interface-list=WAN
/ip firewall nat
add action=masquerade chain=srcnat comment="defconf: masquerade" \
    ipsec-policy=out,none out-interface-list=WAN
add action=dst-nat chain=dstnat dst-address=XX.XXX.XXX.XXX dst-port=13231 \
    protocol=udp to-addresses=10.20.50.0 to-ports=13231
/ipv6 firewall address-list
add address=::/128 comment="defconf: unspecified address" list=bad_ipv6
add address=::1/128 comment="defconf: lo" list=bad_ipv6
add address=fec0::/10 comment="defconf: site-local" list=bad_ipv6
add address=::ffff:0.0.0.0/96 comment="defconf: ipv4-mapped" list=bad_ipv6
add address=::/96 comment="defconf: ipv4 compat" list=bad_ipv6
add address=100::/64 comment="defconf: discard only " list=bad_ipv6
add address=2001:db8::/32 comment="defconf: documentation" list=bad_ipv6
add address=2001:10::/28 comment="defconf: ORCHID" list=bad_ipv6
add address=3ffe::/16 comment="defconf: 6bone" list=bad_ipv6
/ipv6 firewall filter
add action=accept chain=input comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
    invalid
add action=accept chain=input comment="defconf: accept ICMPv6" protocol=\
    icmpv6
add action=accept chain=input comment="defconf: accept UDP traceroute" port=\
    33434-33534 protocol=udp
add action=accept chain=input comment=\
    "defconf: accept DHCPv6-Client prefix delegation." dst-port=546 protocol=\
    udp src-address=fe80::/10
add action=accept chain=input comment="defconf: accept IKE" dst-port=500,4500 \
    protocol=udp
add action=accept chain=input comment="defconf: accept ipsec AH" protocol=\
    ipsec-ah
add action=accept chain=input comment="defconf: accept ipsec ESP" protocol=\
    ipsec-esp
add action=accept chain=input comment=\
    "defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
add action=drop chain=input comment=\
    "defconf: drop everything else not coming from LAN" in-interface-list=\
    !LAN
add action=accept chain=forward comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
    connection-state=invalid
add action=drop chain=forward comment=\
    "defconf: drop packets with bad src ipv6" src-address-list=bad_ipv6
add action=drop chain=forward comment=\
    "defconf: drop packets with bad dst ipv6" dst-address-list=bad_ipv6
add action=drop chain=forward comment="defconf: rfc4890 drop hop-limit=1" \
    hop-limit=equal:1 protocol=icmpv6
add action=accept chain=forward comment="defconf: accept ICMPv6" protocol=\
    icmpv6
add action=accept chain=forward comment="defconf: accept HIP" protocol=139
add action=accept chain=forward comment="defconf: accept IKE" dst-port=\
    500,4500 protocol=udp
add action=accept chain=forward comment="defconf: accept ipsec AH" protocol=\
    ipsec-ah
add action=accept chain=forward comment="defconf: accept ipsec ESP" protocol=\
    ipsec-esp
add action=accept chain=forward comment=\
    "defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
add action=drop chain=forward comment=\
    "defconf: drop everything else not coming from LAN" in-interface-list=\
    !LAN
/system clock
set time-zone-name=Europe/Warsaw
/system ntp client
set enabled=yes
/system ntp client servers
add address=ntp.task.gda.pl
/system routerboard settings
set cpu-frequency=auto
/tool mac-server
set allowed-interface-list=LAN
/tool mac-server mac-winbox
set allowed-interface-list=LAN

Question 1: why is you wireguard listen port on the config 13231 whereas you say above it should be 51820 ?
If you’re knocking at the wrong door, it makes sense nobody opens …

Question 2:
peer definition of wireguard: where is endpoint address and port ? It should at least have the own-IP address if the ‘other side’ does not have a public IP address. It needs an address and a port to listen to.

Once again, please follow the instructions from the documentation. There are a very good base.
https://help.mikrotik.com/docs/display/ROS/WireGuard

I dont see a mismatch the listen port for wireguard and the input chain to listen for it are the same 13231?

However why is this rule in your input chain, (what purpose)?
add action=accept chain=input comment=Wireguard dst-port=13231 in-interface-list=LAN protocol=udp
In the forward chain what is the purpose of this rule??
add action=accept chain=forward dst-address=192.168.1.1 dst-port=13231 in-interface=ether1 protocol=udp

In the NAT chain what is the purpose of this rule??
add action=dst-nat chain=dstnat dst-address=XX.XXX.XXX.XXX dst-port=13231 protocol=udp to-addresses=10.20.50.0 to-ports=13231

If you read my post you only need
a. listening port on input chain
b. route back to the peer

Where in the conversation did all these other crap seeming rules get recommended/discussed???

Where are your IP route settings??

Hello!

I followed once more everything from a thread: http://forum.mikrotik.com/t/mikrotik-wireguard-server-with-road-warrior-clients/148392/1

I came up with this setting:

/interface wireguard
add listen-port=13231 mtu=1420 name=wgmt
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
/ip pool
add name=default-dhcp ranges=192.168.1.2-192.168.1.254
/ip dhcp-server
add address-pool=default-dhcp interface=bridge lease-time=1d name=defconf
/interface bridge port
add bridge=bridge comment=defconf interface=ether2
add bridge=bridge comment=defconf interface=ether3
add bridge=bridge comment=defconf interface=ether4
add bridge=bridge comment=defconf interface=ether5
add bridge=bridge comment=defconf interface=wlan1
add bridge=bridge comment=defconf interface=wlan2
/ip neighbor discovery-settings
set discover-interface-list=all
/interface list member
add comment=defconf interface=bridge list=LAN
add comment=defconf interface=ether1 list=WAN
add comment=Wireguard interface=wgmt list=LAN
/interface wireguard peers
add allowed-address=10.20.50.2/32 endpoint-port=13231 interface=wgmt \
    public-key="sensitive"
/ip address
add address=192.168.1.1/24 comment=defconf interface=bridge network=\
    192.168.1.0
add address=10.20.50.1/24 comment=Wireguard interface=wgmt network=10.20.50.0
/ip dhcp-client
add comment=defconf interface=ether1 use-peer-dns=no use-peer-ntp=no
/ip dhcp-server network
add address=192.168.1.0/24 comment=defconf gateway=192.168.1.1
/ip dns
set allow-remote-requests=yes servers=1.1.1.1,1.0.0.1
/ip firewall filter
add action=accept chain=input comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=accept chain=input comment="Allow Wireguard" dst-port=13231 \
    protocol=udp
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
    invalid
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input comment=\
    "defconf: accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
add action=drop chain=input comment="defconf: drop all not coming from LAN" \
    in-interface-list=!LAN
add action=accept chain=forward comment="defconf: accept in ipsec policy" \
    ipsec-policy=in,ipsec
add action=accept chain=forward comment="defconf: accept out ipsec policy" \
    ipsec-policy=out,ipsec
add action=fasttrack-connection chain=forward comment="defconf: fasttrack" \
    connection-state=established,related hw-offload=yes
add action=accept chain=forward comment=\
    "defconf: accept established,related, untracked" connection-state=\
    established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
    connection-state=invalid
add action=drop chain=forward comment=\
    "defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat \
    connection-state=new in-interface-list=WAN
/ip firewall nat
add action=masquerade chain=srcnat comment="defconf: masquerade" \
    ipsec-policy=out,none out-interface-list=WAN
/ip route
add disabled=no distance=1 dst-address=10.20.50.0/24 gateway=wgmt pref-src="" \
    routing-table=main scope=30 suppress-hw-offload=no target-scope=10
/ipv6 firewall address-list
add address=::/128 comment="defconf: unspecified address" list=bad_ipv6
add address=::1/128 comment="defconf: lo" list=bad_ipv6
add address=fec0::/10 comment="defconf: site-local" list=bad_ipv6
add address=::ffff:0.0.0.0/96 comment="defconf: ipv4-mapped" list=bad_ipv6
add address=::/96 comment="defconf: ipv4 compat" list=bad_ipv6
add address=100::/64 comment="defconf: discard only " list=bad_ipv6
add address=2001:db8::/32 comment="defconf: documentation" list=bad_ipv6
add address=2001:10::/28 comment="defconf: ORCHID" list=bad_ipv6
add address=3ffe::/16 comment="defconf: 6bone" list=bad_ipv6
/ipv6 firewall filter
add action=accept chain=input comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
    invalid
add action=accept chain=input comment="defconf: accept ICMPv6" protocol=\
    icmpv6
add action=accept chain=input comment="defconf: accept UDP traceroute" port=\
    33434-33534 protocol=udp
add action=accept chain=input comment=\
    "defconf: accept DHCPv6-Client prefix delegation." dst-port=546 protocol=\
    udp src-address=fe80::/10
add action=accept chain=input comment="defconf: accept IKE" dst-port=500,4500 \
    protocol=udp
add action=accept chain=input comment="defconf: accept ipsec AH" protocol=\
    ipsec-ah
add action=accept chain=input comment="defconf: accept ipsec ESP" protocol=\
    ipsec-esp
add action=accept chain=input comment=\
    "defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
add action=drop chain=input comment=\
    "defconf: drop everything else not coming from LAN" in-interface-list=\
    !LAN
add action=accept chain=forward comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
    connection-state=invalid
add action=drop chain=forward comment=\
    "defconf: drop packets with bad src ipv6" src-address-list=bad_ipv6
add action=drop chain=forward comment=\
    "defconf: drop packets with bad dst ipv6" dst-address-list=bad_ipv6
add action=drop chain=forward comment="defconf: rfc4890 drop hop-limit=1" \
    hop-limit=equal:1 protocol=icmpv6
add action=accept chain=forward comment="defconf: accept ICMPv6" protocol=\
    icmpv6
add action=accept chain=forward comment="defconf: accept HIP" protocol=139
add action=accept chain=forward comment="defconf: accept IKE" dst-port=\
    500,4500 protocol=udp
add action=accept chain=forward comment="defconf: accept ipsec AH" protocol=\
    ipsec-ah
add action=accept chain=forward comment="defconf: accept ipsec ESP" protocol=\
    ipsec-esp
add action=accept chain=forward comment=\
    "defconf: accept all that matches ipsec policy" ipsec-policy=in,ipsec
add action=drop chain=forward comment=\
    "defconf: drop everything else not coming from LAN" in-interface-list=\
    !LAN

And this is how my android setup looks like:

As you can see - no packets flow. Rebooted mt several times. Clueless at this point.

If the peer is an android phone that will move around in a Roadwarrior fashion, you should not be setting the endpoint-port for it.

Removed port as suggested - no change.