I have a number of services in my home network that I want to expose only in UK. To achieve this I am using
Cloudflare as reverse proxy allowing only Cloudflare IP ranges to reach my services via https;
CloudFlare is setup to block non-UK originating IPs
IPFire has a port forwarding rule for a Host Group that covers the Cloudflare IP ranges
IPFire GeoIP block to any non-UK IP addresses so I restrict Roadwarrior access from non-UK IPs
Problem: For Cloudflare reverse proxy does not work if GeoIP IP blocks Country:US and A3 Proxy, hence I have to expose my IPFire to those IP ranges.
I understand in the FORWARD chain, the LOCATIONBLOCK is resolved before the FORWARDFW rules that contain the Cloudflare IP range, hence given the order of processing I have no option from the WebUI but to accept my IPFire is exposed to US & A3 ranges.
Potential Solution: I was thinking pushing the Cloudflare IP check before the location check by…
Manually add Cloudflare IP ranges under the CUSTOMFORWARD rules
Then block US & A3 ranges under GeoIP menu
Would this be a valid approach ? if yes, anything I should be careful about ?
Allow access to home services via Cloudflare IPs and while using Cloudflare’s GeoBlock against non-UK IP addresses.
I have written a small script that pulls the IPs from Cloudflare API and either adds or removes the cloudflare IPs from the CUSTOMFORWARD & CUSTOMPREROUTING chains. Those CUSTOM chains survive any updates in firewalls rules from the WebUI.
# sh ./cloudflare-port-forward.sh
Usage: ./cloudflare-port-forward.sh [add|del] <destination_ip> <destination_port>
# sh ./cloudflare-port-forward.sh add 192.168.1.152 443
Just to finish this posting, I have now made the changes survive the reboot/restart by adding them into firewall.local (wish I read it earlier)
#!/bin/sh
# Used for private firewall rules
# See how we were called.
case "$1" in
start)
## add your 'start' rules here
sh <abs_path_to>/cloudflare-port-forward.sh add <internal_ip> <port>
;;
stop)
## add your 'stop' rules here
sh <abs_path_to>/cloudflare-port-forward.sh del <internal_ip> <port>
;;
reload)
$0 stop
$0 start
## add your 'reload' rules here
;;
*)
echo "Usage: $0 {start|stop|reload}"
;;
esac