18
19

More than 5 years have passed since last update.

iPhoneからsocksプロキシ使ってプライベートなサーバにアクセスしたい

Last updated at Posted at 2015-12-14

なんか色々やったんですが,これはひとえにiPhoneではsocksプロキシ設定できないと思ってたからでした.

なんていうか,普通にできるんですね.というわけでメモ.

対象サーバにSSH

ssh -D 1080 -g ec2-user@target-server

-gがポイント.これにより,他のマシン(今回だとiPhone)からSSHを実行しているマシンのポートフォワードが利用できるようになります.

設定ファイルを作成し,HTTPアクセスができる場所に配置

socks.pac
function FindProxyForURL(url, host) {
    return "SOCKS 192.168.xx.xx:1080";
}

dropboxにでも置いておけば良いでしょう.

iPhoneのプロキシの設定

image

HTTP PROXYの設定をAUTOにし,さきほどdropboxにあげたpacファイルを指定します.

以上

これでtarget-server内で稼動しているサーバにアクセスできたり,あるいはtarget-serverを経由して別のサーバにアクセスしたりできるようになります.

一応確認

uraura@rosemary$ echo "via socks proxy">index.html

uraura@rosemary$ python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ...

プロキシ設定を変えたiPhoneから localhost:8000 へアクセス

127.0.0.1 - - [14/Dec/2015 07:38:36] "GET / HTTP/1.1" 200 -

アクセスできた!!

注) iPhoneのChromeからだと通りましたが,Safariからだとchannel 9: open failed: administratively prohibited: open failedと言われて開けませんでした...なぜだろう :ghost:


2015-12-14

-vvvv付きでSSHしてログを見てたところ,

Safariからアクセスした場合
debug2: channel 15: dynamic request: socks5 host www.localhost.com port 8000 command 1
channel 15: open failed: administratively prohibited: open failed
debug2: channel 15: zombie
debug2: channel 15: garbage collecting
debug1: channel 15: free: direct-tcpip: listening port 1080 for www.localhost.com port 8000, connect from 192.168.xx.26 port 59393 to 192.168.xx.33 port 1080, nchannels 16
...
Chromeからアクセスした場合
debug2: channel 6: dynamic request: socks5 host localhost port 8000 command 1
debug2: channel 6: open confirm rwindow 2097152 rmax 32768
127.0.0.1 - - [14/Dec/2015 08:59:22] "GET / HTTP/1.1" 200 -
debug2: channel 6: rcvd eof
debug2: channel 6: output open -> drain
debug2: channel 6: obuf empty
debug2: channel 6: close_write
debug2: channel 6: output drain -> closed
debug2: channel 6: read<=0 rfd 14 len 0
debug2: channel 6: read failed
debug2: channel 6: close_read
debug2: channel 6: input open -> drain
debug2: channel 6: ibuf empty
debug2: channel 6: send eof
debug2: channel 6: input drain -> closed
debug2: channel 6: send close
debug3: channel 6: will not send data after close
debug2: channel 6: rcvd close
debug3: channel 6: will not send data after close
debug2: channel 6: is dead
debug2: channel 6: garbage collecting
debug1: channel 6: free: direct-tcpip: listening port 1080 for localhost port 8000, connect from 192.168.xx.26 port 59402 to 192.168.xx.33 port 1080, nchannels 7

なぜかSafariの場合はwww.localhost.comへアクセスしにいってる...?


http://localhost.localdomain:8000 とベタベタに指定すればSafariでも行けました.

18
19
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
18
19