Hi, been spending 2 days on this already, requesting help, deeply apologize for the long post in advance.
In country A : On a freshly installed OpenWRT on WRT1900AC router, I configured Wireguard through the luci UI as a server. The ISP here gives me public IPv4 address, and I can do NAT to forward Wireguard server port from modem to the OpenWRT router.
Country A does censor internet though.
In country B : There is no censorship, but ISP doesn't provide public IP adress and has something called CGNAT that doesn't allow me to host the Wireguard server. So I want to setup a OpenWRT router as Wireguard peer, let's call it Peer1, and have all traffic coming from peers in Country A routed through this Peer1.
There will be multiple peers :
- Some devices in Country A will be on the same site (same downstream subnet) as router hosting the Wiregaurd Server, so they won't need to have any Wireguard client installed.
- Some other devices will be in Country A but will need to have Wireguard installed as regular peers (say a smartphone). Their traffic will also need to be routed through Peer1, to escape censorship
- No other peers will be in Country B, but ideally devices downstream in the subnet of the OpenWRT router hosting PeerX will need to be reachable from the OpenWRT wireguard server router. I can expand more on this requirement if needed.
So I setup Wireguard Server router on a freshly installed WRT1900AC, and generated Peer1 configuration that I installed on a Win10 Wireguard client (for testing, when everything OK I will install that configuration on another router and ship it to Country B).
I setup another peer as say PeerX. But everytime PeerX is connected to the Wireguard server, its traffic is routed through the server, not Peer1.
I tried to follow recommendations made on this post : https://serverfault.com/questions/1074729/route-all-traffic-through-wireguard-peer
but I have trouble understanding where to put the parameter Table=off in OpenWRT, can't seem to find a conf file to modify... Couldn't also find where to put PostUp and PostDown commands, so I entered the following commands manually via ssh on the router :
ip rule add iif wg0 from 192.168.121.0/24 lookup 200
ip route add default via 192.168.121.3 dev wg0 table 200
But no success, peers connect successfully, can browse the internet, but traffic gets routed only through the server...
On the Wireguard server, I followed online guide with the following conf below.
Relevant Wireguard server conf on first OpenWRT router:
interface wg0 created through luci UI, with MTU = 1360 (that's the MTU that worked best through all the testing I did)
IP Adresses = 192.168.121.1/24
No host Routes unchecked
Use default gateway checked
Firewall settings : the tutorial suggested to put the wg0 interface in the same zone as lan
Metric = 20 (WAN interface was set as metric 10)
Peers configuration on the server :
Peer1 :
Allowed IPs = 192.168.121.3/32, 0.0.0.0/0
Route Allowed IPs checked
PeerX :
Allowed IPs = 192.168.121.2/32
Route Allowed IPs checked
Peer1 configuration :
[Interface]
PrivateKey = xxxx
Address = 192.168.121.3/32
DNS = 192.168.21.1 (this .21 subnet is the subnet used by the OpenWRT WGserver router on its lan interface)
MTU = 1360
[Peer]
PublicKey = yyyy
AllowedIPs = 192.168.121.0/24,192.168.21.0/24 (this .21 subnet is the subnet used by the OpenWRT WGserver router on its lan interface)
Endpoint = MY_COUNTRY_B_PUBLIC_IP:PORT
PersistentKeepalive = 25
PeerX configuration :
[Interface]
PrivateKey = zzzzz
Address = 192.168.121.2/32
DNS = 192.168.21.1 (this .21 subnet is the subnet used by the OpenWRT WGserver router on its lan interface)
MTU = 1360
[Peer]
PublicKey = yyyy
AllowedIPs = 0.0.0.0/0, 192.168.121.0/24, 192.168.21.0/24 (this .21 subnet is the subnet used by the OpenWRT WGserver router on its lan interface)
Endpoint = MY_COUNTRY_B_PUBLIC_IP:PORT
PersistentKeepalive = 25
/etc/config/network output :
config interface 'loopback'
option device 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config globals 'globals'
option ula_prefix 'fd2a:4aeb:05c6::/48'
option packet_steering '1'
config device
option name 'br-lan'
option type 'bridge'
list ports 'lan1'
list ports 'lan2'
list ports 'lan3'
list ports 'lan4'
config interface 'lan'
option device 'br-lan'
option proto 'static'
option netmask '255.255.255.0'
option ip6assign '60'
option ipaddr '192.168.21.1'
config device
option name 'wan'
option macaddr 'c2:56:27:7b:c2:27'
config interface 'wan'
option device 'wan'
option proto 'dhcp'
option metric '10'
config interface 'wan6'
option device 'wan'
option proto 'dhcpv6'
option reqaddress 'try'
option reqprefix 'auto'
option metric '11'
config interface 'wg0'
option proto 'wireguard'
option private_key 'REDACTED'
option listen_port 'REDACTED'
list dns '192.168.21.1'
list addresses '192.168.121.1/24'
option metric '20'
option mtu '1360'
config wireguard_wg0
option description 'PeerX'
option public_key 'REDACTED'
option private_key 'REDACTED'
option route_allowed_ips '1'
option persistent_keepalive '25'
list allowed_ips '192.168.121.2/32'
list allowed_ips '0.0.0.0/0'
config wireguard_wg0
option description 'Peer1'
option public_key 'REDACTED'
option private_key 'REDACTED'
list allowed_ips '192.168.121.3/32'
list allowed_ips '0.0.0.0/0'
option route_allowed_ips '1'
option persistent_keepalive '25'
/etc/config/firewall output :
config defaults
option syn_flood '1'
option input 'ACCEPT'
option output 'ACCEPT'
option forward 'REJECT'
config zone
option name 'lan'
option input 'ACCEPT'
option output 'ACCEPT'
option forward 'ACCEPT'
list network 'lan'
list network 'wg0'
config zone
option name 'wan'
list network 'wan'
list network 'wan6'
option input 'REJECT'
option output 'ACCEPT'
option forward 'REJECT'
option masq '1'
option mtu_fix '1'
config forwarding
option src 'lan'
option dest 'wan'
config rule
option name 'Allow-DHCP-Renew'
option src 'wan'
option proto 'udp'
option dest_port '68'
option target 'ACCEPT'
option family 'ipv4'
config rule
option name 'Allow-Ping'
option src 'wan'
option proto 'icmp'
option icmp_type 'echo-request'
option family 'ipv4'
option target 'ACCEPT'
config rule
option name 'Allow-IGMP'
option src 'wan'
option proto 'igmp'
option family 'ipv4'
option target 'ACCEPT'
config rule
option name 'Allow-DHCPv6'
option src 'wan'
option proto 'udp'
option dest_port '546'
option family 'ipv6'
option target 'ACCEPT'
config rule
option name 'Allow-MLD'
option src 'wan'
option proto 'icmp'
option src_ip 'fe80::/10'
list icmp_type '130/0'
list icmp_type '131/0'
list icmp_type '132/0'
list icmp_type '143/0'
option family 'ipv6'
option target 'ACCEPT'
config rule
option name 'Allow-ICMPv6-Input'
option src 'wan'
option proto 'icmp'
list icmp_type 'echo-request'
list icmp_type 'echo-reply'
list icmp_type 'destination-unreachable'
list icmp_type 'packet-too-big'
list icmp_type 'time-exceeded'
list icmp_type 'bad-header'
list icmp_type 'unknown-header-type'
list icmp_type 'router-solicitation'
list icmp_type 'neighbour-solicitation'
list icmp_type 'router-advertisement'
list icmp_type 'neighbour-advertisement'
option limit '1000/sec'
option family 'ipv6'
option target 'ACCEPT'
config rule
option name 'Allow-ICMPv6-Forward'
option src 'wan'
option dest '*'
option proto 'icmp'
list icmp_type 'echo-request'
list icmp_type 'echo-reply'
list icmp_type 'destination-unreachable'
list icmp_type 'packet-too-big'
list icmp_type 'time-exceeded'
list icmp_type 'bad-header'
list icmp_type 'unknown-header-type'
option limit '1000/sec'
option family 'ipv6'
option target 'ACCEPT'
config rule
option name 'Allow-IPSec-ESP'
option src 'wan'
option dest 'lan'
option proto 'esp'
option target 'ACCEPT'
config rule
option name 'Allow-ISAKMP'
option src 'wan'
option dest 'lan'
option dest_port '500'
option proto 'udp'
option target 'ACCEPT'