OpenVPN, NAT, access vpn-devices from lan

Hello,

I configured a OpenVPN Server on my OpenWRT-Router. As I testet, a client can connect to my OpenVPN-Server and access to the Internet is possible and even connecting to lan-devices.

But the other way it doesnt work. Which means, my lan-devices cannot ping the vpn-device. I guess there should be some configuration about NAT or firewall on the openwrt-router. I tried a lot but its not more than try and error. So maybe you can give me an advice how to solve my task.

So I need to connect my lan 192.168.0.0/24 with my vpn 10.21.173.0/24 on the openwrt-device.

Thanks so long
/dafosy

Please 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; \
uci export network; uci export dhcp; uci export firewall; \
head -n -0 /etc/firewall.user; \
ip -4 addr ; ip -4 ro li tab all ; ip -4 ru
1 Like

Hello trendy,

thanks for your reply. I attached the output:

My local router has 192.168.0.2
(the reason is the switch from an old router to the new one years ago and I didnt changed back to 192.168.0.1)

My openvpn router address is 10.21.173.1
A working vpn-client ist 10.21.173.6

My ISP-Adress ist xx.xx.x.xxx

IPv6 Iam not using.

I hope you see easly the reason for not getting a ping by start the request in 192.168.0.0/24 and try to reach 10.21.173.0/24. The ping from 192.168.0.2 to 10.21.173.6 works.

So long
dafosy

root@OpenWrt:/tmp/yamon# ubus call system board; \
> uci export network; uci export dhcp; uci export firewall; \
> head -n -0 /etc/firewall.user; \
> ip -4 addr ; ip -4 ro li tab all ; ip -4 ru
{
        "kernel": "4.14.180",
        "hostname": "OpenWrt",
        "system": "ARMv7 Processor rev 0 (v7l)",
        "model": "Netgear Nighthawk X4S R7800",
        "board_name": "netgear,r7800",
        "release": {
                "distribution": "OpenWrt",
                "version": "19.07.3",
                "revision": "r11063-85e04e9f46",
                "target": "ipq806x/generic",
                "description": "OpenWrt 19.07.3 r11063-85e04e9f46"
        }
}
package network

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'xxxx:xxxx:xxxx::/48'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth1.1'
        option proto 'static'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option gateway '192.168.0.2'
        list dns '192.168.0.2'
        option ipaddr '192.168.0.2'

config interface 'wan'
        option ifname 'eth0.2'
        option proto 'dhcp'

config interface 'wan6'
        option ifname 'eth0.2'
        option proto 'dhcpv6'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option ports '1 2 3 4 6t'

config switch_vlan
        option device 'switch0'
        option vlan '2'
        option ports '5 0t'

config interface 'vpn0'
        option ifname 'tun0'
        option proto 'none'
        option auto '1'

package 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 authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.auto'
        option nonwildcard '1'
        option localservice '1'

config dhcp 'lan'
        option interface 'lan'
        option dhcpv6 'server'
        option ra 'server'
        option ra_management '1'
        option start '50'
        option leasetime '12h'
        option limit '200'

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'

package firewall

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

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

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 src_ip 'fc00::/6'
        option dest_ip 'fc00::/6'
        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'

config include
        option path '/etc/firewall.user'

config rule
        option name 'Allow-OpenVPN-Inbound'
        option target 'ACCEPT'
        option src '*'
        option proto 'udp'
        option dest_port '1194'

config zone
        option name 'vpn'
        option input 'ACCEPT'
        option forward 'REJECT'
        option output 'ACCEPT'
        option network 'vpn0'

config forwarding
        option src 'vpn'
        option dest 'wan'

config forwarding
        option src 'vpn'
        option dest 'lan'

# This file is interpreted as shell script.
# Put your custom iptables rules here, they will
# be executed with each firewall (re-)start.

# Internal uci firewall chains are flushed and recreated on reload, so
# put custom rules into the root chains e.g. INPUT or FORWARD or into the
# special user chains, e.g. input_wan_rule or postrouting_lan_rule.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
7: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    inet 192.168.0.2/24 brd 192.168.0.255 scope global br-lan
       valid_lft forever preferred_lft forever
9: eth0.2@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP qlen 1000
    inet xx.xx.x.xxx/24 brd xx.xx.x.255 scope global eth0.2
       valid_lft forever preferred_lft forever
11: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN qlen 100
    inet 10.21.173.1 peer 10.21.173.2/32 scope global tun0
       valid_lft forever preferred_lft forever
default via xx.xx.x.xxx dev eth0.2  src xx.xx.x.xxx 
10.21.173.0/29 via 10.21.173.2 dev tun0 
10.21.173.2 dev tun0 scope link  src 10.21.173.1 
xx.xx.x.x/24 dev eth0.2 scope link  src xx.xx.x.xxx 
192.168.0.0/24 dev br-lan scope link  src 192.168.0.2 
local 10.21.173.1 dev tun0 table local scope host  src 10.21.173.1 
broadcast xx.xx.x.x dev eth0.2 table local scope link  src xx.xx.x.xxx 
local xx.xx.x.xxx dev eth0.2 table local scope host  src xx.xx.x.xxx 
broadcast xx.xx.x.xxx dev eth0.2 table local scope link  src xx.xx.x.xxx 
broadcast 127.0.0.0 dev lo table local scope link  src 127.0.0.1 
local 127.0.0.0/8 dev lo table local scope host  src 127.0.0.1 
local 127.0.0.1 dev lo table local scope host  src 127.0.0.1 
broadcast 127.255.255.255 dev lo table local scope link  src 127.0.0.1 
broadcast 192.168.0.0 dev br-lan table local scope link  src 192.168.0.2 
local 192.168.0.2 dev br-lan table local scope host  src 192.168.0.2 
broadcast 192.168.0.255 dev br-lan table local scope link  src 192.168.0.2 
0:      from all lookup local 
32766:  from all lookup main 
32767:  from all lookup default 
root@OpenWrt:/tmp/yamon# 

Consider to use topology subnet and client-to-client.
Otherwise you need to push/add the routes manually on every VPN client and utilize NAT on OpenWrt.
To avoid NAT, configure site-to-site connection.

Hello vgaetera,

thanks for reply. Could you be a bit more precise.

Two days ago a added to /etc/config/openvpn the line "option route 192.168.0.0 255.255.255.0" and I ended in the failsafe mode to recover the router.

So what do you recommend:
(1) In the Open-WRT GUI - VPN - OpenVPN - VPN Iam already check the box "client-to-client".
(2) where do I find "topology subnet" and what do I write in the box? 192.168.0.0/24?
(3) Where do I configure side-to-side connections?

Sorry for all the questions. I read a lot and be proud that OpenVPN works somehow, but for deeper configuration I need a bit help.
I just switched from DD-WRT to OpenWRT and even OpenVPN has a bit more configuration-options.

So long
dafosy

From lan interface remove

There is no forwarding from lan to vpn zone in firewall. You have only the vpn->lan.

1 Like

So I removed

        option gateway '192.168.0.2'
        list dns '192.168.0.2'

and added vpn-forwarding as attached.

Unfortunately it doesnt work ether. During a look to "route -n" I found the following, may this cause the problem?

root@OpenWrt:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         xx.xx.x.xxx     0.0.0.0         UG    0      0        0 eth0.2
10.21.173.0     10.21.173.2     255.255.255.248 UG    0      0        0 tun0
10.21.173.2     0.0.0.0         255.255.255.255 UH    0      0        0 tun0
xx.xx.x.x       0.0.0.0         255.255.255.0   U     0      0        0 eth0.2
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 br-lan

I cant remember to define

gateway 10.21.173.2

somewhere. Where did it come from in this Routing List?

/dafosy

It is coming from the VPN tunnel.
Paste here the VPN configuration to verify it is fine. Also which address are you trying to ping?

Sorry for my delay.

Here is my openvpn-config:

config openvpn 'dafosyVPN4'
        option comp_lzo 'yes'
        option keepalive '10 60'
        option ca '/etc/openvpn/ca.crt'
        option dh '/etc/openvpn/dh.pem'
        option cert '/etc/openvpn/cert.pem'
        option key '/etc/openvpn/key.pem'
        option log '/var/log/openvpn.log'
        option log_append '/var/log/openvpn.log'
        option enabled '1'
        option verb '3'
        option tls_server '1'
        option tls_auth '/etc/openvpn/ta.key'
        option auth 'SHA256'
        option key_direction '0'
        option mode 'server'
        option status '/var/run/openvpn.status 5'
        option client_to_client '1'
        option duplicate_cn '1'
        option cipher 'AES-256-CBC'
        list tls_cipher 'TLS-DHE-RSA-WITH-AES-128-CBC-SHA'
        option ifconfig '10.21.173.1 255.255.255.248'
        option client_config_dir '/etc/openvpn/ccd'
        option port '1194'
        option dev 'tun'
        option server '10.21.173.0 255.255.255.248'

I connect with my windows-maschine 10.21.173.6 to the openvpn-network. As I told you, this network is working for internet-purposes. A ping from my local-ubuntu-maschine 192.168.0.4 to 10.21.173.6 doesnt work. The other way it is working.

Make sure to explicitly allow pings for non-local subnets in the Windows firewall settings.

1 Like