Problem with wireguard

Hi!

I’m trying to configure wireguard vpn on my mikroitk. But when I try to connect from 2 and more peer. I have trouble with connections. I can see successful handshake, but internet still works only on first connection peer.

# 2023-08-30 16:00:04 by RouterOS 7.12beta3
# software id = YL68-7YYE
#
# model = RB2011UiAS-2HnD
# serial number = 7A67082B91C6
/interface bridge
add admin-mac=CC:2D:E0:14:EE:09 auto-mac=no comment=defconf name=bridge
/interface ethernet
set [ find default-name=ether1 ] mac-address=60:31:97:3C:9E:64
/interface wireguard
add listen-port=13231 mtu=1420 name=wireguard1
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
add authentication-types=wpa2-psk mode=dynamic-keys name=profile1 \
    supplicant-identity=""
/interface wireless
set [ find default-name=wlan1 ] band=2ghz-b/g/n channel-width=20/40mhz-XX \
    disabled=no distance=indoors frequency=auto installation=indoor mode=\
    ap-bridge security-profile=profile1 ssid=Viteb_House wireless-protocol=\
    802.11
/ip pool
add name=dhcp ranges=192.168.0.10-192.168.0.254
/ip dhcp-server
add address-pool=dhcp interface=bridge lease-time=10m name=defconf
/port
set 0 name=serial0
/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=ether6
add bridge=bridge comment=defconf interface=ether7
add bridge=bridge comment=defconf interface=ether8
add bridge=bridge comment=defconf interface=ether9
add bridge=bridge comment=defconf interface=ether10
add bridge=bridge comment=defconf interface=sfp1
add bridge=bridge comment=defconf interface=wlan1
/ip neighbor discovery-settings
set discover-interface-list=LAN
/interface list member
add comment=defconf interface=bridge list=LAN
add comment=defconf interface=ether1 list=WAN
/interface wireguard peers
add allowed-address=0.0.0.0/0 comment="iphone Andrey" interface=wireguard1 \
    persistent-keepalive=10s public-key=\
    "W0RmYW0PMfYB377mrUi4w2Q+pwfiFklne3FEmQDmRhg="
add allowed-address=0.0.0.0/0 interface=wireguard1 persistent-keepalive=10s \
    public-key="xhXxO1ZUU9agbVi+f8D0kIimAUQysQSpauK7zZEXUxQ="
add allowed-address=0.0.0.0/0 interface=wireguard1 persistent-keepalive=10s \
    public-key="foiAlsF0diVTNmG7CMOmZxtJNvMiQC4fKikxeCram1Y="
add allowed-address=0.0.0.0/0 interface=wireguard1 persistent-keepalive=10s \
    public-key="iSciqNSlIyI1/SrU+reXRusnp7xpnT+RStlBdYjYokY="
add allowed-address=0.0.0.0/0 comment="xiaomi andrey" interface=wireguard1 \
    persistent-keepalive=10s public-key=\
    "EYhX8ib7yjuY1zLYcKmic0oHEfy0VIyjIeBmLj1d0AU="
/ip address
add address=192.168.0.1/24 comment=defconf interface=bridge network=\
    192.168.0.0
add address=174.16.0.1/24 interface=wireguard1 network=174.16.0.0
add address=174.16.1.1/24 interface=wireguard1 network=174.16.1.0
/ip cloud
set ddns-enabled=yes
/ip dhcp-client
add comment=defconf interface=ether1
/ip dhcp-server network
add address=192.168.0.0/24 comment=defconf dns-server=192.168.0.1 gateway=\
    192.168.0.1 netmask=24
/ip dns
set allow-remote-requests=yes
/ip dns static
add address=192.168.0.1 comment=defconf name=router.lan
/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="winbox internet" dst-port=8291 \
    protocol=tcp
add action=accept chain=input comment=wireguard dst-port=13231 \
    in-interface-list=WAN 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 upnp
set enabled=yes
/ip upnp interfaces
add interface=bridge type=internal
add interface=ether1 type=external
/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/Moscow
/system note
set show-at-login=no
/system package update
set channel=testing
/tool mac-server
set allowed-interface-list=LAN
/tool mac-server mac-winbox
set allowed-interface-list=LAN

And additional question. How use new command wg-add-client, I cant understand what need write in this fields .

/interface/wireguard/wg-add-client  
client-address: 
endpoint-address: 
number:

You cannot have multiple peers and use an allowed IP of 0.0.0.0/0 on the router. This is why the first connected client works but the others don’t. The router is being told to send ALL traffic to the peer (the first connected) and so it all goes to peer1 and to no one else. Instead you need to set the allowed IP for each peer to the wireguard IPs that are assigned to each client. Then on your client set the allowed IP to 0.0.0/0. Of course on the router side you need to make sure your firewall and NAT rules allow traffic to flow as you desire.

Assuming your MT Router acts as the server for the handshake and you have remote users coming in as clients, then your config is, as noted, in error.
Each wireguard client device (aka remote user) should have on THEIR settings for peer settings.
a. 0.0.0.0/0 if they plan on going out the internet and possibly reach LAN devices and possibly configure router (depends upon firewall rules)
b. LANSUBNET if they plan on only going to LAN devices
c. WIREGUARD Subnet if only for admin to configure router.

Also client devices on their peer setting need keep alive settings.

++++++++
The router peer settings should be the wireguard address of the client devices ip/32
NO requirement for keep alive on router.

Gabacho pointed out the importance of how ALLOWED IPs works in the wireguard process.
lite reading here: https://forum.mikrotik.com/viewtopic.php?t=182340

corrected it to:

/interface wireguard peers
add allowed-address=174.16.0.3/32 comment="iphone Andrey" interface=\
    wireguard1 persistent-keepalive=10s public-key=\
    "W0RmYW0PMfYB377mrUi4w2Q+pwfiFklne3FEmQDmRhg="
add allowed-address=174.16.0.105/32 comment="Notebook Misha" interface=\
    wireguard1 persistent-keepalive=10s public-key=\
    "xhXxO1ZUU9agbVi+f8D0kIimAUQysQSpauK7zZEXUxQ="
add allowed-address=174.16.0.106/32 comment="TV Xiaomi " interface=wireguard1 \
    persistent-keepalive=10s public-key=\
    "foiAlsF0diVTNmG7CMOmZxtJNvMiQC4fKikxeCram1Y="
add allowed-address=174.16.0.104/32 comment="iphone Misha" interface=\
    wireguard1 persistent-keepalive=10s public-key=\
    "iSciqNSlIyI1/SrU+reXRusnp7xpnT+RStlBdYjYokY="
add allowed-address=174.16.0.4/32 comment="xiaomi andrey" interface=\
    wireguard1 persistent-keepalive=10s public-key=\
    "EYhX8ib7yjuY1zLYcKmic0oHEfy0VIyjIeBmLj1d0AU="

And It’s work Thanks.

I fixed only on router and nothing on client.

What about new command? (wg-add-client)
what the number?

You didnt read my post…
You DONT NEED KEEP ALIVE on the router settings, its a setting for your mobile users on their peer settings.

I changed it before, it was previous config.