Installation d’un proxy Squid
version OS: Centos 6.8
version Squid: 3.1
Pré requis
Voir l’article Préparation d’une machine Centos 6.x
1.Installation du paquet squid
1 |
$ sudo yum install squid |
Éditer le fichier de conf squid et ajouter les modification en gras dans le texte
1 |
$ sudo vim /etc/squid/squid.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
acl Safe_ports port 777 # multiling http acl CONNECT method CONNECT <strong>acl lan src 192.168.3.0/24</strong> <span style="color: #ff0000;"><-- Autoriser le réseau local</span> # # Recommended minimum Access Permission configuration: # # Only allow cachemgr access from localhost # from where browsing should be allowed http_access allow localnet http_access allow localhost <strong>http_access allow lan</strong> <span style="color: #ff0000;"><-- Autoriser les aces lan</span> # And finally deny all other access to this proxy http_access deny all # Squid normally listens to port 3128 <strong>http_port 8080 </strong><span style="color: #ff0000;"><-- définir le port</span> # Uncomment and adjust the following to add a disk cache directory. #cache_dir ufs /var/spool/squid 100 16 256 refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 refresh_pattern . 0 20% 4320 <strong>request_header_access Referer deny all</strong> <strong>request_header_access X-Forwarded-For deny all</strong> <strong>request_header_access Via deny all</strong> <strong>request_header_access Cache-Control deny all</strong> <strong>visible_hostname proxy.domain.tld <-- </strong> <strong>forwarded_for off </strong><span style="color: #ff0000;"><-- pour ne pas afficher le proxy</span> |
Rendre le service automatique et le démarrer
1 2 |
$ sudo chkconfig squid on $ sudo /etc/rc.d/init.d/squid start |
/!\ Penser a ouvrir le port 8080 dans Iptables
Modifier les paramètres du navigateur pour tester le proxy
2.Configuration des clients Linux
Éditer le fichier profile et ajouter en fin de ligne
1 |
$ sudo vim /etc/profile |
1 2 3 4 5 6 7 8 |
MY_PROXY_URL="http://proxy.domain.local:8080/" HTTP_PROXY=$MY_PROXY_URL HTTPS_PROXY=$MY_PROXY_URL FTP_PROXY=$MY_PROXY_URL http_proxy=$MY_PROXY_URL https_proxy=$MY_PROXY_URL ftp_proxy=$MY_PROXY_URL export HTTP_PROXY HTTPS_PROXY FTP_PROXY http_proxy https_proxy ftp_proxy |
Puis recharger le fichier
1 |
$ sudo source /etc/profile |
Ajouter également en fin de ligne pour le fichier de conf yum
1 |
$ sudo vim /etc/yum.conf |
1 |
proxy=http://proxy.domain.local:8080/ |
Et en fin de ligne pour le fichier de conf wget
1 |
# vim /etc/wgetrc |
1 2 3 |
http_proxy = http://proxy.domain.local:8080/ https_proxy = http://proxy.domain.local:8080/ ftp_proxy = http://proxy.domain.local:8080/ |
3.Pour les navigateurs
Renseigner adresse IP ou nom d’hôte dans le paramètre réseau dans les navigateurs.
4.Utiliser une authentification
Il faut installer le paquet httpd-tools, nécessaire pour l’authentification http
1 |
$ sudo yum install httpd-tools |
Éditer le fichier de conf squid et ajout de directive en gras dans le texte
1 |
$ sudo vim /etc/squid/squid.conf |
1 2 3 4 5 6 7 8 9 10 |
acl CONNECT method CONNECT acl lan src 192.168.3.0/24 <strong>auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/.htpasswd</strong> <strong>auth_param basic children 5</strong> <strong>auth_param basic realm Squid Basic Authentication</strong> <span style="color: #000080;"><span style="color: #ff0000;"><-- Type d'authentification</span></span> <strong>auth_param basic credentialsttl 1 hours</strong> <span style="color: #000080;"><span style="color: #ff0000;"><-- Durée des credentials</span></span> <strong>acl password proxy_auth REQUIRED</strong> <strong>http_access allow password</strong> # # Recommended minimum Access Permission configuration: |
Création d’un utilisateur et son mot de passe
1 |
$ sudo htpasswd -c /etc/squid/.htpasswd nom_de_l'utilisateur |
1 2 |
New password: ***** Re-type new password: ***** |
Puis redémarrer le service squid
1 |
$ sudo /etc/rc.d/init.d/squid restart |
A l’ouverture d’un navigateur, renseigner les credentials précédemment crée.