visit
vagrant
achebe@okechukwus-MacBook-Pro ~ % vagrant Usage: vagrant [options] <command> [<args>]
-h, --help Print this help.
Common commands:
autocomplete manages autocomplete installation on host
box manages boxes: installation, removal, etc.
cloud manages everything related to Vagrant Cloud
achebe@okechukwus-MacBook-Pro ~ % cd Desktop
achebe@okechukwus-MacBook-Pro Desktop % mkdir -p TestVagrant/Box/Ubuntu_20_04
achebe@okechukwus-MacBook-Pro Desktop % cd TestVagrant/Box/Ubuntu_20_04
After creating the Ubuntu_20_04 folder inside the ‘Desktop/Testvagrant/Box’ folder, the next step is to install the vagrant ubuntu using the vagrant init
command. like so:
vagrant init ubuntu/focal64
A Vagrantfile has been placed in this directory. You are now
ready to vagrant up your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
vagrantup.com for more information on using Vagrant.
vagrant up
vagrant ssh
Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-122-generic x86_64)
Documentation: //help.ubuntu.com
Management: //landscape.canonical.com
Support: //ubuntu.com/advantage
System information as of Wed Aug 10 23:19:29 UTC 2022
System load: 0.01 Processes: 118
Usage of /: 4.1% of 38.70GB Users logged in: 0
Memory usage: 23% IPv4 address for enp0s3: 10.0.2.15
Swap usage: 0%
0 updates can be applied immediately.
hostnamectl'
vagrant@ubuntu-focal:~$ hostnamectl
Static hostname: ubuntu-focal
Icon name: computer-vm
Chassis: vm
Machine ID: 87a9bd2baeb54bcda24765b89147565a
Boot ID: 3b9ba20e3d494ac89568bb487c447a7f
Virtualization: oracle
Operating System: Ubuntu 20.04.4 LTS
Kernel: Linux 5.4.0-122-generic
Architecture: x86-64
To get the IP address of your virtual machine, use iconfig
.
vagrant@ubuntu-focal:~$ ifconfig
Command 'ifconfig' not found, but can be installed with:
apt install net-tools
Please ask your administrator.
You can easily resolve it with the sudo
command. like so:
sudo apt install net-tools
Then, run the iconfig'
command again and you should get this:
vagrant@ubuntu-focal:~$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::52:20ff:fe6d:cccd prefixlen 64 scopeid 0x20<link>
ether 02:52:20:6d:cc:cd txqueuelen 1000 (Ethernet)
RX packets 80714 bytes 112088617 (112.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11575 bytes 942445 (942.4 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 49 bytes 4998 (4.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 49 bytes 4998 (4.9 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
To configure our vagrant virtual machine (VM) so that it uses dchp as private_network allowing us to give it our own ip, we will need to exit the VM with the exit
command and halt our VM with vagrant halt
.
exit
vagrant halt
Once you’ve exited the vagrant machine environment, the Ubuntu OS into our location machine folder where the vagrant is installed, a vagrantfile
is located in this folder. It is in this vagrantfile
that you add your configuration.
config.vm.network "private_network", type: "dhcp"
Select the installed virtual machine. Take note, vagrant automatically creates the VM in the VirtualBox during installation.
Select settings, choose network and then select Adapter 2 to add another network adapter. For the “Attached to” dropdown select “Host-only Adapter”. Then, for the “Name” dropdown select “vboxnet0”, then click OK.
To see what we just did, enter your VM with the vagrant ssh
, then run the ifconfig
command. You should notice some new changes. Like this:
vagrant@ubuntu-focal:~$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::52:20ff:fe6d:cccd prefixlen 64 scopeid 0x20<link>
ether 02:52:20:6d:cc:cd txqueuelen 1000 (Ethernet)
RX packets 907 bytes 118268 (118.2 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 696 bytes 126192 (126.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.6 netmask 255.255.255.0 broadcast 192.168.56.255
inet6 fe80::a00:27ff:fec4:dd3d prefixlen 64 scopeid 0x20<link>
ether 08:00:27:c4:dd:3d txqueuelen 1000 (Ethernet)
RX packets 24 bytes 11082 (11.0 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16 bytes 2342 (2.3 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 8 bytes 712 (712.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 712 (712.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp0s8
shows your new ip address 192.168.56.6. Cool right?
The last to do is to transfer the output of ifconfig
into a file, then transfer said file to our local machine - the host.
Run this command to write the output of ifconfig
into the file that you’ll create.
ifconfig > ifconfig.txt
vagrant plugin install vagrant-scp
vagrant scp default:/home/vagrant/ifconfig.txt ~/Desktop
When you check your host desktop, you’ll see where the ifconfig.txt
file is located.
vagrant status
Also published .