平衡点


2010/05/18

_ mobile 環境での proxy の proxy

4 月からの職場では上流に proxy がいらっしゃって, 外部への接続は全てこの proxy を通すようになっている. それ自体は良いのだけれど, ラップトップを常に持ち歩いて移動している身としては, 繋がった時に自動的に proxy を切り替えたくなる(というか, proxy のいちいちゴニョゴニョして, なんて考えたくない). アプリケーションレベルでは, firefox みたいに「proxy を自動判別する」なんてのもあるけれど, 全てがそういうわけでもないし.

DNS は localhost で DNS proxy を上げて resolvconf で動的に上流を切り変える, ということをしていて, 特にこれといって手元でゴニョゴニョする必要はない((最近 pdnsd が上流を判断できない事が多くて気にはなっているけれど)).

でも, 他のアプリケーションはそうはいかなくて, ちょっと面倒なので結構ストレスが溜っていた.

というわけで

  • 手元で透過 proxy を立ち上げる
  • アプリケーションは常に proxy として localhost を見に行くようにする
  • ifup|down|ppp の際に上流の proxy を切り替える

ようにしてみた

squid で透過 proxy

というわけで squid で透過 proxy を上げてみた.

$ sudo aptitude install squid

まずは直接接続の設定. キャッシュは使わないことにする.

$ sudo vim /etc/squid/squid-direct.conf

acl all src all
# localhost のみ.
acl localhost src 127.0.0.1
# well-known, unregisted
acl SSL_ports port 443		# https
acl SSL_ports port 563		# snews
acl SSL_ports port 873		# rsync
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 Safe_ports port 631		# cups
acl Safe_ports port 873		# rsync
acl Safe_ports port 901		# SWAT
# client でのアクセス
acl purge method PURGE
# TLS 開始メソッドである CONNECT の定義
acl CONNECT method CONNECT
# client でのアクセスは localhost からのみ.
http_access allow purge localhost
http_access deny purge
# Safe_ports 以外の接続は拒否
http_access deny !Safe_ports
# SSL_ports 以外の接続は CONNECT を使わない
http_access deny CONNECT !SSL_ports
# localhost からは全て許可
http_access allow localhost
# それ以外は不許可
http_access deny all
# icp も localhost だけ
icp_access allow localhost
icp_access deny all
# サーバに IP を送らない.
forwarded_for off
# 透過 proxy. XXXX はポート番号
http_port XXXX transparent
# ヘッダの書き変えをしない.
update_headers off
hosts_file /etc/hosts
# log format apache like
access_log /var/log/squid/access.log squid
logformat common %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st %Ss:%Sh
# キャッシュしない
cache deny all
cache_dir null /dev/null
cache_mem 0 MB
maximum_object_size 0 KB
# ip もキャッシュしない
ipcache_size 0
# store_log は不要
cache_store_log none
emulate_httpd_log on
coredump_dir /var/spool/squid
client_db off
memory_pools off
maximum_single_addr_tries 5
strip_query_terms off
# direct
always_direct allow all

続いて上流の proxy の場合, 以下は kuins の場合.

$ sudo vim /etc/squid/squid-kuins.conf

acl all src all
# localhost のみ.
acl localhost src 127.0.0.1
... 以下, direct まで上記と同じ
# direct
# always_direct allow all <- comment out
# kusm
acl KYOTO-U dstdomain kyoto-u.ac.jp
always_direct allow KYOTO-U
acl KUINS dstdomain kuins.net
always_direct allow KUINS
cache_peer proxy.kuins.net parent 8080 0 no-digest
never_direct allow all

といった塩梅で.

ifup|ifdown での hook

/etc/resolvconf/update-libc.d/squid に Hook スクリプトがあってresolvconf で DNS を切り替える際に squid も reload してくれる.なので /etc/network/interfaces で pre-up/post-down できりかえることにする.例えば

...
iface kuins3 inet dhcp
  pre-up cp /etc/squid/squild-kusm.conf /etc/squid/squid.conf
  post-down cp /etc/squid/squid-direct.conf /etc/squid/squid.conf
...

ppp の場合には既に /etc/ppp/ip-up.d/000resolvconf があったのでとりあえず resolveconf に任せることにする.

まとめ

というわけで local に透過 proxy を立ててみたわけですが. 想像以上に快適です.あるていど log 眺めて, 問題無いようなら zshenv に proxy 設定しておくつもり.

とりあえず /etc/apt/apt.conf.d/02proxy は設定しておきました:

# XXXX はポート番号
Acquire::http::Proxy "http://localhost:XXXX";

ストレス一個解消.


連絡先など
最近の日記
一覧
2006|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|02|03|04|08|09|10|11|12|
2013|01|02|03|04|05|06|08|09|10|11|12|
2014|01|02|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|09|10|
2016|02|03|
2017|01|02|03|05|06|07|09|11|12|
2018|03|06|07|10|11|12|
2019|01|02|03|04|05|07|10|12|
2020|01|02|03|04|05|08|09|10|11|12|
2021|01|02|03|05|06|07|08|09|11|12|
2022|01|02|03|04|05|06|08|10|11|12|
2023|02|03|04|06|08|09|11|12|
2024|01|02|03|
Back to Top ▲