投げ銭

★当サイトへの投げ銭(PayPal)★

LINK


(無償、寄付歓迎) logo
世界中で使われるISO標準オフィスソフト(MSオフィス互換)

★LibreOfficeの導入事例★
詳細について

人気の投稿(1ヶ月間)

Ad

Ad

投げ銭

★当サイトへの投げ銭(PayPal)★

2013年12月10日火曜日

【Linux CentOS6.4 64bit版】 ブラウザと同一のローカルマシンにプロキシSquidをインストールして利用するための設定【Squid x86_64 3.1.10】

CentOS 6.4 64bit(インストーラーで「デスクトップ」タイプを指定して導入したもの) に、
プロキシソフトウェア Squidをインストールした

ただし目的は、
スタンドアローンで動作するCentOSマシンのブラウザからhttpやhttpsで外部ネットワークへアクセスするときに、
同じマシンにインストールしたプロキシを経由させることである。
(他のマシンからのプロキシへのアクセスを受け付ける設定は考慮していない。)


■マシンの情報について

[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-358.18.1.el6.x86_64 #1 SMP Wed Aug 28 17:19:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux


■プロキシソフトウェアSquidのインストールを行った

○Squidの情報を表示させた

[root@localhost ~]# yum info squid
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: ftp.iij.ad.jp
 * extras: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
Available Packages
Name        : squid
Arch        : x86_64
Epoch       : 7
Version     : 3.1.10
Release     : 19.el6_4
Size        : 1.7 M
Repo        : base
Summary     : The Squid proxy caching server
URL         : http://www.squid-cache.org
License     : GPLv2 and (LGPLv2+ and Public Domain)
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.

○Squidのインストール

[root@localhost ~]# yum install squid
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package squid.x86_64 7:3.1.10-19.el6_4 will be installed
--> Processing Dependency: perl(DBI) for package: 7:squid-3.1.10-19.el6_4.x86_64
--> Running transaction check
---> Package perl-DBI.x86_64 0:1.609-4.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                Arch                                 Version                                           Repository                          Size
========================================================================================================================================================================
Installing:
 squid                                  x86_64                               7:3.1.10-19.el6_4                                 base                               1.7 M
Installing for dependencies:
 perl-DBI                               x86_64                               1.609-4.el6                                       base                               705 k

Transaction Summary
========================================================================================================================================================================
Install       2 Package(s)

Total download size: 2.4 M
Installed size: 7.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): perl-DBI-1.609-4.el6.x86_64.rpm                                                                                                           | 705 kB     00:00
(2/2): squid-3.1.10-19.el6_4.x86_64.rpm                                                                                                          | 1.7 MB     00:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   4.9 MB/s | 2.4 MB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : perl-DBI-1.609-4.el6.x86_64                                                                                                                          1/2
  Installing : 7:squid-3.1.10-19.el6_4.x86_64                                                                                                                       2/2
  Verifying  : 7:squid-3.1.10-19.el6_4.x86_64                                                                                                                       1/2
  Verifying  : perl-DBI-1.609-4.el6.x86_64                                                                                                                          2/2

Installed:
  squid.x86_64 7:3.1.10-19.el6_4

Dependency Installed:
  perl-DBI.x86_64 0:1.609-4.el6

Complete!


■Squidの設定ファイルを編集した

Squidの使用するアクセスポートを、8080に設定した。

[root@localhost ~]# vi /etc/squid/squid.conf
(略)
# Squid normally listens to port 3128
#http_port 3128
http_port 8080
(略)


■iptablesを設定した

ネットワークへProxyポートが開くので、iptablesを適切に設定し、起動しておく。

次の例では、CentOS 6.4 64bit版(デスクトップ用途)でデフォルトの設定から、
SSHへのアクセスルールを除いたものを用いていることがわかる。

ネットワークからProxyポートへの入力については、ステートフルインスペクションを利用して対策をしている。

Squidへのローカルプロセス(Firefoxなど)からのパケット入力に関する設定のポイントは、
loインターフェイスからの入力パケットのINPUTを許可していることである。

○IPv4のフィルタテーブルを表示させた
[root@localhost ~]# iptables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    6   396 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  any    any     anywhere             anywhere
    0     0 ACCEPT     all  --  lo     any     anywhere             anywhere
    0     0 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 REJECT     all  --  any    any     anywhere             anywhere            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 5 packets, 572 bytes)
 pkts bytes target     prot opt in     out     source               destination

○IPv6のフィルタテーブルを表示させた
[root@localhost ~]# ip6tables -L -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
 5552 8138K ACCEPT     all      any    any     anywhere             anywhere            state RELATED,ESTABLISHED
 3545  255K ACCEPT     ipv6-icmp    any    any     anywhere             anywhere
  306 24480 ACCEPT     all      lo     any     anywhere             anywhere
    0     0 REJECT     all      any    any     anywhere             anywhere            reject-with icmp6-adm-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 REJECT     all      any    any     anywhere             anywhere            reject-with icmp6-adm-prohibited

Chain OUTPUT (policy ACCEPT 12951 packets, 8673K bytes)
 pkts bytes target     prot opt in     out     source               destination


■Squidを起動した

○次のコマンドで、設定ファイルが有効になるとともに、Squidが起動する
[root@localhost ~]# service squid start
squid を起動中: .                                          [  OK  ] 

○開いているポートを確認できた
[root@localhost ~]# lsof -i -n -P | grep squid
squid     17487   squid    8u  IPv6 1347315      0t0  UDP *:34227
squid     17487   squid    9u  IPv4 1347316      0t0  UDP *:50600
squid     17487   squid   11u  IPv6 1347318      0t0  TCP *:8080 (LISTEN)

◎Squid起動後に、設定ファイルの変更を有効化する方法
プロキシのアドレスやポートの変更時には、ブラウザの変更と再起動も忘れないようにする。
# squid -k reconfigure


■ブラウザ Firefox の設定を行った

○Firefoxがプロキシを利用するように設定した

下記の手順で設定後は、Firefoxを再起動する必要がある。
(編集)→(詳細)→(ネットワーク)→(接続設定)
手動でプロキシを設定する(M)
HTTPプロキシ(X):localhost
ポート(P):8080


■動作チェックを行った

設定しFirefoxの再起動後、
http、httpsプロトコルで外部ネットワークサイトに接続できるかチェックした。

○ステートフルインスペクションのテーブルを参照し、ローカルプロセスFirefoxからの通信が、
プロキシサーバを経由していることを確認した。

パケットがIPv6アドレス0000:0000:0000:0000:0000:0000:0000:0001 (ループバックアドレス)の55555ポートから、
あて先アドレス0000:0000:0000:0000:0000:0000:0000:0001 (ループバックアドレス)の8080ポートに、
到達したことにより、ステート管理テーブルにその情報が現れていることがわかる。

[root@localhost ~]#  cat /proc/net/nf_conntrack | grep ipv6
(略)
ipv6     10 tcp      6 49 TIME_WAIT src=0000:0000:0000:0000:0000:0000:0000:0001 dst=0000:0000:0000:0000:0000:0000:0000:0001 sport=55555 dport=8080 src=0000:0000:0000:0000:0000:0000:0000:0001 dst=0000:0000:0000:0000:0000:0000:0000:0001 sport=8080 dport=55555 [ASSURED] mark=0 secmark=0 use=2

○あるいは、ブラウザから診断くんへアクセスして、プロキシ経由の通信になっているか確認する。
診断くん


(参考)
・Kulbir Saini / Squid Proxy Server 3.1 -Beginner's Guide / PACKT / Pages 308
< http://www.amazon.co.jp/Squid-Proxy-Server-3-1-Capabilities/dp/1849513902/ >

投げ銭

★当サイトへの投げ銭(PayPal)★

Ad

Ad