Squid im Intercept-Modus via TPROXY mit nftables: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| Zeile 1: | Zeile 1: | ||
| − | = Squid im Intercept-Modus via TPROXY | + | = Squid im Intercept-Modus via TPROXY auf separatem Proxyserver = |
== Voraussetzungen == | == Voraussetzungen == | ||
| Zeile 5: | Zeile 5: | ||
* Der Squid-Proxy läuft auf einer separaten Maschine mit der IP 10.88.113.51 | * Der Squid-Proxy läuft auf einer separaten Maschine mit der IP 10.88.113.51 | ||
* Der Proxy soll HTTP (Port 80) und HTTPS (Port 443) Verkehr transparent abfangen. | * Der Proxy soll HTTP (Port 80) und HTTPS (Port 443) Verkehr transparent abfangen. | ||
| − | * Die Original-Ziel-IP soll erhalten bleiben – daher wird auf der Firewall | + | * Die Original-Ziel-IP soll erhalten bleiben – daher wird auf der Firewall DNAT gemacht, und **TPROXY erfolgt auf dem Proxyserver**. |
| − | * Die Firewall nutzt nftables für | + | * Die Firewall nutzt nftables für DNAT. |
* Der Proxyserver setzt nftables und Policy Routing für TPROXY ein. | * Der Proxyserver setzt nftables und Policy Routing für TPROXY ein. | ||
== nftables-Regeln auf der Firewall == | == nftables-Regeln auf der Firewall == | ||
| − | ;NAT-Tabelle und Weiterleitung | + | ;NAT-Tabelle und Weiterleitung an den Proxy: |
*nft add table ip nat | *nft add table ip nat | ||
*nft add chain ip nat prerouting '{ type nat hook prerouting priority dstnat; policy accept; }' | *nft add chain ip nat prerouting '{ type nat hook prerouting priority dstnat; policy accept; }' | ||
| Zeile 17: | Zeile 17: | ||
== nftables-Regeln auf dem Proxyserver == | == nftables-Regeln auf dem Proxyserver == | ||
| − | ;Tabelle und Kette erstellen: | + | ;Tabelle und Kette erstellen (Name nicht "tproxy", da reserviert): |
| − | *nft add table inet | + | *nft add table inet myproxy |
| − | *nft add chain inet | + | *nft add chain inet myproxy prerouting '{ type filter hook prerouting priority mangle; policy accept; }' |
;TPROXY-Regeln für HTTP und HTTPS: | ;TPROXY-Regeln für HTTP und HTTPS: | ||
| − | *nft add rule inet | + | *nft add rule inet myproxy prerouting ip daddr 10.88.113.51 tcp dport 3029 tproxy to :3029 mark set 1 |
| − | *nft add rule inet | + | *nft add rule inet myproxy prerouting ip daddr 10.88.113.51 tcp dport 3030 tproxy to :3030 mark set 1 |
== Policy Routing auf dem Proxyserver == | == Policy Routing auf dem Proxyserver == | ||
| Zeile 50: | Zeile 50: | ||
== Squid-Rechte anpassen == | == Squid-Rechte anpassen == | ||
| − | *setcap | + | *setcap cap_net_admin=eip /usr/sbin/squid |
== Test & Diagnose == | == Test & Diagnose == | ||
| Zeile 57: | Zeile 57: | ||
;Proxyserver: | ;Proxyserver: | ||
| − | *nft list chain inet | + | *nft list chain inet myproxy prerouting |
*ip rule show | *ip rule show | ||
*ip route show table 100 | *ip route show table 100 | ||
| Zeile 64: | Zeile 64: | ||
== Hinweise == | == Hinweise == | ||
| − | * | + | * Diese Konfiguration funktioniert nur, wenn der Proxyserver die Zieladresse 10.88.113.51 lokal empfangen kann. |
| − | * | + | * Clients müssen ggf. die Root-CA akzeptieren, wenn SSL-Bump aktiv ist. |
| − | * | + | * Für produktive Umgebungen ist WPAD mit explizitem Proxy oft die bessere Lösung. |
Version vom 24. April 2025, 04:23 Uhr
Squid im Intercept-Modus via TPROXY auf separatem Proxyserver
Voraussetzungen
- Die Firewall hat die interne IP 172.17.113.1
- Der Squid-Proxy läuft auf einer separaten Maschine mit der IP 10.88.113.51
- Der Proxy soll HTTP (Port 80) und HTTPS (Port 443) Verkehr transparent abfangen.
- Die Original-Ziel-IP soll erhalten bleiben – daher wird auf der Firewall DNAT gemacht, und **TPROXY erfolgt auf dem Proxyserver**.
- Die Firewall nutzt nftables für DNAT.
- Der Proxyserver setzt nftables und Policy Routing für TPROXY ein.
nftables-Regeln auf der Firewall
- NAT-Tabelle und Weiterleitung an den Proxy
- nft add table ip nat
- nft add chain ip nat prerouting '{ type nat hook prerouting priority dstnat; policy accept; }'
- nft add rule ip nat prerouting tcp dport 80 dnat to 10.88.113.51:3029
- nft add rule ip nat prerouting tcp dport 443 dnat to 10.88.113.51:3030
nftables-Regeln auf dem Proxyserver
- Tabelle und Kette erstellen (Name nicht "tproxy", da reserviert)
- nft add table inet myproxy
- nft add chain inet myproxy prerouting '{ type filter hook prerouting priority mangle; policy accept; }'
- TPROXY-Regeln für HTTP und HTTPS
- nft add rule inet myproxy prerouting ip daddr 10.88.113.51 tcp dport 3029 tproxy to :3029 mark set 1
- nft add rule inet myproxy prerouting ip daddr 10.88.113.51 tcp dport 3030 tproxy to :3030 mark set 1
Policy Routing auf dem Proxyserver
- ip rule add fwmark 1 lookup 100
- ip route add local 0.0.0.0/0 dev lo table 100
Notwendige Kernel-Module auf dem Proxyserver
- modprobe nf_conntrack
- modprobe nf_tproxy_ipv4
- modprobe nf_tproxy_ipv6
- modprobe xt_TPROXY
Squid-Setup auf dem Proxyserver
Squid muss mit TPROXY-Support kompiliert sein (mit --enable-linux-netfilter)
Squid-Konfiguration anpassen:
http_port 3029 tproxy https_port 3030 tproxy ssl-bump cert=/etc/squid/certs/proxy.pem key=/etc/squid/certs/proxy.key
- Optional
- SSL-Bump konfigurieren:
ssl_bump peek all ssl_bump bump all sslproxy_cert_error allow all sslproxy_flags DONT_VERIFY_PEER
Squid-Rechte anpassen
- setcap cap_net_admin=eip /usr/sbin/squid
Test & Diagnose
- Firewall
- nft list chain ip nat prerouting
- Proxyserver
- nft list chain inet myproxy prerouting
- ip rule show
- ip route show table 100
- tail -f /var/log/squid/access.log
- tail -f /var/log/squid/cache.log
Hinweise
- Diese Konfiguration funktioniert nur, wenn der Proxyserver die Zieladresse 10.88.113.51 lokal empfangen kann.
- Clients müssen ggf. die Root-CA akzeptieren, wenn SSL-Bump aktiv ist.
- Für produktive Umgebungen ist WPAD mit explizitem Proxy oft die bessere Lösung.