OpenWRT with mobile Internet Wireguard VPN

Hello, i have an OpenWRT with mobile Internet and want a Wireguard VPN Tunnel to it with Acces to the Internet. I have a VDS from a Host but how can i do it is there a Step by Step for this Situation. Thank you guys.

https://openwrt.org/docs/guide-user/services/vpn/wireguard/start

i know how to make a normal Tunnel if the OpenWRT is not behind a NAT and i can Open Ports, but with Mobile Internet its not possible to Open Ports

You only need to open the port on the 'server' side -- so you make the VPS (which should have a public IP -- I hope??) your server and the other side (mobile) becomes the 'client' side (no ports need to be opened on that side).

So, i will make a Wireguard Server on my VDS, making a Client conf. for OpenWRT? What i have to with iptables on VDS? and on OpenWRT Router with Client conf? i want at least, that every Client from the Server should have the IP from my mobile Internet. Not from the VDS because its in another Country.

Is your VDS/VPS running OpenWrt?

I assume your local device is running OpenWrt?

You'll setup the remote peer (VDS/VPS) is the 'server' and your local device can follow the 'client' configuration. When properly configured, your local device will then have an apparent public IP address of the VDS/VPS, and all the traffic of the devices behind the local device will be routed through the tunnel and out the VDS/VPS IP address.

I don't really understand what you're asking here, but I think I have an idea of what you want.

To make this clear -- your OpenWrt router will have an address issued by the ISP. Usually it is just one IPv4 address. All of your other devices (behind the router) share that single address.

If you want to have some devices (or services/sites) routed out the regular wan and others routed via the tunnel, that is done with Policy Based Routing.

VDS is Ubuntu 22.04, with static IP, OpenWRT is local device :slight_smile: with mobile Internet, idk how to make those routings etc. Thats what i am asking for :blush: Is there a Step by Step?

I want, that i can make a VPN to my OpenWRT Router, That every Client can use the Internet from the OpenWRT Router, problem my Router is behind a NAT so i cant just Open a Wireguard Server on it.

Ok... start by setting up the wireguard 'server' on the VDS, and then the 'client' on the local OpenWrt device. The configuration of Ubuntu is out of scope for this forum, so if you need help on that, please ask on other forums (for Ubuntu, Wireguard, or general sites -- this one is specific to OpenWrt).

You'll then need the configuration details to connect to the WG 'server' on your VDS -- we can help you with the OpenWrt configuration to get that working (read the 'client' config documentation in the link I provided earlier, ask for help if/when you get stuck).

Once that is up and running, you can move on to policy based routing if you need different devices/services handled differently once the tunnel is running.
https://openwrt.org/docs/guide-user/network/routing/pbr

As I said before, your OpenWrt router is going to be in 'client' mode so it doesn't need to have any ports opened.

i got everything i think with iptables on Linux Server, but the Client in OpenWRT when i am connected it dont get Internet ...anymore

Please connect to your OpenWrt device using ssh and copy the output of the following commands and post it here using the "Preformatted text </> " button:
grafik
Remember to redact passwords, MAC addresses and any public IP addresses you may have:

ubus call system board
cat /etc/config/network
cat /etc/config/wireless
cat /etc/config/dhcp
cat /etc/config/firewall
wg show
root@OpenWrt:~# ubus call system board
{
        "kernel": "5.15.137",
        "hostname": "OpenWrt",
        "system": "xRX200 rev 1.2",
        "model": "AVM FRITZ!Box 7430",
        "board_name": "avm,fritz7430",
        "rootfs_type": "squashfs",
        "release": {
                "distribution": "OpenWrt",
                "version": "23.05.2",
                "revision": "r23630-842932a63d",
                "target": "lantiq/xrx200",
                "description": "OpenWrt 23.05.2 r23630-842932a63d"
        }
}
root@OpenWrt:~# cat /etc/config/network

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 'fd5b:f52d:6dfc::/48'

config atm-bridge 'atm'
        option vpi '1'
        option vci '32'
        option encaps 'llc'
        option payload 'bridged'
        option nameprefix 'dsl'

config dsl 'dsl'
        option annex 'b'
        option tone 'av'
        option ds_snr_offset '0'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'lan2'
        list ports 'lan3'
        list ports 'lan4'

config device
        option name 'lan1'
        option macaddr 'E8:DF:70:3E:46:A3'

config device
        option name 'lan2'
        option macaddr 'E8:DF:70:3E:46:A3'

config device
        option name 'lan3'
        option macaddr 'E8:DF:70:3E:46:A3'

config device
        option name 'lan4'
        option macaddr 'E8:DF:70:3E:46:A3'

config interface 'lan'
        option device 'lan1'
        option proto 'dhcp'

config device
        option name 'dsl0'
        option macaddr 'E8:DF:70:3E:46:A6'

config interface 'wan'
        option device 'dsl0'
        option proto 'pppoe'
        option username 'username'
        option password 'password'
        option ipv6 '1'

config interface 'wan6'
        option device '@wan'
        option proto 'dhcpv6'

config interface 'lan2'
        option proto 'static'
        option device 'br-lan'
        option ipaddr '192.168.30.1'
        option netmask '255.255.255.0'

config interface 'wg0'
        option proto 'wireguard'
        option private_key '-='
        list addresses '10.0.0.2/32'
        list addresses 'fd42:42:42::2/128'
        list dns '1.1.1.1'
        list dns '1.0.0.1'

config wireguard_wg0
        option description 'Gateway Client'
        option public_key '-'
        option preshared_key 'u-'
        option endpoint_host '45.59.70.159'
        option endpoint_port '51820'
        option route_allowed_ips '1'
        list allowed_ips '0.0.0.0/0'

root@OpenWrt:~# cat /etc/config/wireless

config wifi-device 'radio0'
        option type 'mac80211'
        option path 'pci0000:00/0000:00:00.0/0000:01:00.0'
        option channel 'auto'
        option band '2g'
        option cell_density '0'
        option country 'DE'
        option legacy_rates '1'
        option disabled '0'

config wifi-iface 'wifinet0'
        option device 'radio0'
        option mode 'ap'
        option ssid 'OpenWrt7430'
        option encryption 'psk'
        option key '-'
        option network 'lan2'

root@OpenWrt:~# cat /etc/config/dhcp

config dnsmasq
        option domainneeded '1'
        option boguspriv '1'
        option filterwin2k '0'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option nonegcache '0'
        option cachesize '1000'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto'
        option nonwildcard '1'
        option localservice '1'
        option ednspacket_max '1232'
        option filter_aaaa '0'
        option filter_a '0'

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv4 'server'
        option dhcpv6 'hybrid'
        option ra 'hybrid'
        list ra_flags 'managed-config'
        list ra_flags 'other-config'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'
        option loglevel '4'

config dhcp 'lan2'
        option interface 'lan2'
        option start '100'
        option limit '150'
        option leasetime '12h'

root@OpenWrt:~# cat /etc/config/firewall

config defaults
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'

config zone
        option name 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        list network 'lan2'

config zone
        option name 'wan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        option masq '1'
        option mtu_fix '1'
        list network 'lan'

config forwarding
        option src 'lan'
        option dest 'wan'

config zone
        option name 'VPN'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        list network 'wg0'
        option masq '1'
        option mtu_fix '1'

config forwarding
        option src 'VPN'
        option dest 'wan'

config rule
        option name 'VPN'
        option src 'VPN'
        option dest 'wan'
        option target 'ACCEPT'

config rule
        option name 'Internet'
        option src 'lan'
        option dest 'wan'
        option target 'ACCEPT'

root@OpenWrt:~# wg show
interface: wg0
  public key: -
  private key: (hidden)
  listening port: 43776

peer: -
  preshared key: (hidden)
  endpoint: endpointadress:51820
  allowed ips: 0.0.0.0/0
  latest handshake: 1 minute, 20 seconds ago
  transfer: 68.89 KiB received, 72.54 KiB sent
root@OpenWrt:~#

The Server can ping the OpenWRT Router and the OpenWRT Router can ping the Server

Your wan firewall zone is very wrong. Why did you change this?

This should be deleted.

There are also many other things missing from the firewall. You should probably restore the default firewall file and then make only the modifications necessary for wg.

The Lan 1 ist the Internet and Lan2, Lan3, Lan4 is Br-lan

That is true for the ports, but the wan networks are called wan and wan6.

The firewall is very messed up and should be restored from the default state.

1 Like
root@OpenWrt:~# ubus call system board
{
        "kernel": "5.15.137",
        "hostname": "OpenWrt",
        "system": "xRX200 rev 1.2",
        "model": "AVM FRITZ!Box 7430",
        "board_name": "avm,fritz7430",
        "rootfs_type": "squashfs",
        "release": {
                "distribution": "OpenWrt",
                "version": "23.05.2",
                "revision": "r23630-842932a63d",
                "target": "lantiq/xrx200",
                "description": "OpenWrt 23.05.2 r23630-842932a63d"
        }
}
root@OpenWrt:~# cat /etc/config/network

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 'fdc6:72ee:9795::/48'

config atm-bridge 'atm'
        option vpi '1'
        option vci '32'
        option encaps 'llc'
        option payload 'bridged'
        option nameprefix 'dsl'

config dsl 'dsl'
        option annex 'b'
        option tone 'av'
        option ds_snr_offset '0'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'lan2'
        list ports 'lan3'
        list ports 'lan4'

config device
        option name 'lan1'
        option macaddr 'E8:DF:70:3E:46:A3'

config device
        option name 'lan2'
        option macaddr 'E8:DF:70:3E:46:A3'

config device
        option name 'lan3'
        option macaddr 'E8:DF:70:3E:46:A3'

config device
        option name 'lan4'
        option macaddr 'E8:DF:70:3E:46:A3'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config device
        option name 'dsl0'
        option macaddr 'E8:DF:70:3E:46:A6'

config interface 'wan'
        option device 'dsl0'
        option proto 'pppoe'
        option username 'username'
        option password 'password'
        option ipv6 '1'

config interface 'wan6'
        option device '@wan'
        option proto 'dhcpv6'

config interface 'lanInternet'
        option proto 'dhcp'
        option device 'lan1'

config interface 'wg0'
        option proto 'wireguard'
        option private_key 'privkey'
        list addresses '10.0.0.2/32'
        list addresses 'fd42:42:42::2/128'
        list dns '1.1.1.1'
        list dns '1.0.0.1'

config wireguard_wg0
        option description 'Imported peer configuration'
        option public_key 'pubkey'
        option preshared_key 'presharedkey'
        list allowed_ips '0.0.0.0/0'
        list allowed_ips '::/0'
        option endpoint_host '45.59.70.159'
        option endpoint_port '51820'

root@OpenWrt:~# cat /etc/config/wireless

config wifi-device 'radio0'
        option type 'mac80211'
        option path 'pci0000:00/0000:00:00.0/0000:01:00.0'
        option channel '36'
        option band '5g'
        option htmode 'HT20'
        option disabled '1'
        option cell_density '0'

config wifi-iface 'default_radio0'
        option device 'radio0'
        option network 'lan'
        option mode 'ap'
        option ssid 'OpenWrt7430'
        option encryption 'psk2'
        option key 'swlankey'

root@OpenWrt:~# cat /etc/config/dhcp

config dnsmasq
        option domainneeded '1'
        option boguspriv '1'
        option filterwin2k '0'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option nonegcache '0'
        option cachesize '1000'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto'
        option nonwildcard '1'
        option localservice '1'
        option ednspacket_max '1232'
        option filter_aaaa '0'
        option filter_a '0'

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv4 'server'
        option dhcpv6 'server'
        option ra 'server'
        option ra_slaac '1'
        list ra_flags 'managed-config'
        list ra_flags 'other-config'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'
        option loglevel '4'

root@OpenWrt:~# cat /etc/config/firewall

config defaults
        option syn_flood '1'
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'

config zone
        option name 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        list network 'lan'

config zone
        option name 'wan'
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option masq '1'
        option mtu_fix '1'
        list network 'wan'
        list network 'wan6'
        list network 'lanInternet'

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'

root@OpenWrt:~# wg show
interface: wg0
  public key: pub key
  private key: (hidden)
  listening port: 41655

peer: key
  preshared key: (hidden)
  endpoint: endpointadress:51820
  allowed ips: 0.0.0.0/0, ::/0

Voila now its Original

Ok. Now add a new zone for wg as you had done previously and add forwarding form lan to wg.

like this ?

Yes. And turn on masquerading.