Help about setting a wireguard client on routeros.

I’m tried to set up set up wireguard VPN on my rb4011, but it didn’t work, help needed.
Below is the configuration file I download from vpn provider:

[Interface]
PrivateKey=[int_privatekey=]
Address=172.18.x.y
DNS=69.25.114.211,69.25.114.213
[Peer]
PublicKey=[peer_publickey=]
AllowedIPs=0.0.0.0/0
Endpoint=wg.vpnserver.com:51820
PersistentKeepalive=21

Router configuration:

/interface wireguard
add listen-port=48172 mtu=1420 name=wg_pure
/interface wireguard peers
add allowed-address=0.0.0.0/0 endpoint-address=wg.vpnserver.com endpoint-port=51820 \
    interface=wg_pure persistent-keepalive=21s public-key="[peer_publickey=]"
    
/ip address
add address=192.168.88.1/24 comment=defconf interface=bridge network=192.168.88.0
add address=172.18.x.y interface=wg_pure network=172.18.x.y
/ip route
add dst-address=0.0.0.0/0 gateway=wg_pure routing-table=wg_pure

/routing table
add fib name=wg_pure
 
/ip firewall nat
add action=masquerade chain=srcnat disabled=no out-interface=wg_pure
/ip/firewall/mangle
 add action=mark-routing chain=prerouting connection-mark=no-mark \
    dst-address-list=vpn dst-address-type=!local new-routing-mark=wg_pure \
    passthrough=yes

The wireguard interface is running, I torched the wireguard interface, there is only tx tranfic. Do I have enough information from the configuration file, or there are mistakes in router config?

Any words is appreciated!

Hi there,so,
Lets look at what the VPN provider has given you.

  1. Private KEY ---------> You are to use this as your private key on the MT. This will generate a public key which they will already have since they have given you the private key to use.
  2. Address ---------------> Hence you make this your IP address 172.18.x.y/24
  3. Public Key, ----> what you put on the ROUTER peer settings for the VPN provider
  4. Allowed IPs —> clearly what you need to put for your users to access all possible www. addresses.


    YOUR ROUTER>>>>>> another poster with snippets only, if you ask for help, you need to NOT assume you know what I need to see, … the whole config matters in ROS.
    Sorry, I need to see complete config,

/export file=anynameyouwish ( minus router serial number and any public WANIP information )

Why are you mangling???

Thanks for the reply, the configuration will be posted when I back to work.

Why are you mangling???

I‘m in china, the VPN service is used to access websites such as youtube which is blocked by the GFW.

I’m a novice, I set up the VPN client based on a tutorial article from the internet, mangle is used to redirect some traffic to VPN.

/ip/firewall/mangle
 add action=mark-routing chain=prerouting connection-mark=no-mark \
    dst-address-list=!novpn dst-address-type=!local new-routing-mark=to_vpn \
    passthrough=yes

Is there a better way to do that?

I’m even surprised this would work in China. Wireguard is rather easy for an advanced firewall to detect & filter…that might be the reason why you only see “Tx” traffic :frowning:

Hello Mr ZTX ..
so in dst-address-list=vpn , can you tell me what is the IP address that you put in this field..?

In address list VPN, there is IPs of twitter.com, google.com, facebook.com.

The complete config:

# jan/02/2023 12:05:58 by RouterOS 7.6
# software id = 2HJX-8QY4
#
# model = RB2011UiAS-2HnD
# serial number = 
/interface bridge
add admin-mac=E4:8D:8C:1A:1D:AA auto-mac=no comment=defconf name=bridge
/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 ssid=MikroTik-1A1DB3 wireless-protocol=802.11
/interface wireguard
add listen-port=1997 mtu=1420 name=wg_pure
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
/interface wireless security-profiles
set [ find default=yes ] supplicant-identity=MikroTik
/ip pool
add name=default-dhcp ranges=192.168.88.10-192.168.88.254
/ip dhcp-server
add address-pool=default-dhcp interface=bridge name=defconf
/port
set 0 name=serial0
/routing table
add fib name=wg_pure
/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 endpoint-address=sx016388-wg.pointtoserver.com \
    endpoint-port=51820 interface=wg_pure persistent-keepalive=21s \
    public-key="MvQ1EzHQE7hed8yKuhpjCNUbjzSIJB3jaQ50qh40wEU="
/ip address
add address=192.168.88.1/24 comment=defconf interface=bridge network=\
    192.168.88.0
add address=172.18.240.x interface=wg_pure network=172.18.240.0
/ip dhcp-client
add comment=defconf interface=ether1
/ip dhcp-server network
add address=192.168.88.0/24 comment=defconf dns-server=192.168.88.1 gateway=\
    192.168.88.1
/ip dns
set allow-remote-requests=yes
/ip dns static
add address=192.168.88.1 comment=defconf name=router.lan
/ip firewall address-list
add address=1.1.8.0/24 comment=chnips list=novpn
add address=1.2.4.0/24 comment=chnips list=novpn
add address=1.8.1.0/24 comment=chnips list=novpn
add address=1.8.8.0/24 comment=chnips list=novpn
add address=1.12.0.0/14 comment=chnips list=novpn
... ...


/ip 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 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 mangle
add action=mark-connection chain=prerouting connection-mark=no-mark \
    dst-address-list=!novpn dst-address-type=!local new-connection-mark=\
    wg_pure
add action=mark-routing chain=prerouting connection-mark=wg_pure \
    new-routing-mark=wg_pure
/ip firewall nat
add action=masquerade chain=srcnat comment="defconf: masquerade" \
    ipsec-policy=out,none out-interface-list=WAN
add action=masquerade chain=srcnat out-interface=wg_pure
/ip route
add dst-address=0.0.0.0/0 gateway=wg_pure routing-table=wg_pure
/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=Asia/Shanghai
/system routerboard settings
set silent-boot=yes
/tool mac-server
set allowed-interface-list=LAN
/tool mac-server mac-winbox
set allowed-interface-list=LAN

/ip/firewall/connection/print:

Flags: S - SEEN-REPLY; A - ASSURED; C - CONFIRMED; F - FASTTRACK; s - SRCNAT
Columns: PROTOCOL, SRC-ADDRESS, DST-ADDRESS, TCP-STATE, TIMEOUT, ORIG-RATE, REPL-RATE, ORIG-PACKETS, REPL-PACKETS, ORIG-BYTES, REPL-BYTES
 #       PROTOCOL  SRC-ADDRESS           DST-ADDRESS            TCP-STATE    TIMEOUT    ORIG-RATE  REPL-RATE  ORIG-PACKETS  REPL-PACKETS  ORIG-BYTES   REPL-BYTES
26   C   udp       192.168.7.226:1997    69.25.114.212:51820                 7s         0bps       0bps                 19             0       3 344            0

Please help, Thanks!