Sometimes you want to use jails on the same hosts that do the NAT. That of course isn’t by any means a complicated task
and pf
can do that very easily. The problems begin when you want to connect from one jail to a NATed IP (in the
example 192.168.122.251) to a port that is redirected to another jail on the same system. Here is one of the solutions.
Let’s assume this configuration: external interface is em0
, the public IP assigned to that interface will be used to
NAT all connections from small network used by jails. Jails IPs are aliased on lo1
interface.
|
|
The pf
configuration is as follows:
|
|
We have two jails:
|
|
On j2 we started an http server that listens on port 8080, connections to our NATed IP are redirected to that port and jail. Yet when you want to connect from j1 to NATIP:80, the connection will fail!
All the communication between the IP address assigned to a single host use loopback interface lo0
, regardless of the
interface they are bind to. This is a very important clue. This is what we see after initialising connection from j1 to
j2 (that are aliased on lo1!) using internal addresses:
|
|
Now, since we know that, we can add a line like
rdr pass on lo0 proto tcp from $jail_net to ($ext_if) port 80 -> 10.10.10.11 port 8080
Yet it’ll still not work as expected:
|
|
We need to remove set skip on lo0
to allow pf to filter on this interface. After that, we can add
explicit pass quick on lo0 all
to simulate set skip rule.
Finally, we should be able to connect from j1 to j2 using our public/NATed IP!