Squid-Kit-1: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Zeile 1: Zeile 1:
 
=Installation=
 
=Installation=
 
*apt install squid-openssl
 
*apt install squid-openssl
 +
;Installiert den Squid Proxy inkl. HTTPS-Unterstützung.
 +
;Ohne SSL-Unterstützung funktioniert CONNECT nicht korrekt.
  
 
=Erste Schritte=
 
=Erste Schritte=
 
==Configdir==
 
==Configdir==
 
*cd /etc/squid
 
*cd /etc/squid
 +
;Hier liegt die zentrale Konfigurationsdatei squid.conf.
 +
;Alle Anpassungen erfolgen in diesem Verzeichnis.
 +
 
==Default Konfiguration sichern==
 
==Default Konfiguration sichern==
 
*cp squid.conf squid.conf.org
 
*cp squid.conf squid.conf.org
==Kommentare aus der squid.conf entfernen==
+
;Sichert die Originalkonfiguration.
 +
;Ermöglicht schnelles Zurücksetzen bei Fehlern.
 +
 
 +
==Kommentare entfernen==
 
*grep "^[^#]" squid.conf.org > squid.conf
 
*grep "^[^#]" squid.conf.org > squid.conf
 +
;Entfernt Kommentare für bessere Übersicht.
 +
;Zeigt nur aktive Konfiguration.
 +
 
==Bereinigte squid.conf==
 
==Bereinigte squid.conf==
<pre>
+
acl localnet src 10.0.0.0/8
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
+
acl localnet src 172.16.0.0/12
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
+
  acl localnet src 192.168.0.0/16
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
+
acl localnet src fc00::/7
acl localnet src fc00::/7       # RFC 4193 local private network range
+
acl localnet src fe80::/10
acl localnet src fe80::/10     # RFC 4291 link-local (directly plugged) machines
+
 
acl SSL_ports port 443
+
acl SSL_ports port 443
acl Safe_ports port 80         # http
+
 
acl Safe_ports port 21         # ftp
+
acl Safe_ports port 80
acl Safe_ports port 443         # https
+
acl Safe_ports port 21
acl Safe_ports port 70         # gopher
+
acl Safe_ports port 443
acl Safe_ports port 210         # wais
+
acl Safe_ports port 70
acl Safe_ports port 1025-65535  # unregistered ports
+
acl Safe_ports port 210
acl Safe_ports port 280         # http-mgmt
+
acl Safe_ports port 1025-65535
acl Safe_ports port 488         # gss-http
+
  acl Safe_ports port 280
acl Safe_ports port 591         # filemaker
+
acl Safe_ports port 488
acl Safe_ports port 777         # multiling http
+
acl Safe_ports port 591
acl CONNECT method CONNECT
+
acl Safe_ports port 777
http_access deny !Safe_ports
+
 
http_access deny CONNECT !SSL_ports
+
acl CONNECT method CONNECT
http_access allow localhost manager
+
 
http_access deny manager
+
http_access deny !Safe_ports
http_access allow localnet
+
http_access deny CONNECT !SSL_ports
http_access allow localhost
+
 
http_access deny all
+
http_access allow localhost manager
http_port 3128
+
http_access deny manager
coredump_dir /var/cache/squid
+
 
refresh_pattern ^ftp:          1440    20%    10080
+
http_access allow localnet
refresh_pattern ^gopher:        1440    0%      1440
+
http_access allow localhost
refresh_pattern -i (/cgi-bin/|\?) 0    0%      0
+
 
refresh_pattern .              0      20%    4320
+
http_access deny all
</pre>
+
 
 +
http_port 3128
 +
coredump_dir /var/cache/squid
 +
 
 +
refresh_pattern ^ftp:          1440    20%    10080
 +
refresh_pattern ^gopher:        1440    0%      1440
 +
refresh_pattern -i (/cgi-bin/|\?) 0    0%      0
 +
refresh_pattern .              0      20%    4320
 +
 
 +
;Erlaubt allen internen Netzen Zugriff auf den Proxy.
 +
;Am Ende blockiert "deny all" alles nicht explizit Erlaubte.
 +
 
 
==Prinzip der ACL==
 
==Prinzip der ACL==
 +
*Squid arbeitet von oben nach unten – erste passende Regel gewinnt.
 +
;Falsche Reihenfolge führt häufig zu unerwartetem Verhalten.
 +
;Debugging beginnt fast immer hier.
 +
 
{{#drawio:Prinzip der ACL}}
 
{{#drawio:Prinzip der ACL}}
  
 +
==Konfiguration anpassen (eigene Netze)==
 +
;Ziel ist es, Zugriff gezielt zu steuern.
 +
;Die Default-Konfiguration ist zu offen.
  
==Konfigurationseinstellungen==
+
==Neue squid.conf==
===Grundlegende Direktiven===
+
<span style="color:blue"># acl localnet src 10.0.0.0/8</span>
====Filter anlegen====
+
  <span style="color:blue"># acl localnet src 172.16.0.0/12</span>
acl it-dmz src 10.88.213.0/24
+
<span style="color:blue"># acl localnet src 192.168.0.0/16</span>
  acl it-lan src 172.26.213.0/24
 
:acl Schlüsselwort
 
:it-dmz Bezeichner (beliebig)
 
:src filterkriterium (es gibt viele)
 
:10.88.213.0/24 Bereich (Variable)
 
  
====Anwenden der Filter====
+
acl localnet src fc00::/7
:http_access Schlüsselwort
+
acl localnet src fe80::/10
  http_access allow it-dmz
+
 
  http_access allow it-lan
+
<span style="color:red">acl it-dmz src 10.88.213.0/24</span>
:allow (erlauben) oder deny (verbieten)
+
<span style="color:red">acl it-lan src 172.26.213.0/24</span>
 +
 
 +
acl SSL_ports port 443
 +
 
 +
acl Safe_ports port 80
 +
acl Safe_ports port 21
 +
acl Safe_ports port 443
 +
acl Safe_ports port 70
 +
acl Safe_ports port 210
 +
acl Safe_ports port 1025-65535
 +
acl Safe_ports port 280
 +
acl Safe_ports port 488
 +
acl Safe_ports port 591
 +
acl Safe_ports port 777
 +
 
 +
acl CONNECT method CONNECT
 +
 
 +
http_access deny !Safe_ports
 +
http_access deny CONNECT !SSL_ports
 +
 
 +
http_access allow localhost manager
 +
http_access deny manager
 +
 
 +
<span style="color:blue"># http_access allow localnet</span>
 +
 
 +
  <span style="color:red">http_access allow it-dmz</span>
 +
  <span style="color:red">http_access allow it-lan</span>
 +
 
 +
http_access allow localhost
 +
 
 +
http_access deny all
  
====Port auf Squid lauscht====
 
 
  http_port 3128
 
  http_port 3128
 
====Coredumpdir====
 
 
  coredump_dir /var/cache/squid
 
  coredump_dir /var/cache/squid
:wenn squid abstürzt wird dort ein Abbild geschrieben
 
====Refresh Pattern====
 
'''Eigentlich obsolet, da wegen dynamischer und verschlüsselten Webseiten nicht mehr gechached wird.'''
 
  
:Schlüsselwort   Pattern        Min     Prozent Max           
+
refresh_pattern ^ftp:           1440   20%     10080
 
  refresh_pattern ^gopher:        1440    0%      1440
 
  refresh_pattern ^gopher:        1440    0%      1440
 
  refresh_pattern -i (/cgi-bin/|\?) 0    0%      0
 
  refresh_pattern -i (/cgi-bin/|\?) 0    0%      0
 
  refresh_pattern .              0      20%    4320
 
  refresh_pattern .              0      20%    4320
  
*Hier kann der Refresh-Algorithmus von squid für die eigenen Bedürfnisse optimiert werden.
+
;RFC1918 wurde entfernt, damit nicht jeder Zugriff bekommt.
*MIN ist die Zeit in Minuten,die ein Objekt ohne explizite Ablaufzeit als Aktuell betrachtet wird. Der ermpfohlene Wert ist 0, jeder höhere Wert könnte dazu führen, dass dynmaische Anwendungen irrtümlich gecachtt werden, wenn der Webdesigner keine entsprechenden Gegenaktionen getroffen hat.
+
;Nur definierte Netze dürfen den Proxy nutzen.
*PROZENT ist der Prozentsatz eines Objektalters (Zeit seit der letzten Modifikation) wo ein Objekt ohne explizite Ablaufzeit als aktuell betrachtet wird.
 
*MAX ist ein oberes Limit wie lange Objekte ohne explizite Ablaufzeiten als aktuell betrachtet werden.
 
  
=First run=
+
==First run==
 
==läuft squid?==
 
==läuft squid?==
 
*ss -lntp | grep 3128
 
*ss -lntp | grep 3128
 +
;Zeigt ob Squid auf Port 3128 lauscht.
 +
;Kein Output = Dienst läuft nicht.
 +
 +
==starten==
 +
*systemctl start squid
 +
;Startet den Proxy-Dienst.
 +
;Fehler stehen im Journal.
  
==starten im Hintergrund==
 
* systemctl start squid
 
 
==Kontrolle==
 
==Kontrolle==
*tail -f /var/log/squid/access.log  
+
*tail -f /var/log/squid/access.log
1415788926.412  33247 192.168.244.1 TCP_MISS/200 3776 CONNECT aur.archlinux.org:443 - HIER_DIRECT/5.9.250.164 -
+
;Zeigt Live-Traffic durch den Proxy.
1415788926.424  33266 192.168.244.1 TCP_MISS/200 3822 CONNECT aur.archlinux.org:443 - HIER_DIRECT/5.9.250.164 -
+
;Wichtig zum Debuggen.
 +
 
 +
;TCP_MISS bedeutet kein Cache wurde genutzt.
 +
;CONNECT zeigt HTTPS-Tunnelverkehr.
 +
 
 +
==Hinweis==
 +
*HTTPS wird nur getunnelt (CONNECT)
 +
*Caching ist heute meist irrelevant
 +
;Für Inhaltsanalyse wäre SSL-Bump nötig.
 +
;In der Praxis dient Squid oft nur als Access-Proxy.

Version vom 2. April 2026, 12:51 Uhr

Installation

  • apt install squid-openssl
Installiert den Squid Proxy inkl. HTTPS-Unterstützung.
Ohne SSL-Unterstützung funktioniert CONNECT nicht korrekt.

Erste Schritte

Configdir

  • cd /etc/squid
Hier liegt die zentrale Konfigurationsdatei squid.conf.
Alle Anpassungen erfolgen in diesem Verzeichnis.

Default Konfiguration sichern

  • cp squid.conf squid.conf.org
Sichert die Originalkonfiguration.
Ermöglicht schnelles Zurücksetzen bei Fehlern.

Kommentare entfernen

  • grep "^[^#]" squid.conf.org > squid.conf
Entfernt Kommentare für bessere Übersicht.
Zeigt nur aktive Konfiguration.

Bereinigte squid.conf

acl localnet src 10.0.0.0/8
acl localnet src 172.16.0.0/12
acl localnet src 192.168.0.0/16
acl localnet src fc00::/7
acl localnet src fe80::/10
acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 21
acl Safe_ports port 443
acl Safe_ports port 70
acl Safe_ports port 210
acl Safe_ports port 1025-65535
acl Safe_ports port 280
acl Safe_ports port 488
acl Safe_ports port 591
acl Safe_ports port 777
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localnet
http_access allow localhost
http_access deny all
http_port 3128
coredump_dir /var/cache/squid
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320
Erlaubt allen internen Netzen Zugriff auf den Proxy.
Am Ende blockiert "deny all" alles nicht explizit Erlaubte.

Prinzip der ACL

  • Squid arbeitet von oben nach unten – erste passende Regel gewinnt.
Falsche Reihenfolge führt häufig zu unerwartetem Verhalten.
Debugging beginnt fast immer hier.

Konfiguration anpassen (eigene Netze)

Ziel ist es, Zugriff gezielt zu steuern.
Die Default-Konfiguration ist zu offen.

Neue squid.conf

# acl localnet src 10.0.0.0/8
# acl localnet src 172.16.0.0/12
# acl localnet src 192.168.0.0/16
acl localnet src fc00::/7
acl localnet src fe80::/10
acl it-dmz src 10.88.213.0/24
acl it-lan src 172.26.213.0/24
acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 21
acl Safe_ports port 443
acl Safe_ports port 70
acl Safe_ports port 210
acl Safe_ports port 1025-65535
acl Safe_ports port 280
acl Safe_ports port 488
acl Safe_ports port 591
acl Safe_ports port 777
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
# http_access allow localnet
http_access allow it-dmz
http_access allow it-lan
http_access allow localhost
http_access deny all
http_port 3128
coredump_dir /var/cache/squid
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320
RFC1918 wurde entfernt, damit nicht jeder Zugriff bekommt.
Nur definierte Netze dürfen den Proxy nutzen.

First run

läuft squid?

  • ss -lntp | grep 3128
Zeigt ob Squid auf Port 3128 lauscht.
Kein Output = Dienst läuft nicht.

starten

  • systemctl start squid
Startet den Proxy-Dienst.
Fehler stehen im Journal.

Kontrolle

  • tail -f /var/log/squid/access.log
Zeigt Live-Traffic durch den Proxy.
Wichtig zum Debuggen.
TCP_MISS bedeutet kein Cache wurde genutzt.
CONNECT zeigt HTTPS-Tunnelverkehr.

Hinweis

  • HTTPS wird nur getunnelt (CONNECT)
  • Caching ist heute meist irrelevant
Für Inhaltsanalyse wäre SSL-Bump nötig.
In der Praxis dient Squid oft nur als Access-Proxy.