PF Can I make a 2-way tunnel via firewall rules?

This is all hypothetical, but I'm very curious if theres a way to set this up, and if so, what that way is?

So say I have a server thats at a data center, directly connected to the internet, using PF as it's firewall. All ports are blocked by default, and web and email ports are open explicitly.

This server has two IPs. One IP for one website, and a second IP for a bunch of others.

So is it possible to make a rule that takes all inbound traffic from the first IP, on lets say port 80, and redirect that to another IP and port entirely, across the internet? But of course it needs to be a 2-way communication, so responses to those inbound forwarded requests would also need to ping from the redirect server, back across the internet to this collocated server, then sent back to the original requester as if it was being handled normally.

Let me know if it's not clear what I'm trying to do. It sounds very much like I'm describing a VPN. But with the traffic already being fully encrypted, and also not being sensitive anyway, I wonder if I can do it super simply with just firewall redirects?

So to recap, website visitor would make an http request to server A, server A's firewall would forward the request to server B, server B would respond to the request by sending it back to server A, which would then send the response back to the user.

I've done a fair bit of networking and firewall rules and vpn tunneling over the years, but I've never done a setup like this. But if it can be done easily, this could be a really useful solution for me.
 
So is it possible to make a rule that takes all inbound traffic from the first IP, on lets say port 80, and redirect that to another IP and port entirely, across the internet?
No. You cannot "bounce" packets out the same interface they came in on. Besides that, connections to the second IP address (from the host itself) would never go out of the interface, the IP address is accessible on the host. If you look at your routing table, you'll see the IP address gets routed to lo0.

So to recap, website visitor would make an http request to server A, server A's firewall would forward the request to server B, server B would respond to the request by sending it back to server A, which would then send the response back to the user.
There is no server A and B. You have a single, multi-homed, server.
 
Well if I do use a VPN to make the connection, how can I route traffic to server B over the VPN? So I guess basically port forwarding to a 'lan' IP is what I'm trying to do.
 
So I guess basically port forwarding to a 'lan' IP is what I'm trying to do.
Basic rdr:
Code:
rdr on $ext_if inet proto tcp from any to ($ext_if) port 80 -> 192.168.100.12 port 80

Routing table will do the rest. Packet filters like PF manipulate packets, it's not a routing engine.
 
Back
Top