https://end0tknr.hateblo.jp/entry/20261026/1792962540
先日の上記entryの oracle linux版です
目次
- wsl自体のインストールと最新化
- wslへの Oracle Linuxのインストールと最新化
- pythonはoracle linux付属のものを利用
- Claude Codeインストール
- windows側dirのmount
- 接続先の制限
- ログの収集
- 作業ユーザからsudo権限削除
wsl自体のインストールと最新化
windowsのコマンドプロンプトから以下を実行後、pc再起動
CMD> wsl --install CMD> wsl --update
wslへの Oracle Linuxのインストールと最新化
windowsのコマンドプロンプトからOracle Linuxのインストール
※インストール中に聞かれるusernameは、要調整
# オンライン配布されているlinux distributionの一覧確認 CMD> wsl --list --online # oracle linuxのインストール CMD> wsl --install OracleLinux_9_5 # oracle linuxの起動。起動するとプロンプト表示が変更 CMD> wsl -d OracleLinux_9_5 [ユーザ名@ホスト名 ~]$
今回のPCはproxy内にある為、wsl内のdnf.conf編集と、windows内に.wslconfig新規作成
$ sudo vi /etc/dnf/dnf.conf [main] gpgcheck=1 installonly_limit=3 clean_requirements_on_remove=True best=True skip_if_unavailable=False assumeyes=True sslverify=False # 行追加
CMD> vi c:/Users/ユーザ名/.wslconfig [wsl2] networkingMode=consomme dnsTunneling=true autoProxy=true
Oracle Linuxの最新化
$ sudo dnf update
sysytemdによるdaemonを利用できる様、wsl.conf を編集後、wsl再起動
$ sudo vi /etc/wsl.conf [boot] systemd=true
wsl 再起動
停止 CMD> wsl --shutdown 起動 CMD> wsl
pythonはoracle linux付属のものを利用
python本体はインストール済みでしたので、pipのみ追加
$ /usr/bin/python3 --version Python 3.9.25 $ sudo dnf install python3-pip
Claude Codeインストール
https://code.claude.com/docs/ja/setup
Claude Codeインストール
$ sudo tee /etc/yum.repos.d/claude-code.repo <<'EOF' [claude-code] name=Claude Code baseurl=https://downloads.claude.ai/claude-code/rpm/stable enabled=1 gpgcheck=1 gpgkey=https://downloads.claude.ai/keys/claude-code.asc EOF $ sudo dnf install claude-code
環境変数PATHの編集や、インストールされたclaudeのバージョン確認
$ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc $ source ~/.bashrc $ claude --version 2.1.311 (Claude Code)
windows側dirのmount
$ sudo mkdir -p /mnt/claude_pc $ sudo mkdir -p /mnt/claude_share $ cd $ ln -s /mnt/claude_pc . $ ln -s /mnt/claude_share .
$ sudo vi /etc/fstab C:/claude_pc /mnt/claude_pc drvfs rw,nofail 0 0 S:/software/claude_share /mnt/claude_share drvfs ro,nofail 0 0
※ rw:読書きOK、ro:読取りのみ
接続先の制限
必要パッケージのインストール
$ sudo dnf install \
squid \
iptables \
iptables-services \
curl \
jq \
procps-ng \
shadow-utils \
tree
squidによる接続先制限
squid.confをバックアップ後、書換え
$ sudo cp -a /etc/squid/squid.conf /etc/squid/squid.conf.org $ sudo vi /etc/squid/squid.conf
squid.confの書換え内容は以下
# WSL内部からのみ利用可能 http_port 127.0.0.1:3128 # Claude Code関連の接続先 acl allowed_domains dstdomain \ .oracle.com \ .anthropic.com \ .claude.ai \ .claude.com \ .statsig.com \ .sentry.io \ .pypi.org \ .pythonhosted.org #.github.com \ #.githubusercontent.com # HTTPS CONNECTは443番ポートのみ acl SSL_ports port 443 acl CONNECT method CONNECT # HTTPS:許可ドメインのみ http_access deny CONNECT !SSL_ports http_access allow CONNECT allowed_domains # HTTP:許可ドメインなら任意のポートを許可 http_access allow allowed_domains # その他はすべて拒否 http_access deny all # キャッシュを使用しない cache deny all # win pcのあるproxyのssl verifyを解除 sslproxy_cert_error allow all # tls_outgoing_options flags=DONT_VERIFY_PEER
設定検証後、squid起動
$ sudo squid -k parse 2026/11/14 06:31:51| Startup: Initializing Authentication Schemes ... 2026/11/14 06:31:51| Startup: Initialized Authentication Scheme 'basic' 2026/11/14 06:31:51| Startup: Initialized Authentication Scheme 'digest' 2026/11/14 06:31:51| Startup: Initialized Authentication Scheme 'negotiate' 2026/11/14 06:31:51| Startup: Initialized Authentication Scheme 'ntlm' 2026/11/14 06:31:51| Startup: Initialized Authentication. 2026/11/14 06:31:51| Processing Configuration File: /etc/squid/squid.conf (depth 0) 2026/11/14 06:31:51| Processing: http_port 127.0.0.1:3128 2026/11/14 06:31:51| Processing: acl allowed_domains dstdomain .anthropic.com .claude.ai .claude.com .statsig.com .sentry.io 2026/11/14 06:31:51| Processing: acl SSL_ports port 443 2026/11/14 06:31:51| Processing: acl CONNECT method CONNECT 2026/11/14 06:31:51| Processing: http_access deny CONNECT !SSL_ports 2026/11/14 06:31:51| Processing: http_access allow CONNECT allowed_domains 2026/11/14 06:31:51| Processing: http_access deny all 2026/11/14 06:31:51| Processing: cache deny all 2026/11/14 06:31:51| Processing: sslproxy_cert_error allow all 2026/11/14 06:31:51| Initializing https:// proxy context 2026/11/14 06:31:51| Requiring client certificates.
$ sudo systemctl enable --now squid $ sudo systemctl status squid
squidの設定反映を行う場合、以下
$ sudo squid -k reconfigure
iptablesによるファイアウォール設定
現在のルールを確認
$ sudo iptables -S OUTPUT -P OUTPUT ACCEPT $ sudo ip6tables -S OUTPUT -P OUTPUT ACCEPT
$ sudo vi /usr/local/sbin/firewall.sh
で、以下の firewall.sh を作成
#!/bin/bash set -eu # Squidの実行ユーザーを確認 SQUID_USER="$(systemctl show squid -p User --value)" # systemdのUserが空の場合は、Oracle Linux標準のsquidを使用 if [ -z "$SQUID_USER" ]; then SQUID_USER="squid" fi # Squidユーザーが存在することを確認 id "$SQUID_USER" >/dev/null # IPv4: 外向き通信をデフォルト拒否 iptables -F OUTPUT iptables -P OUTPUT DROP # ループバック通信 iptables -A OUTPUT -o lo -j ACCEPT # 既存接続の応答を許可 iptables -A OUTPUT \ -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT # SquidだけDNS問い合わせを許可 iptables -A OUTPUT \ -m owner --uid-owner "$SQUID_USER" \ -p udp --dport 53 -j ACCEPT iptables -A OUTPUT \ -m owner --uid-owner "$SQUID_USER" \ -p tcp --dport 53 -j ACCEPT # Squid経由なら許可ドメインの任意TCPポートにアクセス可 iptables -A OUTPUT \ -m owner --uid-owner "$SQUID_USER" \ -p tcp -j ACCEPT # IPv6: 外向き通信を遮断 ip6tables -F OUTPUT ip6tables -P OUTPUT DROP ip6tables -A OUTPUT -o lo -j ACCEPT ip6tables -A OUTPUT \ -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT exit 0
$ sudo chmod 750 /usr/local/sbin/firewall.sh
設定を恒久化する前に、まず手動で適用します。
$ sudo /usr/local/sbin/firewall.sh $ sudo iptables -S OUTPUT -P OUTPUT DROP -A OUTPUT -o lo -j ACCEPT -A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -A OUTPUT -p udp -m owner --uid-owner 23 -m udp --dport 53 -j ACCEPT -A OUTPUT -p tcp -m owner --uid-owner 23 -m tcp --dport 53 -j ACCEPT -A OUTPUT -p tcp -m owner --uid-owner 23 -m tcp --dport 443 -j ACCEPT $ sudo ip6tables -S OUTPUT -P OUTPUT DROP -A OUTPUT -o lo -j ACCEPT -A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
/etc/wsl.conf 設定
Windowsとの連携を制限し、WSL起動時にファイアウォールを適用
$ sudo vi /etc/wsl.conf
[boot] systemd=true # WSL起動時にファイアウォールを適用 command="/usr/local/sbin/firewall.sh" # Cドライブの自動マウントは無効化するが、fstabによるマウントは許可 [automount] enabled=false mountFsTab=true [interop] # Windows実行ファイルとの連携を無効化 enabled=false # Windows側のPATHを引き継がない appendWindowsPath=false [user] # 通常起動時のユーザーを指定 default=ないしょ021
$ vi ~/.bashrc
により .bashrc の末尾に以下を追加
# Claude Code用プロキシ 大文字&小文字 export HTTP_PROXY=http://127.0.0.1:3128 export HTTPS_PROXY=http://127.0.0.1:3128 export http_proxy=http://127.0.0.1:3128 export https_proxy=http://127.0.0.1:3128 # 自動更新と不要な通信を抑制 # export DISABLE_AUTOUPDATER=1 # export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 # SSL検証を無効化 export NODE_TLS_REJECT_UNAUTHORIZED=0
wsl再起動
CMD> wsl --shutdown CMD> wsl
動作確認
windowsとの連携を禁止できていることを確認
cは何も表示されず、一方、 mountの claude_pc、claude_share表示ならOK
$ ls /mnt/c $ ls /mnt/claude_pc $ ls /mnt/claude_share
command not foundなら、OK
$ cmd.exe
接続拒否なら、OK
$ curl -v -m 10 --proxy http://127.0.0.1:3128 --ssl-no-revoke \
https://www.google.com/
$ curl -v -m 10 --noproxy '*' --ssl-no-revoke \
https://www.google.com/
Claude Code関連が接続できれば、OK
$ curl -v -m 15 --proxy http://127.0.0.1:3128 --ssl-no-revoke \
https://api.anthropic.com/
$ curl -v -m 15 --noproxy '*' --ssl-no-revoke \
https://api.anthropic.com/
Claude Codeを起動できれば、OK
$ claude Welcome to Claude Code v2.1.311 Unable to connect to Anthropic services Failed to connect to api.anthropic.com: ERR_PROXY_TUNNEL A proxy is configured via HTTPS_PROXY. Check that it allows connections to the host above. See https://code.claude.com/docs/en/network-config Please check your internet connection and network settings. Note: Claude Code might not be available in your country. Check supported countries at https://anthropic.com/supported-countries
テストに失敗し、squidのログを確認する場合は以下
$ sudo tail -f /var/log/squid/access.log 1794555969.171 0 127.0.0.1 TCP_DENIED/403 3435 CONNECT api.anthropic.com:443 - HIER_NONE/- text/html 1794555969.171 0 127.0.0.1 TCP_DENIED/403 3439 CONNECT platform.claude.com:443 - HIER_NONE/- text/html
ログの収集
$ sudo dnf install -y cronie $ sudo systemctl enable --now crond $ sudo crontab -e 5 * * * * /usr/bin/tar czf /home/claude/claude_pc/claude_log_$(/usr/bin/cat /etc/hostname)_$(/usr/bin/date +\%m\%d).tar.gz -C /home/claude .claude/projects .claude.json -C /var/log/squid access.log @reboot sleep 60 && /usr/bin/tar czf /home/claude/claude_pc/claude_log_$(/usr/bin/cat /etc/hostname)_$(/usr/bin/date +\%m\%d).tar.gz -C /home/claude .claude/projects .claude.json -C /var/log/squid access.log
作業ユーザからsudo権限削除
$ sudo gpasswd -d ないしょ021 wheel
※ 管理者として起動する場合は、Windows側から次のようにwslを起動
CMD> wsl -d OracleLinux_9_5 -u root