T
TorchedPoseidon
Guest
I have issues trying to route traffic from tcp port 51413. I have the feeling it's something simple that's staring me in the face, but can't for the life of me find what I'm missing so I was hoping for some extra eyes to help me out.
The goal: Have only traffic (inbound and outbound) from port 51413 (originating from ip 10.0.0.31) go through the VPN tunnel and let all other traffic go through WAN. Preferably with a kill switch that prevents any traffic from port 51413 going through WAN at all times.
Additionally I'm running a PiHole from this source IP so I need to make sure that there's no interference in terms of access to DNS servers by the PiHole service, which runs through port 53 if I'm not mistaken. That takes priority over the risk of DNS leaks so if the DNS configuration needs to be changed to something less strict that's ok.
The way I've been trying to accomplish this (thanks to documentation of members like @Martineau and @john9527) is as follow:
FW: Merlin 384.13_0
The relevant client settings (Client1)
Automatic start at boot time: Yes
Interface Type: TUN
Protocol: UDP
Accept DNS Configuration: Exclusive
Create NAT on tunnel: Yes
Inbound Firewall: Allow
Compression: None
Force Internet traffic through tunnel: Policy Rules (strict); No policy rules set up through GUI
Block routed clients if tunnel goes down: Yes
Content of /jffs/scripts/nat-start:
Which is effectively creates a reset state and adds an RPDB rule for WAN (didn't know of a more elegant place to put it) mirroring the placement of the RPDB rules for the individual VPN clients in their respective scripts.
Content of /jffs/scripts/openvpn-event:
Content of /jffs/scripts/vpnclient1-route-up
And bonus contents (for the sake of good practice) of /jffs/scripts/vpnclient1-route-down:
With the other vpnclientX-route-up/down scripts simply containing fwmarks
Scripts are set as executable
Sadly this doesn't seem to work as per https://ipleak.net
Logs do mention something about the scripts:
However renaming vpnclient1-route-up to just vpnclient1-up doesn't change anything.
Some (semi-)relevant diagnostic output:
Output of ip route show table 111:
Output of iptables --list:
I hit the character count limit for this post so I'll continue below
The goal: Have only traffic (inbound and outbound) from port 51413 (originating from ip 10.0.0.31) go through the VPN tunnel and let all other traffic go through WAN. Preferably with a kill switch that prevents any traffic from port 51413 going through WAN at all times.
Additionally I'm running a PiHole from this source IP so I need to make sure that there's no interference in terms of access to DNS servers by the PiHole service, which runs through port 53 if I'm not mistaken. That takes priority over the risk of DNS leaks so if the DNS configuration needs to be changed to something less strict that's ok.
The way I've been trying to accomplish this (thanks to documentation of members like @Martineau and @john9527) is as follow:
FW: Merlin 384.13_0
The relevant client settings (Client1)
Automatic start at boot time: Yes
Interface Type: TUN
Protocol: UDP
Accept DNS Configuration: Exclusive
Create NAT on tunnel: Yes
Inbound Firewall: Allow
Compression: None
Force Internet traffic through tunnel: Policy Rules (strict); No policy rules set up through GUI
Block routed clients if tunnel goes down: Yes
Content of /jffs/scripts/nat-start:
Code:
#!/bin/sh
sleep 10 # During the boot process nat-start may run multiple times so this is required
# Ensure duplicate rules are not created
for VPN_ID in 0 1 2 3 4 5
do
ip rule del prio 999$VPN_ID 2>/dev/null
done
# Create the RPDB rule for WAN
ip rule add from 0/0 fwmark "0x8000/0x8000" table main prio 9990 # WAN fwmark
Content of /jffs/scripts/openvpn-event:
Code:
#!/bin/sh
scr_name="$(basename $0)[$$]"
case "$1" in
"tun11")
vpn_name="client1"
;;
"tun12")
vpn_name="client2"
;;
"tun13")
vpn_name="client3"
;;
"tun14")
vpn_name="client4"
;;
"tun15")
vpn_name="client5"
;;
"tun21")
vpn_name="server1"
;;
"tun22")
vpn_name="server2"
;;
*)
vpn_name=""
;;
esac
# Call appropriate script based on script_type
vpn_script_name="vpn$vpn_name-$script_type"
# Check script state/use nvram to save last script run
vpn_script_state=$(nvram get vpn_script_state)
nvram set vpn_script_state="$vpn_script_name"
if [ "$vpn_script_name" = "$vpn_script_state" ]; then
echo "VPN script" $vpn_script_name "already run" | logger -t "$scr_name"
exit 0
fi
if [[ -f "/jffs/scripts/$vpn_script_name" ]] ; then
sh /jffs/scripts/$vpn_script_name $*
else
echo "Script not defined for event: "$vpn_script_name | logger -t $scr_name
exit 0
fi
exit 0
Content of /jffs/scripts/vpnclient1-route-up
Code:
#!/bin/sh
ip rule add from 0/0 fwmark 0x1000/0x1000 table ovpnc1 prio 9993 # VPN 1 fwmark
iptables -t mangle -A PREROUTING -i br0 -m iprange --src-range 10.0.0.31 -p tcp -m multiport --sport 51413 -j MARK --set-mark 0x1000/0x1000
iptables -t mangle -A PREROUTING -i br0 -m iprange --src-range 10.0.0.31 -p tcp -m multiport --dport 51413 -j MARK --set-mark 0x1000/0x1000
And bonus contents (for the sake of good practice) of /jffs/scripts/vpnclient1-route-down:
Code:
#!/bin/sh
ip rule del from 0/0 fwmark 0x1000/0x1000 table ovpnc1 prio 9993 # VPN 1 fwmark
iptables -t mangle -D PREROUTING -i br0 -m iprange --src-range 10.0.0.31 -p tcp -m multiport --sport 51413 -j MARK --set-mark 0x1000/0x1000
iptables -t mangle -D PREROUTING -i br0 -m iprange --src-range 10.0.0.31 -p tcp -m multiport --dport 51413 -j MARK --set-mark 0x1000/0x1000
With the other vpnclientX-route-up/down scripts simply containing fwmarks
Scripts are set as executable
Sadly this doesn't seem to work as per https://ipleak.net
Logs do mention something about the scripts:
Code:
Dec 5 10:34:33 custom_script: Running /jffs/scripts/openvpn-event (args: tun11 1500 1553 10.200.0.66 10.200.0.65 init)
Dec 5 10:34:33 openvpn-event[2449]: Script not defined for event: vpnclient1-up
Some (semi-)relevant diagnostic output:
Output of ip route show table 111:
Code:
10.0.0.0/24 dev br0 proto kernel scope link src 10.0.0.1
10.200.0.65 dev tun11 proto kernel scope link src 10.200.0.66
Output of iptables --list:
Code:
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP icmp -- anywhere anywhere icmp echo-request
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
DROP all -- anywhere anywhere state INVALID
PTCSRVWAN all -- anywhere anywhere
PTCSRVLAN all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state NEW
ACCEPT all -- anywhere anywhere state NEW
OVPN all -- anywhere anywhere state NEW
ACCEPT udp -- anywhere anywhere udp spt:bootps dpt:bootpc
INPUT_ICMP icmp -- anywhere anywhere
DROP all -- anywhere anywhere
Chain FORWARD (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
other2wan all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
DROP all -- anywhere anywhere state INVALID
NSFW all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate DNAT
OVPN all -- anywhere anywhere state NEW
DROP all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain ACCESS_RESTRICTION (0 references)
target prot opt source destination
Chain DNSFILTER_DOT (0 references)
target prot opt source destination
Chain FUPNP (0 references)
target prot opt source destination
ACCEPT tcp -- anywhere 10.0.0.31 tcp dpt:51413
Chain INPUT_ICMP (1 references)
target prot opt source destination
RETURN icmp -- anywhere anywhere icmp echo-request
RETURN icmp -- anywhere anywhere icmp timestamp-request
ACCEPT icmp -- anywhere anywhere
Chain NSFW (1 references)
target prot opt source destination
Chain OVPN (2 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
Chain PControls (0 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
Chain PTCSRVLAN (1 references)
target prot opt source destination
Chain PTCSRVWAN (1 references)
target prot opt source destination
Chain SECURITY (0 references)
target prot opt source destination
RETURN tcp -- anywhere anywhere tcpflags: FIN,SYN,RST,ACK/SYN limit: avg 1/sec burst 5
DROP tcp -- anywhere anywhere tcpflags: FIN,SYN,RST,ACK/SYN
RETURN tcp -- anywhere anywhere tcpflags: FIN,SYN,RST,ACK/RST limit: avg 1/sec burst 5
DROP tcp -- anywhere anywhere tcpflags: FIN,SYN,RST,ACK/RST
RETURN icmp -- anywhere anywhere icmp echo-request limit: avg 1/sec burst 5
DROP icmp -- anywhere anywhere icmp echo-request
RETURN all -- anywhere anywhere
Chain default_block (0 references)
target prot opt source destination
Chain logaccept (0 references)
target prot opt source destination
LOG all -- anywhere anywhere state NEW LOG level warning tcp-sequence tcp-options ip-options prefix "ACCEPT "
ACCEPT all -- anywhere anywhere
Chain logdrop (0 references)
target prot opt source destination
LOG all -- anywhere anywhere state NEW LOG level warning tcp-sequence tcp-options ip-options prefix "DROP "
DROP all -- anywhere anywhere
Chain other2wan (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
DROP all -- anywhere anywhere
I hit the character count limit for this post so I'll continue below
Last edited by a moderator: