Issue with firewall/routing with OpenVPN client connected

Hi There,

I have an issue where I have configured my router with a PPPOE (wan) interface and an OpenVPN (tun) interface. For the OpenVPN connection I have created a separate interface and zone specifically for the connection to AirVPN.

All is working fine. However the problem I have is that when the OpenVPN client is connected none of the external access rules work (such as tcp 22, 80, as examples) to the wan interface.

When the OpenVPN client is disconnected they work just fine testing from an external shell with nmap.

I can only think this is potentially a routing problem where the packet gets sent back down the wrong interface ie the tun adapter when received on the wan.

Can anyone help with this?

Kind Regards,
Ross

Sounds like a routing issue with multiple interfaces. Could you post here the following:
cat /etc/config/network; cat /etc/config/firewall; ip -4 addr ; ip -4 ro ; ip -4 ru

@trendy

root@unicorn:/etc/openvpn# cat /etc/config/network; cat /etc/config/firewall; ip -4 addr ; ip -4 ro ; ip -4 ru

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 'fd73:01bc:c51a::/48'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0'
        option proto 'static'
        option ipaddr '10.99.69.253'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan'
        option ifname 'eth1'
        option proto 'pppoe'
        option username 'sel190@plusdsl.net'
        option password 'XXXXX!'
        option ipv6 'auto'
        option peerdns '0'

config interface 'airvpn'
        option proto 'none'
        option ifname 'tun0'


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 defaults
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option syn_flood '1'

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

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

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

config zone
        option forward 'REJECT'
        option output 'ACCEPT'
        option name 'airvpnzone'
        option input 'REJECT'
        option masq '1'
        option mtu_fix '1'
        option network 'airvpn'

config forwarding
        option dest 'airvpnzone'
        option src 'lan'

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

config rule
        option target 'ACCEPT'
        option src 'wan'
        option proto 'tcp'
        option dest_port '2222'
        option name 'wan_ssh'

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
6: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 10.99.69.253/24 brd 10.99.69.255 scope global br-lan
       valid_lft forever preferred_lft forever
15: pppoe-wan: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1492 qdisc fq_codel state UNKNOWN group default qlen 3
    inet 213.31.216.113 peer 172.16.12.65/32 scope global pppoe-wan
       valid_lft forever preferred_lft forever
55: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc cake state UNKNOWN group default qlen 100
    inet 10.6.24.2/24 brd 10.6.24.255 scope global tun0
       valid_lft forever preferred_lft forever
0.0.0.0/1 via 10.6.24.1 dev tun0
default via 172.16.12.65 dev pppoe-wan proto static
10.6.24.0/24 dev tun0 proto kernel scope link src 10.6.24.2
10.99.69.0/24 dev br-lan proto kernel scope link src 10.99.69.253
128.0.0.0/1 via 10.6.24.1 dev tun0
141.98.101.132 via 172.16.12.65 dev pppoe-wan
172.16.12.65 dev pppoe-wan proto kernel scope link src 213.31.216.113
0:      from all lookup local
32676:  from all fwmark 0x20000 lookup 202
32677:  from all fwmark 0x10000 lookup 201
32766:  from all lookup main
32767:  from all lookup default
root@unicorn:/etc/openvpn#

Edit: For clarity I am running dropbear on TCP 2222 (all interfaces) not the default of TCP 22

Kind Regards,
Ross

Add a rule to send traffic from WAN interface out of WAN interface (in /etc/config/network , then do a service network restart )

config rule
        option out     'wan'
	option lookup '100'

config route 'name_your_route'
        option 'interface' 'wan'
        option 'target' '0.0.0.0'
        option 'netmask' '0.0.0.0'
        option 'table' '100'

That should do the trick. In case it doesn't work, post once again the above outputs.

@trendy Thanks for response. Put that into config and reinitialised network but tried testing still not getting a connection when connected to VPN.

As requested. Here is latest output

root@unicorn:/etc/config# cat /etc/config/network; cat /etc/config/firewall; ip -4 addr ; ip -4 ro ; ip -4 ru

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 'fd73:01bc:c51a::/48'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0'
        option proto 'static'
        option ipaddr '10.99.69.253'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan'
        option ifname 'eth1'
        option proto 'pppoe'
        option username 'xxxxxx@plusxxx.net'
        option password 'XXXXX'
        option ipv6 'auto'
        option peerdns '0'

config interface 'airvpn'
        option proto 'none'
        option ifname 'tun0'


config rule
        option out     'wan'
        option lookup '100'

config route 'wan_back_out'
        option 'interface' 'wan'
        option 'target' '0.0.0.0'
        option 'netmask' '0.0.0.0'
        option 'table' '100'

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 defaults
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option syn_flood '1'

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

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

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

config zone
        option forward 'REJECT'
        option output 'ACCEPT'
        option name 'airvpnzone'
        option input 'REJECT'
        option masq '1'
        option mtu_fix '1'
        option network 'airvpn'

config forwarding
        option dest 'airvpnzone'
        option src 'lan'

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

config rule
        option target 'ACCEPT'
        option src 'wan'
        option proto 'tcp'
        option dest_port '2222'
        option name 'wan_ssh'

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
46: br-lan: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 10.99.69.253/24 brd 10.99.69.255 scope global br-lan
       valid_lft forever preferred_lft forever
47: pppoe-wan: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1492 qdisc fq_codel state UNKNOWN group default qlen 3
    inet 150.143.xxx.97 peer 172.16.12.65/32 scope global pppoe-wan
       valid_lft forever preferred_lft forever
48: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 100
    inet 10.6.24.2/24 brd 10.6.24.255 scope global tun0
       valid_lft forever preferred_lft forever
0.0.0.0/1 via 10.6.24.1 dev tun0
default via 172.16.12.65 dev pppoe-wan proto static
10.6.24.0/24 dev tun0 proto kernel scope link src 10.6.24.2
10.99.69.0/24 dev br-lan proto kernel scope link src 10.99.69.253
128.0.0.0/1 via 10.6.24.1 dev tun0
141.98.xxx.132 via 172.16.12.65 dev pppoe-wan
172.16.12.65 dev pppoe-wan proto kernel scope link src 150.143.103.97
0:      from all lookup local
1:      from all oif pppoe-wan lookup 100
32766:  from all lookup main
32767:  from all lookup default
root@unicorn:/etc/config#

Any more ideas?

Kind Regards,
Ross

First I suggest that you cover some sensitive data in your previous post, like username and password for PPPOE, your public IP address.

Add this command and test again, no restart needed.
ip rule add from $IP1 table 100 where $IP1 is the public IP of pppoe-wan.
For the router itself to use the wan line you can issue the following command ip rule add iif lo to default lookup 100 prio 2
That should do it and then we would need to see how to add it in the configuration for every time the network restarts or pppoe renews your IP.

@stavster

While you are at it:

Please use "Preformatted text </>" for logs, scripts, configs and general console output.
grafik

Please edit your posting accordingly.

1 Like

@trendy
Thanks for the latest fix. Now making progress with your latest solution and I can confirm that inbound connections to the wan interface while OpenVPN is connected are now working great.

I have somewhat put together a solution (although not thoroughly tested) for /etc/init.d/network restarts and the VPN connecting and disconnecting. I currently run an up.sh and down.sh script upon connection and disconnection with the OpenVPN client.

I have modified these scripts with your routing fix and some of my code to grab the current IPV4 address from the pppoe-wan interface.

up.sh

#!/bin/sh
#reload sqm due to openvpn interface changes
/etc/init.d/sqm reload >/dev/null 2>&1

#commit crontab on openvpn up successfull to enable vpn gateway checking and restart if down
(crontab -u root -l ; echo "*/5 * * * * /root/check_vpn") | crontab -u root -

#Fix for inbound connections on wan interface while openvpn connected
pppoeip4=$(/sbin/ip -o -4 addr list pppoe-wan | awk '{print $4}' | cut -d/ -f1)
ip rule add from $pppoeip4 table 100

#ipv6 not currently supported by ISP
#pppoeip6=$(/sbin/ip -o -6 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
#ip rule add from $pppoeip6 table 100

down.sh

#!/bin/sh
#reload sqm due to interface changes
/etc/init.d/sqm reload >/dev/null 2>&1

#commit crontab vpn gateway check script
crontab -u root -l | grep -v '/root/check_vpn'  | crontab -u root -

#ipv4 remove wan traffic fix when openvpn disconnects
pppoeip4=$(/sbin/ip -o -4 addr list pppoe-wan | awk '{print $4}' | cut -d/ -f1)
ip rule del from $pppoeip4 table 100


#ipv6 not currently supported by ISP so not used yet (not required for 6in4)
#pppoeip6=$(/sbin/ip -o -6 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
#ip rule del from $pppoeip6 table 100

I am not fussed about routing all traffic from the OpenWRT router out of the wan interface with the vpn connected (I prefer it this way for security)

The only potential problem I can so far see is with a full network init script restart. However I am hoping if the OpenVPN service is still running when that happens, the up.sh and down.sh scripts should still take effect when it reconnects.Also if the pppoe-wan address gets dhcp renewed on re-lease this should still force OpenVPN to reconnect in the same manner (in theory) and the scripts to fix the traffic will run.

Will give it some testing tonight

Kind Regards,
Ross

1 Like