[squid-users] variable/macro, setting outgoing address

Andrey K ankor2023 at gmail.com
Fri Nov 27 09:03:06 UTC 2026


Hello Matus,

I think you can achieve this using the ${service_name} macro together with
the tcp_outgoing_address directive.

The proposed scheme would look like this:
Suppose you have several Squid hosts: host1, host2, host3, etc.
1. Register host-specific names in your DNS (or /etc/hosts), such as
host1-special, host2-special, host3-special, pointing to their
corresponding "special" IPs.
2. Pass the hostname as the service name when starting Squid using the -n
option. In a systemd unit file, you can use -n %H (or %h for the short
hostname).
3. Use the ${service_name} macro in your tcp_outgoing_address directive,
for example:
tcp_outgoing_address ${service_name}-special special_hosts

Another very handy approach I can recommend for managing identical configs
with per-host values is using Ansible templates (Jinja2).

Kind regards,
    Ankor




чт, 26 нояб. 2026 г. в 19:24, Matus UHLAR - fantomas <uhlar at fantomas.sk>:

> >On 26 November 2026 11:28:52 am UTC, Matus UHLAR - fantomas <
> uhlar at fantomas.sk> wrote:
> >>This seems to be possible, although confusing in case of multiple ACLs
> to match.
>
> On 26.11.26 16:04, Nishant Sharma wrote:
> >For each ACL you can have separate outgoing address lines in the file.
> >
> >For AND match, you can have those ACLs on the same line.
> >
> >I hope I am able to understand your concern.
>
> Aha... yes, I understand how ACLs work.
>
> But keeping the same list of ACLs in separate file is a complication.
> Your proposed "/special/host/file" and separate file containing:
>
> tcp_outgoing_address x.x.x.x special_hosts
>
> would be easy in case of routing requests from single list of source hosts
> via extra address.
> If those acls were more complicated, the separate file would look like:
>
> tcp_outgoing_address x.x.x.x src1 dst1
> tcp_outgoing_address x.x.x.x src2 dst1
> tcp_outgoing_address x.x.x.x src2 dst2
>
> ...and I'd have to maintain two these files on two extra hosts.
> This is where macros/variables would make it easy for me.
>
>
> For now I'm speculating about using:
>
> tcp_outgoing_mark 0x10 [...]
> [...]
>
> iptables -t nat -A POSTROUTING -m mark --mark 0x10 -j SNAT --to-source
> $altsource
>
>
> where I can include file containing $altsource to firewall config file.
>
>
> --
> Matus UHLAR - fantomas, uhlar at fantomas.sk ; http://www.fantomas.sk/
> Warning: I wish NOT to receive e-mail advertising to this address.
> Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
> Silvester Stallone: Father of the RISC concept.
> _______________________________________________
> squid-users mailing list
> squid-users at lists.squid-cache.org
> https://lists.squid-cache.org/listinfo/squid-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squid-cache.org/pipermail/squid-users/attachments/20261127/9dc80060/attachment-0001.htm>


More information about the squid-users mailing list