【squid】ACLでWebフィルタリングを設定する方法【プロキシ】|スクショ付きで解説

Winodws
この記事は約21分で読めます。

squidで特定のサイトへのアクセスを制限したい。

プロキシサーバーでフィルタリングを行えるのか気になる

結論から先にお話しするとsquidでフィルタリングは可能です。


本記事では、squidでフィルタリングを設定する手順をスクリーンショット付きでご紹介しています。

初めてフィルタリングの設定へ挑戦する方でも分かるようstep by stepで解説していきます。

はじめに

squidを使ったことがない方は以下記事をご覧ください。

インストール~基本的な使い方までを画像付きで解説しています。

まなび丸
まなび丸

では、さっそく本題へいきましょう!

squidのwebフィルタリング設定手順

webフィルタリングとは

webフィルタリングについて先に補足しておきます。

webとは、特定のサイトへのアクセスを止めることができる機能を指します。

この機能を活用することで、ユーザー側が意図しないで危険なサイトへアクセスすることを事前に防止することができるのでセキュリティが向上します。

検証構成

今回は、Virtual boxを活用してsquidのwebフィルタリングを検証していきます。

検証環境で使用する仮想マシンのOSバージョンは以下の通りになります。

  • Virtual box
    バージョン 7.2.4 r170995
  • Windows Server 2022 Datacenter Evaluation
    バージョン 21H2 OS ビルド 20348.587
  • Windows 11 Enterprise Evaluation
    バージョン 24H2 OS ビルド 26100.6899

※Windows Server 2022が「Datacenter Evaluation」になっていますが、特に意味はありません。

プロキシサーバーとクライアントのホスト名とIPアドレスの割り当ては以下の通りです。

役割OSホスト名IPアドレス
プロキシサーバーWindows Serverproxy-svr-0110.0.2.15 /24
クライアントPCWindows 11proxy-client-0110.0.2.10 /24

今回の検証のゴールは以下の通りとします。

ゴール

特定のサイト(https://www.kuwamakurano98.com/)へのアクセス制限を行う

※上記サイトは私が運営している「ゆる勉ITブログ」のサイトになります。

squidのwebフィルタリング設定

squidでwebフィルタリングを行うにあたり、「ACL」を活用していきます。

ACLとは「アクセス コントロール リスト」の略になります。

squidでもACLの基本的な考え方は同じになります。ACLの考え方は以下にまとめておきます。

  • ACLで記載されたルールを上から確認していき、合致したルールを適用する流れ
  • 合致した時点で、それ以降のルールは確認しない
  • 合致するルールがなかった場合は、最後「暗黙のDeny」が適用され、通信が拒否される

squidの場合、confファイルを確認すると分かりやすく「暗黙のDeny」を記載しています。笑

# And finally deny all other access to this proxy
http_access deny all

squidでは以下手順でACLの作成と適用を行っていきます。

  1. ACLのルールを作成
  2. ルールを「accept」するか「Deny」するのかを定義する

通常のACL(例えば、ciscoのルーターなど)では1行でACLの条件と通信の「許可 or 拒否」を決めますが、squidの場合、ACLの内容と通信の許可 or 拒否は分けて記載する点が特有のクセだと考えられます。

まなび丸
まなび丸

ただし、記載する内容はシンプルで分かりやすいのでそこまで苦戦はしないと思います!

squidでのACLの書き方は以下の通りです。

acl [acl名] dstdomain .[対象サイトのドメイン]

「accept」もしくは「Deny」を決める方法は以下の通りになります。

http_access [deny/allow] [acl名]

今回の検証では以下のようなACLの書き方になります。

#ACLのルール
acl deny_mysite_test dstdomain .kuwamakurano98.com

#ルールを「Deny」として設定する
http_access deny deny_mysite_test

記述はsquidのconfファイルに記載していきます。

以下のコードがsquidのconfファイルの中身です。
緑太文字になっているのが先ほど作成したコンフィグの追記箇所になります。

#」でコメントアウトできますので、ACLの中身と適用箇所について記載しました。

#
# Recommended minimum configuration:
#

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed

acl localnet src 10.0.0.0/8	# RFC1918 possible internal network
acl localnet src 172.16.0.0/12	# RFC1918 possible internal network
acl localnet src 192.168.0.0/16	# RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80		# http
acl Safe_ports port 21		# ftp
acl Safe_ports port 443		# https
acl Safe_ports port 70		# gopher
acl Safe_ports port 210		# wais
acl Safe_ports port 1025-65535	# unregistered ports
acl Safe_ports port 280		# http-mgmt
acl Safe_ports port 488		# gss-http
acl Safe_ports port 591		# filemaker
acl Safe_ports port 777		# multiling http
acl CONNECT method CONNECT

#検証用のALC定義を追加
acl deny_mysite_test dstdomain .kuwamakurano98.com

#
# Recommended minimum Access Permission configuration:
#

#検証用のALCを適用
http_access deny deny_mysite_test

#

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128

# Uncomment the line below to enable disk caching - path format is /cygdrive/<full path to cache folder>, i.e.
#cache_dir aufs /cygdrive/d/squid/cache 3000 16 256


# Leave coredumps in the first cache dir
coredump_dir /var/cache/squid

# Add any of your own refresh_pattern entries above these.
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

dns_nameservers 8.8.8.8 208.67.222.222

max_filedescriptors 3200
まなび丸
まなび丸

次のセクションでは動作確認をおこなってきます!

webフィルタリングの動作確認

動作確認を行う前に、squdのポイントだけ際にお伝えしておきます。

squidでは設定を反映させる場合、以下どちらかの対応が必要となります。

  • squidを再起動させる
  • Squid Terminalを開き、「squid -k reconfigure」コマンドを実行する

個人的には、再起動よりもコマンドを実行する方が手間が少ないのでおすすめです。
※設定が反映されない場合は再起動を試してみてください。

では動作確認を行ってきます。

confファイルにACLの設定を行った後は、設定をsquidへ読み込ませる前にクライアントから対象サイトへアクセスできることを確認しておきます。

それでは設定をsquidへ読み込ませていきましょう。

今回はコマンドを用いて設定を再読み込みさせる方法をご紹介します。

  • step.1
    Squid terminalを開きます
  • step.2
    Squid terminalが立ち上がることを確認します
  • step.3
    設定を再読み込みするコマンドを実行する

    以下コマンドを実行します。

    squid -k reconfigure

    このコマンドはconfファイルに新たに設定したコマンドをsquidへ再読み込みさせるコマンドです。

    特にエラーが表示されずに次の行で「C:\Squid>」のプロンプトが表示されていれば、OKです。

上記手順が実行できたら、クライアントからアクセスを制限したサイト(https://www.kuwamakurano98.com/)へアクセスできないことが確認を確認します。

ほかのサイトへアクセスができることも確認します。

※以下例では、google.comへアクセスしています。

まなび丸
まなび丸

ここまででwebフィルタリングの設定方法は完了になります!

webフィルタリングが反映されない時

confファイルにACLを設定したのにも関わらず、特定のサイトへの制限ができない場合の対処法を解説します。

構文チェックを行う

まず疑うべきは、「記載したACLが本当に正しいのか」確認することです。

squidでは Squid Terminalを用いてconfファイルの中身を確認するコマンドが用意されています。

確認コマンドは以下の通りです。

squid -k parse

実際に実行した結果は以下の通りです。

正しく設定できている場合は、緑太文字の箇所でハイライトしたように「Processing」となります。

C:\Squid>squid -k parse
2025/11/12 13:11:15| Startup: Initializing Authentication Schemes ...
2025/11/12 13:11:15| Startup: Initialized Authentication Scheme 'basic'
2025/11/12 13:11:15| Startup: Initialized Authentication Scheme 'digest'
2025/11/12 13:11:15| Startup: Initialized Authentication Scheme 'negotiate'
2025/11/12 13:11:15| Startup: Initialized Authentication Scheme 'ntlm'
2025/11/12 13:11:15| Startup: Initialized Authentication.
2025/11/12 13:11:15| Processing Configuration File: /etc/squid/squid.conf (depth 0)
2025/11/12 13:11:15| Processing: acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
2025/11/12 13:11:15| Processing: acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
2025/11/12 13:11:15| Processing: acl localnet src 192.168.0.0/16        # RFC1918 possible internal network
2025/11/12 13:11:15| Processing: acl localnet src fc00::/7       # RFC 4193 local private network range
2025/11/12 13:11:15| Processing: acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
2025/11/12 13:11:15| Processing: acl SSL_ports port 443
2025/11/12 13:11:15| Processing: acl Safe_ports port 80         # http
2025/11/12 13:11:15| Processing: acl Safe_ports port 21         # ftp
2025/11/12 13:11:15| Processing: acl Safe_ports port 443                # https
2025/11/12 13:11:15| Processing: acl Safe_ports port 70         # gopher
2025/11/12 13:11:15| Processing: acl Safe_ports port 210                # wais
2025/11/12 13:11:15| Processing: acl Safe_ports port 1025-65535 # unregistered ports
2025/11/12 13:11:15| Processing: acl Safe_ports port 280                # http-mgmt
2025/11/12 13:11:15| Processing: acl Safe_ports port 488                # gss-http
2025/11/12 13:11:15| Processing: acl Safe_ports port 591                # filemaker
2025/11/12 13:11:15| Processing: acl Safe_ports port 777                # multiling http
2025/11/12 13:11:15| Processing: acl CONNECT method CONNECT
2025/11/12 13:11:15| Processing: acl deny_mysite_test dstdomain .kuwamakurano98.com
2025/11/12 13:11:15| Processing: http_access deny deny_mysite_test
2025/11/12 13:11:15| Processing: http_access allow localhost manager
2025/11/12 13:11:15| Processing: http_access deny manager
2025/11/12 13:11:15| Processing: http_access deny !Safe_ports
2025/11/12 13:11:15| Processing: http_access deny CONNECT !SSL_ports
2025/11/12 13:11:15| Processing: http_access allow localnet
2025/11/12 13:11:15| Processing: http_access allow localhost
2025/11/12 13:11:15| Processing: http_access deny all
2025/11/12 13:11:15| Processing: http_port 3128
2025/11/12 13:11:15| Processing: coredump_dir /var/cache/squid
2025/11/12 13:11:15| Processing: refresh_pattern ^ftp:          1440    20%     10080
2025/11/12 13:11:15| Processing: refresh_pattern ^gopher:       1440    0%      1440
2025/11/12 13:11:15| Processing: refresh_pattern -i (/cgi-bin/|\?) 0    0%      0
2025/11/12 13:11:15| Processing: refresh_pattern .              0       20%     4320
2025/11/12 13:11:15| Processing: dns_nameservers 8.8.8.8 208.67.222.222
2025/11/12 13:11:15| Processing: max_filedescriptors 3200
2025/11/12 13:11:15| Initializing https:// proxy context

C:\Squid>

構文が間違っている場合ですと、以下緑文字でハイライトした通りエラーが表示されています。

※ACLの名前をあえて「deny_mysite_」にしています。

C:\Squid>squid -k parse
2025/11/12 13:13:39| Startup: Initializing Authentication Schemes ...
2025/11/12 13:13:39| Startup: Initialized Authentication Scheme 'basic'
2025/11/12 13:13:39| Startup: Initialized Authentication Scheme 'digest'
2025/11/12 13:13:39| Startup: Initialized Authentication Scheme 'negotiate'
2025/11/12 13:13:39| Startup: Initialized Authentication Scheme 'ntlm'
2025/11/12 13:13:39| Startup: Initialized Authentication.
2025/11/12 13:13:39| Processing Configuration File: /etc/squid/squid.conf (depth 0)
2025/11/12 13:13:39| Processing: acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
2025/11/12 13:13:39| Processing: acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
2025/11/12 13:13:39| Processing: acl localnet src 192.168.0.0/16        # RFC1918 possible internal network
2025/11/12 13:13:39| Processing: acl localnet src fc00::/7       # RFC 4193 local private network range
2025/11/12 13:13:39| Processing: acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
2025/11/12 13:13:39| Processing: acl SSL_ports port 443
2025/11/12 13:13:39| Processing: acl Safe_ports port 80         # http
2025/11/12 13:13:39| Processing: acl Safe_ports port 21         # ftp
2025/11/12 13:13:39| Processing: acl Safe_ports port 443                # https
2025/11/12 13:13:39| Processing: acl Safe_ports port 70         # gopher
2025/11/12 13:13:39| Processing: acl Safe_ports port 210                # wais
2025/11/12 13:13:39| Processing: acl Safe_ports port 1025-65535 # unregistered ports
2025/11/12 13:13:39| Processing: acl Safe_ports port 280                # http-mgmt
2025/11/12 13:13:39| Processing: acl Safe_ports port 488                # gss-http
2025/11/12 13:13:39| Processing: acl Safe_ports port 591                # filemaker
2025/11/12 13:13:39| Processing: acl Safe_ports port 777                # multiling http
2025/11/12 13:13:39| Processing: acl CONNECT method CONNECT
2025/11/12 13:13:39| Processing: acl deny_mysite_test dstdomain .kuwamakurano98.com
2025/11/12 13:13:39| Processing: http_access deny deny_mysite_
2025/11/12 13:13:39| ACL not found: deny_mysite_
2025/11/12 13:13:39| Not currently OK to rewrite swap log.
2025/11/12 13:13:39| storeDirWriteCleanLogs: Operation aborted.
2025/11/12 13:13:39| FATAL: Bungled /etc/squid/squid.conf line 37: http_access deny deny_mysite_
2025/11/12 13:13:39| Squid Cache (Version 4.14): Terminated abnormally.
CPU Usage: 0.046 seconds = 0.000 user + 0.046 sys
Maximum Resident Size: 791552 KB
Page faults with physical i/o: 3191

C:\Squid>

上記エラーと同じになるとは限りませんが、一度こちらのコマンドを活用して構文の確認をしてみてください。

まとめ

以上、squidでwebフィルタリングを設定する手順を解説しました。

webフィルタリングで表示されるブロックページですが、実はsquidで設定したカスタムページを表示させることも可能です。

以下記事では、squidでwebフィルタリングを行った際に表示させるブロックページのカスタマイズ方法について解説しています。

よりsquidを使いこなしたい方は以下記事を参考にして挑戦してみてください。

参考サイト

コメント

タイトルとURLをコピーしました