LoginSignup
6
11

More than 5 years have passed since last update.

Proxy環境下でVagrantを使用する場合のTips

Last updated at Posted at 2018-08-14

プロキシ環境下でのvagrant使用時の注意点(windows)

プロキシ情報を設定(cmd上で)

set "http_proxy=http://<username>:<password>@<proxy>:<port>"
set "https_proxy=http://<username>:<password>@<proxy>:<port>"
vagrant plugin install vagrant-proxyconf

vagrant-proxyconfはVMのプロキシ設定に使用する。

上記を使用すると

vagrant box add <box名> <url>

などを実行可能となる。

外部からの接続(ポートフォワーディング)

ポートフォワーディングを設定する。

Vagrantfile
config.vm.box = "ubuntu14.04"  #box名
config.vm.network :forwarded_port, guest:22, host:2000, id:"ssh"

VMのプロキシ設定

Vagrantfile
if Vagrant.has_plugin?("vagrant-proxyconf")
  config.proxy.http     = "http://<username>:<password>@<proxy>:<port>"
  config.proxy.https    = "http://<username>:<password>@<proxy>:<port>"
  config.proxy.no_proxy = "localhost,127.0.0.1"
end

上記を設定することで(この場合)

ホストOSのIP:2000

でゲストOSにssh接続することが可能となる。

ssh 172.104.70.204:2000

外部からの接続(ブリッジ)

ブリッジ設定

Vagrantfile
config.vm.box = "ubuntu14.04"  #box名
config.vm.network :public_network, :ip=>"xxx.xxx.xxx.xxx", :bridge=>"eth1" #設定したいIPを記載する.

VMのプロキシ設定

Vagrantfile
if Vagrant.has_plugin?("vagrant-proxyconf")
  config.proxy.http     = "http://<username>:<password>@<proxy>:<port>"
  config.proxy.https    = "http://<username>:<password>@<proxy>:<port>"
  config.proxy.no_proxy = "localhost,127.0.0.1"
end

その後デフォルトルートを設定するため、OSの.bashrcファイルに以下を記入する

.bashrc
sudo route del default gw x.x.x.x eth0
sudo route add default gw xxx.xxx.xxx.xxx eth1 #デフォルトゲートウェイを書く.

上記を設定することでIPを指定してアクセス可能となる

ssh xxx.xxx.xxx.xxx:22

その他

Vagrant自体の環境構築は以下が参考になります。
Vagrant+VirtualBoxでUbuntu環境構築

6
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
6
11