Vagrant: Creating two CentOS VMs and ping each other. 
[acool@localhost ~]$ date
Fri 21 Feb 2020 02:53:59 PM PST
[acool@localhost ~]$
[acool@localhost ~]$ cat /etc/redhat-release
Fedora release 31 (Thirty One)
[acool@localhost ~]$
[acool@localhost ~]$ sudo dnf install vagrant-libvirt
...
[acool@localhost ~]$ vagrant --version
Vagrant 2.2.6
[acool@localhost ~]$
[acool@localhost ~]$ mkdir vagrant-box-1
[acool@localhost ~]$ cd vagrant-box-1/
[acool@localhost vagrant-box-1]$
[acool@localhost vagrant-box-1]$ vagrant init centos/7
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.
[acool@localhost vagrant-box-1]
[acool@localhost vagrant-box-1]$ vagrant up
...
[acool@localhost vagrant-box-1]$
[acool@localhost vagrant-box-1]$ vagrant status
Current machine states:

default running (libvirt)

The Libvirt domain is running. To stop this machine, you can run
`vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
[acool@localhost vagrant-box-1]$
[acool@localhost vagrant-box-1]$ # you can now visually access this VM via "Boxes" which is like virt-manager
[acool@localhost vagrant-box-1]$
[acool@localhost vagrant-box-1]$
[acool@localhost vagrant-box-1]$ # or you can ssh into this box via vagrant
[acool@localhost vagrant-box-1]$ vagrant ssh
Last login: Fri Feb 21 23:05:54 2020 from 192.168.122.1
[vagrant@localhost ~]$
[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[vagrant@localhost ~]$
[vagrant@localhost ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:7f:e1:0c brd ff:ff:ff:ff:ff:ff
inet 192.168.122.194/24 brd 192.168.122.255 scope global noprefixroute dynamic eth0
valid_lft 3068sec preferred_lft 3068sec
inet6 fe80::5054:ff:fe7f:e10c/64 scope link
valid_lft forever preferred_lft forever
[vagrant@localhost ~]$
[vagrant@localhost ~]$
[vagrant@localhost ~]$ exit
logout
Connection to 192.168.122.194 closed.
[acool@localhost vagrant-box-1]$
[acool@localhost vagrant-box-1]$
[acool@localhost vagrant-box-1]$ # lets create another box
[acool@localhost vagrant-box-1]$ cd ../ && mkdir vagrant-box-2
[acool@localhost ~]$
[acool@localhost ~]$ cd vagrant-box-2
[acool@localhost vagrant-box-2]$
[acool@localhost vagrant-box-2]$ vagrant init centos/7
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.
[acool@localhost vagrant-box-2]$
[acool@localhost vagrant-box-2]$ vagrant up
...
[acool@localhost vagrant-box-2]$
[acool@localhost vagrant-box-2]$ vagrant ssh
Last login: Fri Feb 21 23:17:20 2020 from 192.168.122.1
[vagrant@localhost ~]$
[vagrant@localhost ~]$ ip a show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:69:74:25 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.27/24 brd 192.168.122.255 scope global noprefixroute dynamic eth0
valid_lft 2908sec preferred_lft 2908sec
inet6 fe80::5054:ff:fe69:7425/64 scope link
valid_lft forever preferred_lft forever
[vagrant@localhost ~]$
[vagrant@localhost ~]$ # let's ping box-1 from box-2
[vagrant@localhost ~]$ ping -c 2 192.168.122.194
PING 192.168.122.194 (192.168.122.194) 56(84) bytes of data.
64 bytes from 192.168.122.194: icmp_seq=1 ttl=64 time=0.589 ms
64 bytes from 192.168.122.194: icmp_seq=2 ttl=64 time=0.548 ms

--- 192.168.122.194 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.548/0.568/0.589/0.031 ms
[vagrant@localhost ~]$
[vagrant@localhost ~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[vagrant@localhost ~]$ exit
logout
Connection to 192.168.122.27 closed.
[acool@localhost vagrant-box-2]$
[acool@localhost vagrant-box-2]$
[acool@localhost vagrant-box-2]$
[acool@localhost vagrant-box-2]$# le's cleanup our tests
[acool@localhost vagrant-box-2]$ vagrant destroy
...
[acool@localhost vagrant-box-1]$ vagrant destroy


Comments
Comments are not available for this entry.
2024 By Angel Cool