Vagrant Behind Corporate Proxy or Firewall
In corporate environments, internet access is often routed through an HTTP proxy or restricted by firewall rules. This can break Vagrant box downloads, provisioner package installs (dnf/yum), and plugin installations. This page covers all the configuration needed to make Vagrant work in such environments.
Configure Proxy for Vagrant Itself
BASH — Host Proxy Setup
# Install vagrant-proxyconf plugin
vagrant plugin install vagrant-proxyconf
# Set proxy environment variables on your host
export http_proxy="http://proxy.company.com:8080"
export https_proxy="http://proxy.company.com:8080"
export no_proxy="localhost,127.0.0.1,192.168.56.0/24"
# For Windows PowerShell
$env:http_proxy = "http://proxy.company.com:8080"
$env:https_proxy = "http://proxy.company.com:8080"
$env:no_proxy = "localhost,127.0.0.1"
Configure Proxy Inside OEL 8 VM
Ruby — vagrant-proxyconf in Vagrantfile
# vagrant-proxyconf plugin automatically configures proxy inside VM
Vagrant.configure("2") do |config|
config.vm.box = "generic/oracle8"
# Read proxy from host environment
if Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = ENV["http_proxy"] || "http://proxy.company.com:8080"
config.proxy.https = ENV["https_proxy"] || "http://proxy.company.com:8080"
config.proxy.no_proxy = ENV["no_proxy"] || "localhost,127.0.0.1,192.168.56.0/24"
# Apply to these tools inside VM
config.proxy.enabled = { apt: true, yum: true, git: true, svn: true, docker: true }
end
config.vm.provision "shell", inline: "dnf install -y wget curl"
end
Configure dnf/yum Proxy Inside VM
BASH — dnf Proxy Config
# Inside OEL 8 VM — configure dnf proxy manually
# (if vagrant-proxyconf is not available)
sudo cat >> /etc/dnf/dnf.conf << EOF
proxy=http://proxy.company.com:8080
proxy_username=
proxy_password=
EOF
# Test
sudo dnf install -y wget
# Also set system-wide proxy
sudo cat >> /etc/environment << EOF
http_proxy=http://proxy.company.com:8080
https_proxy=http://proxy.company.com:8080
no_proxy=localhost,127.0.0.1,192.168.56.0/24
EOF
# Export for current session inside VM
export http_proxy="http://proxy.company.com:8080"
export https_proxy="http://proxy.company.com:8080"
export no_proxy="localhost,127.0.0.1"
# Test download
curl -v https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
Download Boxes Behind Proxy
BASH — Box Download Behind Proxy
# Set proxy before vagrant box add
export http_proxy="http://proxy.company.com:8080"
export https_proxy="http://proxy.company.com:8080"
# Download box
vagrant box add generic/oracle8
# Or use a locally cached box file
# Download the box file manually using a browser/curl from outside network
# Then add it locally
vagrant box add oel8-local /path/to/downloaded/oracle8.box
# For Parallels — use metadata JSON
vagrant box add /path/to/box-metadata.json
Offline / Air-Gapped Environments
If your lab machines have no internet access at all, use this approach:
BASH — Air-Gapped Setup
# Step 1 — On a machine WITH internet access:
# Download box
vagrant box add generic/oracle8 --provider virtualbox
# Box is saved at: ~/.vagrant.d/boxes/generic-VAGRANTSLASH-oracle8/
# Download RPM packages needed for provisioning
mkdir -p ~/offline-rpms
dnf download --resolve --destdir ~/offline-rpms mysql-community-server mysql-community-client
# Step 2 — Transfer to air-gapped machine:
# Copy ~/.vagrant.d/boxes/ directory
# Copy ~/offline-rpms/ directory
rsync -avz ~/.vagrant.d/boxes/ airgapped-machine:~/.vagrant.d/boxes/
rsync -avz ~/offline-rpms/ airgapped-machine:~/offline-rpms/
# Step 3 — On air-gapped machine:
# Use local RPMs in provisioner
vagrant up
# In provisioner script — install from local RPMs
dnf localinstall -y /vagrant/offline-rpms/*.rpm
Proxy Authentication
BASH — Authenticated Proxy
# Proxy with username and password
export http_proxy="http://username:password@proxy.company.com:8080"
export https_proxy="http://username:password@proxy.company.com:8080"
# In Vagrantfile with vagrant-proxyconf
config.proxy.http = "http://username:password@proxy.company.com:8080"
config.proxy.https = "http://username:password@proxy.company.com:8080"
# dnf.conf with authentication
sudo cat >> /etc/dnf/dnf.conf << EOF
proxy=http://proxy.company.com:8080
proxy_username=myuser
proxy_password=mypassword
EOF
Firewall — Required Ports
| Destination | Port | Purpose |
|---|---|---|
| app.vagrantup.com | 443 | Box downloads, Vagrant Cloud |
| vagrantcloud-files.s3.amazonaws.com | 443 | Box file storage |
| repo.mysql.com | 443/80 | MySQL repository |
| yum.oracle.com | 443/80 | OEL packages |
| repo.percona.com | 443/80 | Percona/PXC packages |
| download.postgresql.org | 443/80 | PostgreSQL packages |
| github.com | 443 | Vagrant plugin downloads |
💡 Note: If only specific boxes need to work offline, download them once on any machine with internet, then copy the ~/.vagrant.d/boxes/ directory to the target machine. Vagrant will use the locally cached box without needing internet.