2
0

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 3 years have passed since last update.

【2022年版】インターネット接続できない環境から、SSH 接続を経由した、インターネットアクセスの方法

Posted at

はじめに

  • 以下の要望を満たす  
    • インターネット接続できない環境から、インターネットアクセスしたい
    • インターネットから SSH で接続できる環境で
      • apt update, apt upgrade したい
      • curl したい
      • git したい

PC Local から PC Target に ssh アクセスできる場合( Local -> Target )

環境

  • PC Local
    • インターネットにアクセスできる
    • PC Target に ssh アクセスできる
  • PC Target
    • インターネットにアクセスできない
    • PC Local から ssh アクセスできる

proxychains をインストール

  • Local で ssh を接続 ( Local -> Target )

    $ ssh -R 7777 target
    
  • apt で proxy chains をインストール、この時はproxyのオプションを使う

    $ sudo apt -o Acquire::http::proxy="socks5h://localhost:7777" -o Acquire::https::proxy="socks5h://localhost:7777" update
    $ sudo apt -o Acquire::http::proxy="socks5h://localhost:7777" -o Acquire::https::proxy="socks5h://localhost:7777" install proxychains
    
    • Acquire::http::proxyオプションではなく、以下の方法でもよい
      • http_proxy, https_proxy 環境変数を設定
      • /etc/apt/apt.conf を設定
  • /etc/proxychains.conf を修正、末尾の [ProxyList] へ以下を追加

    [ProxyList]
    # add proxy here ...
    # meanwile
    # defaults set to "tor"
    socks5 127.0.0.1 7777
    

proxychains を利用したコマンド実行

  • 以後は、apt を利用する際は、proxyのオプションではなく、proxychains を利用する
    $ sudo proxychains apt update
    $ sudo proxychains apt upgrade
     :
     :
    $ proxychains git clone ...
     :
     :
    $ proxychains curl httpbin.org/ip
    |DNS-request| httpbin.org 
    |S-chain|-<>-127.0.0.1:7777-<><>-4.2.2.2:53-<><>-OK
    |DNS-response| httpbin.org is 35.173.123.14
    |S-chain|-<>-127.0.0.1:7777-<><>-35.173.123.14:80-<><>-OK
    {
      "origin": "XXX.XXX.XXX.XXX"
    }
    

PC Target から PC Local に ssh アクセスできる場合( Target -> Local )

環境

  • PC Local
    • インターネットにアクセスできる
  • PC Target
    • インターネットにアクセスできない
    • PC Local に ssh アクセスできる

proxychains をインストール

  • Targetで ssh を接続 ( Target -> Local )

    $ ssh -f -N -D 7777 localhost
    
    • あとから ssh セッションは kill しましょう
  • apt で proxy chains をインストール、この時はproxyのオプションを使う

    $ sudo apt -o Acquire::http::proxy="socks5h://localhost:7777" -o Acquire::https::proxy="socks5h://localhost:7777" update
    $ sudo apt -o Acquire::http::proxy="socks5h://localhost:7777" -o Acquire::https::proxy="socks5h://localhost:7777" install proxychains
    
    • Acquire::http::proxyオプションではなく、以下の方法でもよい
      • http_proxy, https_proxy 環境変数を設定
      • /etc/apt/apt.conf を設定
  • /etc/proxychains.conf を修正、末尾の [ProxyList] へ以下を追加

    [ProxyList]
    # add proxy here ...
    # meanwile
    # defaults set to "tor"
    socks5 127.0.0.1 7777
    

proxychains を利用したコマンド実行

  • 以後は、apt を利用する際は、proxyのオプションではなく、proxychains を利用する
    $ sudo proxychains apt update
    $ sudo proxychains apt upgrade
     :
     :
    $ proxychains git clone ...
     :
     :
    $ proxychains curl httpbin.org/ip
    |DNS-request| httpbin.org 
    |S-chain|-<>-127.0.0.1:7777-<><>-4.2.2.2:53-<><>-OK
    |DNS-response| httpbin.org is 35.173.123.14
    |S-chain|-<>-127.0.0.1:7777-<><>-35.173.123.14:80-<><>-OK
    {
      "origin": "XXX.XXX.XXX.XXX"
    }
    

さいごに

  • かんたんでしたね

参考リソース

2
0
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?