Lionel Blog

The road is under your feet, the heart looks to the distance

squid

설치

sudo apt update 
sudo apt install squid

상태확인

  • 설치하면 자동으로 시작 됨. 다음의 명령어로 상태 확인
sudo systemctl status squid

다시 실행하기

sudo squid -k parse  # 설정 오류 확인 (오류 없으면 OK)
sudo systemctl restart squid
sudo systemctl status squid  # active (running) 확인
sudo ufw allow 3128  # 방화벽 열기 (uFW 사용 시)

설정

  • /etc/squid/squid.conf 파일을 수정해서 설정 가능
# cat /etc/squid/squid.conf
 
# 기본 포트 (터널링 모드, intercept 없음)
http_port 3128

# ACL 정의 (HTTPS CONNECT 허용 필수)
acl localnet src 192.168.71.0/24  # Raspberry Pi 네트워크 (IP 범위 조정 가능, 테스트용: acl localnet src 0.0.0.0/0)
acl SSL_ports port 443
acl Safe_ports port 80          # HTTP
acl Safe_ports port 443         # HTTPS (중복 포함으로 안전)
acl CONNECT method CONNECT

# 기본 포트 보호 (기본 deny)
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports

# 접근 허용 (localnet에 CONNECT 허용, 순서 중요: allow 전에 deny!)
http_access allow localnet Safe_ports
http_access allow CONNECT localnet SSL_ports
http_access deny all  # 마지막에 deny all

# 로그 및 캐시 (기본값)
access_log /var/log/squid/access.log squid
cache_dir ufs /var/spool/squid 100 16 256
coredump_dir /var/spool/squid

# 기타 (헤더 전달 위해 via off, 테스트용)
via off
  • squid는 기본 포트가 3128

특정 ip만 허용 (Access control list)

  • 위의 acl localnet src 192.168.71.0/2 대신 다음을 설정하고
acl allowed_ips src "/etc/squid/allowed_ips.txt"

해당 파일을 만들어서 허용할 ip를 등록

# /etc/squid/allowed_ips.txt

192.168.33.1
# All other allowed IPs

기타 기능

  • 인증된 사용자만 접근 하게 할 수도 있음. /etc/squid/htpasswd
  • http 기본 자격증명 인증도 가능

사용하는 방법

  1. 각 브라우저에서 proxy 설정을 하거나
  2. /etc/environment 파일에서 전체 적용 가능.
pi@raspberrypi2:~/dev $ cat /etc/environment
http_proxy="http://192.168.71.39:3128/"
https_proxy="http://192.168.71.39:3128/"
no_proxy="localhost,127.0.0.1,192.168.71.117,192.168.71.118,239.0.0.0/8"