5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

macOSでcntlmを使う

Last updated at Posted at 2018-08-28

認証Proxy越えのために

忌々しいですね。
NTLM認証Proxy。
毎回忘れる(定期的にパスワードを変えろポリシーが以前あったせいです)ので、忘備録です。

インストール

Homebrewを使ってお手軽インストールします。
(今回はマシン切替のために、brew自体入っていませんでしたが…)

$ brew install cntlm
==> Downloading https://homebrew.bintray.com/bottles/cntlm-0.92.3.high_sierra.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring cntlm--0.92.3.high_sierra.bottle.1.tar.gz
==> Caveats
Edit /usr/local/etc/cntlm.conf to configure Cntlm

To have launchd start cntlm now and restart at startup:
  sudo brew services start cntlm
==> Summary
🍺  /usr/local/Cellar/cntlm/0.92.3: 9 files, 144.6KB

設定ファイル

上記のインストール時に書いてある通り、/usr/local/etc/cntlm.confを弄ります。

$ sudo vi /usr/local/etc/cntlm.conf

自動起動

これまた上記のインストール時に書いてある通り、brew servicesコマンドで自動起動させることができます。
(これは、正常処理されたときの状態)

$ sudo brew services start cntlm
==> Successfully started `cntlm` (label: homebrew.mxcl.cntlm)

ところがですね。
最初に書いたとおりbrewも未インストールだったもんで servicesってコマンドがわからん とか怒られまして。
上記が正常に動くようにするには、servicesをインストールする必要があります。

$ brew services
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Counting objects: 14, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 14 (delta 0), reused 7 (delta 0), pack-reused 0
Unpacking objects: 100% (14/14), done.
Tapped 1 command (43 files, 55.2KB).
brew services command:
    Integrates Homebrew formulae with macOS' launchctl manager.

    [sudo] brew services list
    List all running services for the current user (or root)

    [sudo] brew services run formula|--all
    Run the service formula without starting at login (or boot).

    [sudo] brew services start formula|--all
    Start the service formula immediately and register it to launch at login (or boot).

    [sudo] brew services stop formula|--all
    Stop the service formula immediately and unregister it from launching at login (or boot).

    [sudo] brew services restart formula|--all
    Stop (if necessary) and start the service immediately and register it to launch at login (or boot).

    [sudo] brew services cleanup
    Remove all unused services.

    If sudo is passed, operate on /Library/LaunchDaemons (started at boot).
    Otherwise, operate on ~/Library/LaunchAgents (started at login).

というわけで、パスワードを変更したなどでcntlmを再起動させる場合は、以下になります。

$ sudo brew services start cntlm
Stopping `cntlm`... (might take a while)
==> Successfully stopped `cntlm` (label: homebrew.mxcl.cntlm)
==> Successfully started `cntlm` (label: homebrew.mxcl.cntlm)

なお。

一応、総務省はパスワードの定期的な変更は必要ないということで。
そういう運用は無くなったので、そうそうパスワードを変えることも無くなったのは僥倖です。

追記

ローカルにインストールしたcntlmを使おうとすると、

$ export http_proxy=http://localhost:3128
$ export https_proxy=http://localhost:3128
$ curl http://www.yahoo.co.jp/
curl: (52) Empty reply from server

つれない返答だ…。

tcpdumpで見てみれば、IPv6で繋いでくださってる。

$ sudo tcpdump -i lo0 -n port 3128
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo0, link-type NULL (BSD loopback), capture size 262144 bytes
13:30:30.956497 IP6 ::1.51393 > ::1.3128: Flags [S], seq 1694240149, win 65535, options [mss 16324,nop,wscale 5,nop,nop,TS val 75433652 ecr 0,sackOK,eol], length 0
13:30:30.956514 IP6 ::1.3128 > ::1.51393: Flags [R.], seq 0, ack 1694240150, win 0, length 0

この場合、eth0をIPv4オンリーにして、そちらにプロキシ設定する、という手を使った。

$ sudo networksetup -setv6off Ethernet
$ export http_proxy=http://192.168.0.1:3128
$ export https_proxy=http://192.168.0.1:3128

追記2

追記を書いた後に、localhostではなくて127.0.0.1でいいんでね?と気が付いた。

$ export http_proxy=http://127.0.0.1:3128
$ export https_proxy=http://127.0.0.1:3128
$ curl http://www.yahoo.co.jp/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">

というわけで、うっかりうっかり。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?