Skip to content

Instantly share code, notes, and snippets.

@danielrosehill
Created August 29, 2025 12:37
Show Gist options
  • Select an option

  • Save danielrosehill/b1bb13f448cfb3377bf8fb397dec58fe to your computer and use it in GitHub Desktop.

Select an option

Save danielrosehill/b1bb13f448cfb3377bf8fb397dec58fe to your computer and use it in GitHub Desktop.
LAN redirect wiith Opnsense and Haproxy

Opnsense Redirect On Gateway Host Logic

Example problem

Danel installs Homebox on his home network.

Daniel installs it on an Ubuntu VM at 10.0.0.1.

Daniel later realises that his home network config is dumb! He moves the gateway to 10.0.0.1.

Daniel also buys a URL / FQDN for his Homebox instance and uses Cloudflare Tunnel to route to it.

But Daniel now has a problem!

He has thousands of barcodes and QR codes in his house. They all look like this:

10.0.0.1:3100/item/daniels-tech-thing

Daniel knows that ther is a better way to solve this than to reprint thosands of barcodes. He installs Opnsense.

Redirect On Gateway

In this example (that cost Daniel quite a bit of torn-out hair), Daniel is trying to do the following:

  • Create a port-specific wildcard redirect on the gateway host

It's port-specific because we can't redirect everything on 10.0.0.1 as that's the gateway and Unbound DNS address and doing so would break the whole network! So we need two things:

  1. A port-specific LAN redirect
  2. A regex rewrite logic

Ha Proxy makes both of these easy to configure!

Ha Proxy Config

We will want to:

  1. Enable advanced mode
  2. Creating a listener at the (former) homebox instance:
image

We configure "option pass through":

image

And add:

http-request redirect code 301 prefix https://yourhomebox.instance.com if { path_beg /item/ }

Then:

  • Apply
  • Enable HA Proxy

Make sure that SSL is enabled if your URLs are written with both http and https (or just https)

Now the redirects will happen extremely quickly and at source - every device connected to the LAN will follow the redirect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment