LoginSignup
11
11

More than 5 years have passed since last update.

インターネットに接続できないサーバへのプロビジョニング

Posted at

対象サーバをプロビジョニングする時に、apt-getとかgithubとか使いたいので、
操作端末をproxyにして一時的にインターネットへのアクセス経路を作る手順。

以下の様なネットワーク環境を想定。

  • 操作端末はインターネットに接続できる
  • 対象サーバはインターネットに接続できない
  • 操作端末から対象サーバへはsshで接続できる

要するに、itamae/serverspec/capistranoみたいな、対象サーバにsshが通りさえすれば使えるよ的なツール群を使っていて、インターネットに直接アクセスする必要のないバックエンド系のサーバを構築するみたいなシチュエーションを想定している。

操作端末での作業

# proxyサーバをインストール
sudo apt-get install squid3
# proxyサーバのaclをザル化
sudo sed -i '/^http_access deny all$/d' /etc/squid3/squid.conf
sudo service squid3 restart
# トンネルを掘る
ssh -fN -R 8080:localhost:3128 対象サーバ

これで対象サーバで「localhost:8080」がproxyサーバとして機能する。

対象サーバでの作業

proxyサーバ経由で接続するようにaptとgitを設定する

cat << __EOF__ > 99proxy
Acquire::ftp::proxy "ftp://localhost:8080/";
Acquire::http::proxy "http://localhost:8080/";
Acquire::https::proxy "https://localhost:8080/";
__EOF__
sudo mv 99proxy /etc/apt/apt.conf.d/99proxy
git config --global http.proxy http://localhost:8080/
git config --global https.proxy https://localhost:8080/
11
11
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
11
11