본문 바로가기

Linux Server 구축/6-1. Proxy Server

Proxy Server - Squid


Proxy Server 설치


1-1. squid rpm 설치

 
[root@server3 named]# rpm -qa | grep squid
[root@server3 Desktop]# ls
squid-2.6.STABLE6-5.el5_1.3.i386.rpm 
[root@server3 Desktop]# rpm -Uvh squid-2.6.STABLE6-5.el5_1.3.i386.rpm
준비 중...               ########################################### [100%]
   1:squid                  ########################################### [100%]



1-2. squid yum 설치

 
[root@server3 Desktop]# yum install squid*



3. 설치 확인

 
[root@server3 Desktop]# rpm -qa | grep squid
squid-2.6.STABLE6-5.el5_1.3
[root@server3 Desktop]# rpm -qi squid
Name        : squid                        Relocations: (not relocatable)
Version     : 2.6.STABLE6                       Vendor: CentOS
Release     : 5.el5_1.3                     Build Date:
Install Date:       Build Host: builder10.centos.org
Group       : System Environment/Daemons    Source RPM: squid-2.6.STABLE6-5.el5_1.3.src.rpm
Size        : 3498594                          License: GPL
Signature   : DSA/SHA1, 2008년 04월 19일 (토) 오전 01시 56분 19초, Key ID a8a447dce8562897
Summary     : Squid 프록시 캐시 서버.
Description :
Squid is a high-performance proxy caching server for Web clients,
supporting FTP, gopher, and HTTP data objects. Unlike traditional
caching software, Squid handles all requests in a single,
non-blocking, I/O-driven process. Squid keeps meta data and especially
hot objects cached in RAM, caches DNS lookups, supports non-blocking
DNS lookups, and implements negative caching of failed requests.

Squid consists of a main server program squid, a Domain Name System
lookup program (dnsserver), a program for retrieving FTP data
(ftpget), and some management and client tools.

[root@server3 Desktop]# rpm -ql squid | more

/etc/squid
/etc/squid/cachemgr.conf
/etc/squid/errors
/etc/squid/icons
/etc/squid/mib.txt
/etc/squid/mime.conf
/etc/squid/mime.conf.default
/etc/squid/msntauth.conf
/etc/squid/msntauth.conf.default
/etc/squid/squid.conf
/etc/squid/squid.conf.default



4. squid 환경설정

 
[root@server3 Desktop]# vi /etc/squid/squid.conf

72 # Squid normally listens to port 3128
73 http_port 3128 - 기본 port로 3128을 사용한다 다른 포트를 사용하려면 이 설정을 수정해 주면 된다..

992 #Default:
993 # cache_dir ufs /var/spool/squid 100 16 256 - 캐시 디렉토리 경로이다.

1086 #Default:
1087 # cache_log /var/log/squid/cache.log - access_log 파일이 있는 경로이다.

1381 #Default:
1382 # hosts_file /etc/hosts - hosts 파일이 있는 경로이다.


2393 #Recommended minimum configuration:
2394 acl all src 0.0.0.0/0.0.0.0
- 이 설정은 꼭 있어야 한다.

- 여기서 all (이름) = 0.0.0.0/0.0.0.0(IP대역) 을 의미한다.
즉, squid 에서는 ip 대신 이름을 지정해서 사용한다.


2395 acl linux7 src 10.10.0.0/255.255.0.0
- proxy server 를 이용하기 위해 10.10.0.0/255.255.0.0 대역대의 네트워크를 linux7이라는 이름으로 설정을 추가해준다.


2396 acl manager proto cache_object
2397 acl localhost src 127.0.0.1/255.255.255.255
2398 acl to_localhost dst 127.0.0.0/8
2399 acl SSL_ports port 443
2400 acl Safe_ports port 80          # http
2401 acl Safe_ports port 21          # ftp
2402 acl Safe_ports port 443         # https
2403 acl Safe_ports port 70          # gopher
2404 acl Safe_ports port 210         # wais
2405 acl Safe_ports port 1025-65535  # unregistered ports
2406 acl Safe_ports port 280         # http-mgmt
2407 acl Safe_ports port 488         # gss-http
2408 acl Safe_ports port 591         # filemaker
2409 acl Safe_ports port 777         # multiling http
2410 acl CONNECT method CONNECT


2504 #Recommended minimum configuration:
2505 #
2506 # Only allow cachemgr access from localhost
2507 http_access allow manager localhost - acl의 이름이 manager, localhost인 것만 http_access 접속을 허용한다.

2508 http_access allow linux7
- linux7의 http_access의 접속을 허용해주기 위해 추가해준다.

2509 http_access deny manager
2510 # Deny requests to unknown ports
2511 http_access deny !Safe_ports
2512 # Deny CONNECT to other than SSL ports
2513 http_access deny CONNECT !SSL_ports

2520 #http_access deny to_localhost

2530 # And finally deny all other access to this proxy
2531 http_access allow localhost

2532 http_access deny all
- 기본값으로 all (= 0.0.0.0/255.255.255.255 대의 네트워크) 는 http_access 접속을 거부한다.
즉, 모든 네트워크 대역의 접속을 거부해준다음 원하는 ip 만 접속허용을 해준다.




5. squid 서비스 시작

 
[root@server3 ~]# service squid start

[root@server3 ~]# tail -f /var/log/squid/access.log

1232672845.465     39 10.10.33.2 TCP_MISS/200 3306 GET http://imgshop.daum-img.net/image/cont/shoppingbox_W/abcmart_090116161521.gif - DIRECT/222.231.42.48 image/gif
1232672845.473     45 10.10.33.2 TCP_MISS/200 3280 GET http://imgshop.daum-img.net/image/cont/shoppingbox_W/lotteimall_090122133124.gif - DIRECT/222.231.42.48 image/gif
1232672845.475     14 10.10.33.2 TCP_MISS/200 2222 GET http://imgshop.daum-img.net/image/cont/shoppingbox_W/otto_090122110901.gif - DIRECT/222.231.42.48 image/gif

- 즉, 이렇게 자신의 프록시로 접속한 시스템을 알 수 있으며 관리 또는 방화벽 역할을 할 수 있다.



6. 사용자 Browser 설정

사용자가 프록시서버를 이용하기 위해서는 아래와 같이 설정을 해주어야 한다.

# 웹창 - 편집 - 환경설정 - 고급 - 네트워크 - 설정 : 프록시 수동 설정
HTTP 프록시 : (프록시서버주소:10.10.33.2)   /   포트 : 3128






7. squid를 이용해 특정 IP 를 차단하는 방법

 
[root@server3 Desktop]# vi /etc/squid/squid.conf

2394 acl all src 0.0.0.0/0.0.0.0
2395 acl linux7 src 10.10.0.0/255.255.0.0
2396 acl server2 src 10.10.33.2
  - 차단할 ip의 이름을 지정해준다.

2507 http_access allow manager localhost
2508 http_access allow linux7
2509 http_access deny server2 - 차단할 이름을 지정해준다.


[root@server3 Desktop]# service squid restart



8. 사용자 확인


10.10.33.2 의 IP를 가진 시스템에서 인터넷에 접속하려하면 위와 같은 화면에 뜨면서 인터넷이 되지 않는다.