Squid im Intercept-Modus via TPROXY mit nftables: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
Zeile 1: Zeile 1:
= Squid im Intercept-Modus via TPROXY auf separatem Proxyserver =
+
= Squid im Intercept-Modus per REDIRECT (lokal auf dem Proxy) =
  
 
== Voraussetzungen ==
 
== Voraussetzungen ==
* Die Firewall hat die interne IP 172.17.113.1
+
* Der Proxy hat eine eigene IP im LAN, z. B. 10.88.113.51
* Der Squid-Proxy läuft auf einer separaten Maschine mit der IP 10.88.113.51
+
* Squid läuft direkt auf diesem Host
* Der Proxy soll HTTP (Port 80) und HTTPS (Port 443) Verkehr transparent abfangen.
+
* Der Traffic wird per iptables/nftables von Port 80/443 auf lokale Ports umgeleitet
* Die Original-Ziel-IP soll erhalten bleiben – kein DNAT, sondern reines Routing mit Policy-Markierung.
+
* Keine TPROXY-Konfiguration nötig
* TPROXY erfolgt ausschließlich auf dem Proxyserver.
 
  
== nftables-Regeln auf der Firewall ==
+
== Squid-Konfiguration ==
*Tabelle und Set anlegen:
+
http_port 3128 intercept
nft add table inet fwmark
+
https_port 3129 intercept ssl-bump cert=/etc/squid/certs/proxyCA.pem key=/etc/squid/certs/proxyCA.key
nft add set inet fwmark ports { type inet_service\; flags constant\; elements = { 80, 443 } }
 
  
*Kette für PREROUTING:
+
;Optional: SSL-Bump
nft add chain inet fwmark prerouting '{ type filter hook prerouting priority mangle\; policy accept\; }'
 
 
 
*Markierung setzen:
 
nft add rule inet fwmark prerouting ip daddr != 10.88.113.51 tcp dport @ports meta mark set 0x1
 
 
 
== Policy Routing auf der Firewall ==
 
*ip rule add fwmark 1 lookup 100
 
*ip route add 10.88.113.51 dev eth0 table 100
 
 
 
== nftables-Regeln auf dem Proxyserver ==
 
*Tabelle und Kette erstellen:
 
nft add table inet myproxy
 
nft add chain inet myproxy prerouting '{ type filter hook prerouting priority mangle\; policy accept\; }'
 
 
 
*TPROXY-Regeln:
 
nft add rule inet myproxy prerouting ip daddr 10.88.113.51 tcp dport 3129 tproxy ip to :3129 meta mark set 0x1
 
nft add rule inet myproxy prerouting ip daddr 10.88.113.51 tcp dport 3130 tproxy ip to :3130 meta mark set 0x1
 
 
 
== 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
 
 
 
== Kernel-Module auf dem Proxyserver laden ==
 
*modprobe nf_conntrack
 
*modprobe nf_tproxy_ipv4
 
*modprobe nf_tproxy_ipv6
 
*modprobe xt_TPROXY
 
 
 
== Squid-Konfiguration auf dem Proxy ==
 
http_port 3129 tproxy
 
https_port 3130 ssl-bump tproxy cert=/etc/squid/certs/squid_proxyCA.pem key=/etc/squid/certs/squid_proxyCA.key
 
 
 
;Optional SSL-Bump:
 
 
ssl_bump peek all
 
ssl_bump peek all
 
ssl_bump bump all
 
ssl_bump bump all
Zeile 52: Zeile 17:
 
sslproxy_flags DONT_VERIFY_PEER
 
sslproxy_flags DONT_VERIFY_PEER
  
== Squid-Rechte anpassen ==
+
== nftables-Konfiguration (lokal auf dem Proxy) ==
*setcap cap_net_admin=eip /usr/sbin/squid
+
*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  redirect to :3128
 +
*nft add rule ip nat prerouting tcp dport 443 redirect to :3129
 +
 
 +
== Kernel-Module laden (falls nötig) ==
 +
*modprobe nf_nat
 +
*modprobe nf_conntrack
 +
 
 +
== Squid-Rechte (kein TPROXY nötig) ==
 +
Keine `setcap`-Anpassung notwendig – REDIRECT reicht.
  
== Logs & Diagnose ==
+
== Test & Logs ==
*nft list chain inet fwmark prerouting
 
*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/access.log
 
*tail -f /var/log/squid/cache.log
 
*tail -f /var/log/squid/cache.log

Aktuelle Version vom 24. April 2025, 05:19 Uhr

Squid im Intercept-Modus per REDIRECT (lokal auf dem Proxy)

Voraussetzungen

  • Der Proxy hat eine eigene IP im LAN, z. B. 10.88.113.51
  • Squid läuft direkt auf diesem Host
  • Der Traffic wird per iptables/nftables von Port 80/443 auf lokale Ports umgeleitet
  • Keine TPROXY-Konfiguration nötig

Squid-Konfiguration

http_port 3128 intercept https_port 3129 intercept ssl-bump cert=/etc/squid/certs/proxyCA.pem key=/etc/squid/certs/proxyCA.key

Optional
SSL-Bump

ssl_bump peek all ssl_bump bump all sslproxy_cert_error allow all sslproxy_flags DONT_VERIFY_PEER

nftables-Konfiguration (lokal auf dem 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 redirect to :3128
  • nft add rule ip nat prerouting tcp dport 443 redirect to :3129

Kernel-Module laden (falls nötig)

  • modprobe nf_nat
  • modprobe nf_conntrack

Squid-Rechte (kein TPROXY nötig)

Keine `setcap`-Anpassung notwendig – REDIRECT reicht.

Test & Logs

  • tail -f /var/log/squid/access.log
  • tail -f /var/log/squid/cache.log