Win(Host)+Lenny(Guest)多段プロキシ

■ホストOS(WinXP)とvmplayerのゲスト(Lenny)2段プロキシを設定する。
 WindowsUpdateもaptやyum同様、別途プロキシの設定が必要というところがポイント。
 FW等でプロキシを通さないと外に出れない場合は特に。
 ※WinXPにはGowが導入済みです。

 今更WinXP初期設定
 http://d.hatena.ne.jp/labunix/20120118

■ゲストのlocalhostは「127.0.1.1/32」
 ホストのlocalhostは「127.0.0.1/32」
 ホストのポートは「3128」
 ゲストのポートは「7080」

 ※「strip_query_terms off」で検索文字列もログに出力する
 ※この後、もう一段上位プロキシを追加して問題無く動作している。

$ sudo diff squid.conf squid.conf.org
601c601
< acl localhost src 127.0.1.1/32
---
> acl localhost src 127.0.0.1/32
610d609
< #acl localnet src 192.168.132.0/24
656d654
< http_access allow localnet
1112c1110
< http_port 7080
---
> http_port 3128
1608d1605
< cache_peer host-winxp parent 3128 3130 no-query default
2091c2088
< logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
---
> #logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
2118,2119c2115
< #access_log /var/log/squid/access.log squid
< access_log /var/log/squid/access.log combined
---
> access_log /var/log/squid/access.log squid
2206d2201
< logfile_rotate 7
2315d2309
< strip_query_terms off
3388d3381
< visible_hostname vmlenny86a
4420d4412
< never_direct allow all

■WinXPホストOS側のsquidの設定
 ※ホスト側のキャッシュサイズは32MBに設定

$ diff squid.conf squid.conf.default
577d576
< acl localnet src 192.168.100.0/24
617d615
< http_access allow localnet
1607d1604
< cache_mem 32 MB
1946c1943
< logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
---
> #logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
1976c1973
< access_log c:/squid/var/logs/access.log combined
---
> access_log c:/squid/var/logs/access.log squid
2053c2050
< logfile_rotate 7
---
>
2161d2157
< strip_query_terms off
3046d3041
< visible_hostname host-winxp

■ゲスト(Lenny)のブラウザプロキシの設定

$ grep -i proxy /etc/profile
export http_proxy=http://vmlenny86a:7080/
export ftp_proxy=http://vmlenny86a:7080/
export HTTP_PROXY=http://vmlenny86a:7080/
export FTP_PROXY=http://vmlenny86a:7080/

■ホスト(Windows)のプロキシ設定
 ※「file:///c:/proxy.pac」としてブラウザに設定

> cat c:\proxy.pac
function FindProxyForURL(url, host)
{
        if ( ( isPlainHostName( host )                     )    ||
             ( isInNet(host, "192.168.100.0", "255.255.255.0") )    ||
             ( shExpMatch( url, "http://127.0.0.1*"      ) )    ||
             ( shExpMatch( url, "http://localhost*"      ) ) )   {
             return "DIRECT";
        }
        else {
             return "PROXY 192.168.100.68:3128";
        }
}

■ゲスト(Lenny)の「/etc/apt/apt.conf」の設定
 ※aptブラウザは「"Debian APT-HTTP/1.3 (0.7.20.2)"」

$ cat /etc/apt/apt.conf
Acquire::http::Proxy "http://vmlenny86a:7080/";

■ホスト(Windows)の「proxycfg」の設定
 ※WindowsUpdateブラウザは「"Microsoft BITS/6.7"> sc GetKeyName "Background Intelligent Transfer Service"
[SC] GetServiceKeyName SUCCESS  Name = BITS

> cat c:\WINDOWS\WindowsProxySettings.bat
@echo off
cd /d c:\WINDOWS
proxycfg -d 
proxycfg -u
net stop "Background Intelligent Transfer Service"
net start "Background Intelligent Transfer Service"
proxycfg > WUSettings.log

> WindowsUpdateSettings.bat
Microsoft (R) WinHTTP Default Proxy Configuration Tool
Copyright (C) Microsoft Corporation. All rights reserved.

更新されたプロキシ設定
現在の WinHTTP プロキシ設定:
  HKEY_LOCAL_MACHINE\
    SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\
      WinHttpSettings :

     直接アクセス (プロキシ サーバーなし)
Microsoft (R) WinHTTP Default Proxy Configuration Tool
Copyright (C) Microsoft Corporation. All rights reserved.

更新されたプロキシ設定
現在の WinHTTP プロキシ設定:
  HKEY_LOCAL_MACHINE\
    SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Connections\
      WinHttpSettings :

    プロキシ サーバー:  192.168.100.68:3128
    バイパス一覧     :  localhost;<local>