Setting Up a Vagrant Centos box example: A Practical


Explore the practical steps to set up a Vagrant CentOS box example in this detailed guide. Whether you’re working with CentOS 6 or 7, this tutorial provides clear instructions and essential tips for using Vagrant to deploy CentOS virtual machines effectively.

In this tutorial, I deployed a centos VM from Vagrantfiles. For example, the Vagrant Centos box example for Centos 6 and Centos 7. To use Vagrant, Virtualbox, and Centos.

The first is to create a Project folder as below:

$ mkdir vagrant_centos
$ cd vagrant_centos
$ vagrant init

To create a vagrant SSH key

[huupv@huupv example01]$ ssh-keygen

The Private key and public key in /home/huupv/project/keys/.ssh

To configure the vagrant SSH key in Vagrantfiles

config.ssh.insert_key = false
config.vm.boot_timeout = 800
config.ssh.private_key_path = ["keys/.ssh/vagrant_rsa", "~/.vagrant.d/insecure_private_key"]
config.vm.provision "file", source: "keys/.ssh/", destination: "~/.ssh/authorized_keys"

To configure a vagrant box in Vagrantfiles

For centos 6 or Centos 7 = “centos/6” = “centos/7”

Modifying Vagrant box memory and CPU settings

# Set VM memory size
vb.customize ["modifyvm", :id, "--memory", "512"]
# Set VM cpu size
config.vm.customize ["modifyvm", :id, "--cpus", 2]

Configure Forwarded port network "forwarded_port", guest: 80, host: 8888 :public_network, :bridge => "eth1", :auto_config => false

To set VM hostname for Guest VM

#Set VM hostname
config.vm.hostname = "Server01"

To install the packages necessary for the Vagrant Centos box

config.vm.provision :shell, path: "VAGRANT_ENV/"

Vagrant Centos box example in a Vagrantfile.

 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| = "centos/6"
 config.vm.hostname = "Server01"
 config.ssh.insert_key = false
 config.vm.provision :shell, path: "VAGRANT_ENV/"
 # Create a private network, which allows host-only access to the machine
 # using a specific IP.
 # :private_network, ip: "" "forwarded_port", guest: 80, host: 8888 :public_network, :bridge => "eth1", :auto_config => false
 # Share an additional folder to the guest VM
 # config.vm.synced_folder ".", "/vagrant", disabled: true
 # config.vm.synced_folder ".", "/home/vagrant/provision", type: "rsync"
 config.vm.provider :virtualbox do |vb|
 # Set VM memory size
 vb.customize ["modifyvm", :id, "--memory", "512"]
 # these 2 commands massively speed up DNS resolution, which means outbound
 # connections don't take forever (eg the WP admin dashboard and update page)
 vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
 vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]

To run vagrant up a Virtual Machine, to start guest VM

[huupv@huupv example01]$ vagrant up
Setting Up a Vagrant Centos box example


This guide demystifies the process of deploying CentOS using Vagrant, making it accessible for developers and IT professionals alike. With these insights, you’re now equipped to streamline your development and testing environments efficiently.

Thought the article, you can use the Vagrant Centos box example as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

1 thought on “Setting Up a Vagrant Centos box example: A Practical

  1. Thank you very much for the Vagrant centos box example!
    I am not a native English speaker myself, but I can see some spelling errors.
    PM me if you want me to help you in return by fixing them 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.