I’ve figured out how to do it, albeit temporarily - these settings will probably need to be performed each time the container is stopped/started.
For anyone interested:
Say you’ve got a Plex app and you’ve specified IP address 192.168.1.11
as the Host IP address
for the app, which is an alias on the TrueNAS nic (the first TrueNAS IP address being 192.168.1.10
). If you query docker you’ll see port 32400 is bound to that address:
% sudo docker ps -a | grep pms-docker
5f906db91545 plexinc/pms-docker:plexpass "/init" 13 days ago Up 13 days (healthy) 3005/tcp, 1900/udp, 32410/udp, 8324/tcp, 32412-32414/udp, 32469/tcp, 192.168.1.11:32400->32400/tcp ix-plex-plex-1
Great, but as I explained, any outgoing connections from the app will originate from 192.168.1.10
, which isn’t great if you want to use a firewall to police what Plex container is talking to.
Check the docker network that Plex is using:
% sudo docker network ls | grep plex
cddfa6489de7 ix-plex_default bridge local
Keep that network ID, and query iptables with it. You’ll see something like this:
% sudo iptables-save | grep cddfa6489de7 | grep POSTROUTING
-A POSTROUTING -s 172.16.2.0/24 ! -o br-cddfa6489de7 -j MASQUERADE
We want to replace that rule (making sure the -s
source address is the same in the appended rule as on the deleted one):
# The next line removes the above masquerading rule
sudo iptables -t nat -D POSTROUTING -s 172.16.2.0/24 ! -o br-cddfa6489de7 -j MASQUERADE
# The next line adds a new SNAT rule
sudo iptables -t nat -A POSTROUTING -s 172.16.2.0/24 ! -o br-cddfa6489de7 -j SNAT --to-source 192.168.1.11
Voila, all outbound connections from Plex will originate from 192.168.1.11
instead of 192.168.1.10
and you can effectively police them from a firewall.
The next thing I need to figure out is how to do this programmatically not manually.