Connect to Vagrant Virtual Machine over Wi-Fi Network

I recently had the need to quickly set up an Oracle 19c database lab environment on Linux to run some tests. My laptop was already running a VirtualBox VM with Oracle 12.2 release and I wanted to have a different VM environment for 19c. I didn’t want the VMs using up all my laptop’s resources so I decided to set up the lab in a backup laptop that I had just lying around.
A quick Google search showed me that using VirtualBox and Vagrant projects cloned from Git was the quickest way to set up my test environment. I wanted to use SQL developer from my main laptop to connect to my backup device. Since both my devices lie on the same Wi-Fi network, setting up the connectivity wouldn’t be an issue if I used a typical VirtualBox VM with a bridged adapter network interface. But I was using Vagrant to manage my installation. How would I set up the network when using Vagrant? Read the following steps to find out:
First, I installed the software I needed to get the VM to run.
1. Install Oracle VirtualBox. Get it here.
2. Install Vagrant. Get it here.
3. Install Git. Get it here.
I downloaded the binaries for the Oracle database release I wanted to install. In my case this was 19.3, which I got here.
The second step was to clone the Vagrant project repository from Github.
Using Command Prompt (On Windows) or Terminal (On Mac):
$ git clone https://github.com/oracle/vagrant-boxes Cloning into 'vagrant-boxes'... remote: Enumerating objects: 10, done. remote: Counting objects: 100% (10/10), done. remote: Compressing objects: 100% (8/8), done. remote: Total 2501 (delta 1), reused 2 (delta 1), pack-reused 2491 Receiving objects: 100% (2501/2501), 1.11 MiB | 1.86 MiB/s, done. Resolving deltas: 100% (1507/1507), done.
I navigated to the Oracle release I wanted to use, and copied the binary file I downloaded earlier to this location.
$ cp ~\Downloads\LINUX.X64_193000_db_home.zip ~\vagrant-boxes\OracleDatabase\19.3.0\ $ cd vagrant-boxes\OracleDatabase\19.3.0 $ ls Directory: ~\vagrant-boxes\OracleDatabase\19.3.0 Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 2021-02-04 6:53 PM ora-response d----- 2021-02-04 6:53 PM scripts d----- 2021-02-04 6:53 PM userscripts -a---- 2021-02-04 6:53 PM 1361 .env -a---- 2021-02-04 6:53 PM 18 .gitattributes -a---- 2021-02-04 6:53 PM 13 .gitignore -a---- 2021-02-04 7:15 PM 3059705302 LINUX.X64_193000_db_home.zip -a---- 2021-02-04 6:53 PM 6512 README.md -a---- 2021-02-04 6:53 PM 5587 Vagrantfile
My next step was to build the Vagrant box. Just one command will download the Linux OS, update the required rpms, start the server and install the Oracle database!
$ Vagrant up ==> oracle-19c-vagrant: Importing base box 'oraclelinux/7'... ==> oracle-19c-vagrant: Matching MAC address for NAT networking... ==> oracle-19c-vagrant: Checking if box 'oraclelinux/7' version '7.9.184' is up to date... ==> oracle-19c-vagrant: Setting the name of the VM: oracle-19c-vagrant ==> oracle-19c-vagrant: Clearing any previously set network interfaces... ==> oracle-19c-vagrant: Preparing network interfaces based on configuration... oracle-19c-vagrant: Adapter 1: nat ==> oracle-19c-vagrant: Forwarding ports... oracle-19c-vagrant: 1521 (guest) => 1521 (host) (adapter 1) oracle-19c-vagrant: 5500 (guest) => 5500 (host) (adapter 1) oracle-19c-vagrant: 22 (guest) => 2222 (host) (adapter 1) ==> oracle-19c-vagrant: Running 'pre-boot' VM customizations... ==> oracle-19c-vagrant: Booting VM... ==> oracle-19c-vagrant: Waiting for machine to boot. This may take a few minutes... oracle-19c-vagrant: SSH address: 127.0.0.1:2222 oracle-19c-vagrant: SSH username: vagrant oracle-19c-vagrant: SSH auth method: private key oracle-19c-vagrant: Vagrant insecure key detected. Vagrant will automatically replace oracle-19c-vagrant: this with a newly generated keypair for better security. oracle-19c-vagrant: oracle-19c-vagrant: Inserting generated public key within guest... ==> oracle-19c-vagrant: Machine booted and ready! ==> oracle-19c-vagrant: Checking for guest additions in VM... ==> oracle-19c-vagrant: Setting hostname... ==> oracle-19c-vagrant: Mounting shared folders... oracle-19c-vagrant: /vagrant => ~/vagrant-boxes/OracleDatabase/19.3.0 ==> oracle-19c-vagrant: Running provisioner: shell... oracle-19c-vagrant: Running: ~/Local/Temp/vagrant-shell20210205-1668-capwz4.sh oracle-19c-vagrant: INSTALLER: Started up oracle-19c-vagrant: inflating: /opt/oracle/product/19c/dbhome_1/ldap/schema/oid/oidSchemaCreateAux.lst oracle-19c-vagrant: inflating: /opt/oracle/product/19c/dbhome_1/ldap/schema/oid/oidDefaultSubscriberConfig.sbs .. .. oracle-19c-vagrant: /opt/oracle/product/19c/dbhome_1/javavm/lib/security/cacerts -> ../../../javavm/jdk/jdk8/lib/security/cacerts oracle-19c-vagrant: /opt/oracle/product/19c/dbhome_1/javavm/lib/sunjce_provider.jar -> ../../javavm/jdk/jdk8/lib/sunjce_provider.jar oracle-19c-vagrant: /opt/oracle/product/19c/dbhome_1/javavm/lib/security/README.txt -> ../../../javavm/jdk/jdk8/lib/security/README.txt oracle-19c-vagrant: /opt/oracle/product/19c/dbhome_1/javavm/lib/security/java.security -> ../../../javavm/jdk/jdk8/lib/security/java.security oracle-19c-vagrant: /opt/oracle/product/19c/dbhome_1/jdk/jre/lib/amd64/server/libjsig.so -> ../libjsig.so oracle-19c-vagrant: Launching Oracle Database Setup Wizard... oracle-19c-vagrant: [WARNING] [INS-32055] The Central Inventory is located in the Oracle base. oracle-19c-vagrant: ACTION: Oracle recommends placing this Central Inventory in a location outside the Oracle base directory. oracle-19c-vagrant: The response file for this session can be found at: oracle-19c-vagrant: /opt/oracle/product/19c/dbhome_1/install/response/db_2021-02-05_08-54-43AM.rsp oracle-19c-vagrant: You can find the log of this install session at: oracle-19c-vagrant: /tmp/InstallActions2021-02-05_08-54-43AM/installActions2021-02-05_08-54-43AM.log oracle-19c-vagrant: oracle-19c-vagrant: As a root user, execute the following script(s): oracle-19c-vagrant: 1. /opt/oracle/oraInventory/orainstRoot.sh oracle-19c-vagrant: 2. /opt/oracle/product/19c/dbhome_1/root.sh oracle-19c-vagrant: oracle-19c-vagrant: Execute /opt/oracle/oraInventory/orainstRoot.sh on the following nodes: oracle-19c-vagrant: [oracle-19c-vagrant] oracle-19c-vagrant: Execute /opt/oracle/product/19c/dbhome_1/root.sh on the following nodes: oracle-19c-vagrant: [oracle-19c-vagrant] oracle-19c-vagrant: oracle-19c-vagrant: oracle-19c-vagrant: Successfully Setup Software. oracle-19c-vagrant: Moved the install session logs to: oracle-19c-vagrant: /opt/oracle/oraInventory/logs/InstallActions2021-02-05_08-54-43AM oracle-19c-vagrant: Changing permissions of /opt/oracle/oraInventory. oracle-19c-vagrant: Adding read,write permissions for group. oracle-19c-vagrant: Removing read,write,execute permissions for world. oracle-19c-vagrant: Changing groupname of /opt/oracle/oraInventory to dba. oracle-19c-vagrant: The execution of the script is complete. oracle-19c-vagrant: Check /opt/oracle/product/19c/dbhome_1/install/root_oracle-19c-vagrant_2021-02-05_08-56-02-466285736.log for the output of root script oracle-19c-vagrant: INSTALLER: Oracle software installed oracle-19c-vagrant: oracle-19c-vagrant: LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 05-FEB-2021 08:56:02 oracle-19c-vagrant: oracle-19c-vagrant: Copyright (c) 1991, 2019, Oracle. All rights reserved. oracle-19c-vagrant: Starting /opt/oracle/product/19c/dbhome_1/bin/tnslsnr: please wait... oracle-19c-vagrant: TNSLSNR for Linux: Version 19.0.0.0.0 - Production oracle-19c-vagrant: System parameter file is /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora oracle-19c-vagrant: Log messages written to /opt/oracle/diag/tnslsnr/oracle-19c-vagrant/listener/alert/log.xml oracle-19c-vagrant: Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1))) oracle-19c-vagrant: Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521))) oracle-19c-vagrant: oracle-19c-vagrant: Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1))) oracle-19c-vagrant: STATUS of the LISTENER oracle-19c-vagrant: ------------------------ oracle-19c-vagrant: Alias LISTENER oracle-19c-vagrant: Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production oracle-19c-vagrant: Start Date 05-FEB-2021 08:56:02 oracle-19c-vagrant: Uptime 0 days 0 hr. 0 min. 0 sec oracle-19c-vagrant: Trace Level off oracle-19c-vagrant: Security ON: Local OS Authentication oracle-19c-vagrant: SNMP OFF oracle-19c-vagrant: Listener Parameter File /opt/oracle/product/19c/dbhome_1/network/admin/listener.ora oracle-19c-vagrant: Listener Log File /opt/oracle/diag/tnslsnr/oracle-19c-vagrant/listener/alert/log.xml oracle-19c-vagrant: Listening Endpoints Summary... oracle-19c-vagrant: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1))) oracle-19c-vagrant: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521))) oracle-19c-vagrant: The listener supports no services oracle-19c-vagrant: The command completed successfully oracle-19c-vagrant: INSTALLER: Listener created oracle-19c-vagrant: Prepare for db operation oracle-19c-vagrant: 8% complete oracle-19c-vagrant: Copying database files oracle-19c-vagrant: 31% complete oracle-19c-vagrant: Creating and starting Oracle instance oracle-19c-vagrant: 32% complete oracle-19c-vagrant: 36% complete oracle-19c-vagrant: 40% complete oracle-19c-vagrant: 43% complete oracle-19c-vagrant: 46% complete oracle-19c-vagrant: Completing Database Creation oracle-19c-vagrant: 51% complete oracle-19c-vagrant: 54% complete oracle-19c-vagrant: Creating Pluggable Databases oracle-19c-vagrant: 58% complete oracle-19c-vagrant: 77% complete oracle-19c-vagrant: Executing Post Configuration Actions oracle-19c-vagrant: 100% complete oracle-19c-vagrant: Database creation complete. For details check the logfiles at: oracle-19c-vagrant: /opt/oracle/cfgtoollogs/dbca/ORCLCDB. oracle-19c-vagrant: Database Information: oracle-19c-vagrant: Global Database Name:ORCLCDB oracle-19c-vagrant: System Identifier(SID):ORCLCDB oracle-19c-vagrant: Look at the log file "/opt/oracle/cfgtoollogs/dbca/ORCLCDB/ORCLCDB.log" for further details. oracle-19c-vagrant: oracle-19c-vagrant: SQL*Plus: Release 19.0.0.0.0 - Production on Fri Feb 5 09:10:45 2021 oracle-19c-vagrant: Version 19.3.0.0.0 oracle-19c-vagrant: oracle-19c-vagrant: Copyright (c) 1982, 2019, Oracle. All rights reserved. oracle-19c-vagrant: oracle-19c-vagrant: Connected to: oracle-19c-vagrant: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production oracle-19c-vagrant: Version 19.3.0.0.0 oracle-19c-vagrant: SQL> oracle-19c-vagrant: Pluggable database altered. oracle-19c-vagrant: SQL> oracle-19c-vagrant: oracle-19c-vagrant: PL/SQL procedure successfully completed. oracle-19c-vagrant: SQL> oracle-19c-vagrant: oracle-19c-vagrant: System altered. oracle-19c-vagrant: SQL> oracle-19c-vagrant: oracle-19c-vagrant: System altered. oracle-19c-vagrant: SQL> oracle-19c-vagrant: Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production oracle-19c-vagrant: Version 19.3.0.0.0 oracle-19c-vagrant: INSTALLER: Database created oracle-19c-vagrant: INSTALLER: Oratab configured oracle-19c-vagrant: Created symlink from /etc/systemd/system/multi-user.target.wants/oracle-rdbms.service to /etc/systemd/system/oracle-rdbms.service. oracle-19c-vagrant: INSTALLER: Created and enabled oracle-rdbms systemd's service oracle-19c-vagrant: INSTALLER: setPassword.sh file setup oracle-19c-vagrant: INSTALLER: Running user-defined post-setup scripts oracle-19c-vagrant: INSTALLER: Done running user-defined post-setup scripts oracle-19c-vagrant: ORACLE PASSWORD FOR SYS, SYSTEM AND PDBADMIN: xxxxx oracle-19c-vagrant: INSTALLER: Installation complete, database ready to use! ~\vagrant-boxes\OracleDatabase\19.3.0> vagrant status Current machine states: oracle-19c-vagrant running (virtualbox) The VM is running. To stop this VM, you can run `vagrant halt` to shut it down forcefully, or you can run `vagrant suspend` to simply suspend the virtual machine. In either case, to restart it again, simply run `vagrant up`.
At this point I could login to the VM server using the command vagrant ssh. SSH keys were already set up to enable passwordless SSH. The vagrant user had sudo access to switch user once in the server.
~\vagrant-boxes\OracleDatabase\19.3.0> vagrant ssh Welcome to Oracle Linux Server release 7.9 (GNU/Linux 5.4.17-2036.100.6.1.el7uek.x86_64) The Oracle Linux End-User License Agreement can be viewed here: * /usr/share/eula/eula.en_US For additional packages, updates, documentation and community help, see: * https://yum.oracle.com/ For additional packages, updates, documentation and community help, see: * https://yum.oracle.com/ [vagrant@oracle-19c-vagrant ~]$ sudo su - oracle Last login: Fri Feb 5 11:58:13 -05 2021 [oracle@oracle-19c-vagrant ~]$
So far so good! I could now login to my database and start working. But this isn’t what I wanted. I wanted to be able to SSH to the VM instance from my primary machine. Here’s how I managed that:
I needed to set up an additional network interface on the VM server. At this point my VM had just one NAT network adapter set up. This is what it looked like:
1. Stop the VM server
~\vagrant-boxes\OracleDatabase\19.3.0> vagrant halt ==> oracle-19c-vagrant: Attempting graceful shutdown of VM... ~\vagrant-boxes\OracleDatabase\19.3.0> vagrant status Current machine states: oracle-19c-vagrant poweroff (virtualbox)
2. Set up a second network adapter
I added a bridged network adapter for this VM on the VirtualBox utility. It’s important to note the name of the adapter. In my case this was Intel(R) Wi-Fi 6 AX201 160MHz.
3. Modify the configuration
I now had a network on the server which needed to be configured. Vagrant resets any configuration changes made inside the VM, so I used Vagrantfile to add the network to the VM. I added a line under the # Oracle port forwarding section and mentioned the interface and IP address I wanted to assign to the machine. I needed to make sure this IP address lay within my internal Wi-Fi network range. My Wi-Fi network range was 192.168.2.0/24.
4. Start the VM machine and verify
~\vagrant-boxes\OracleDatabase\19.3.0> vagrant up Bringing machine 'oracle-19c-vagrant' up with 'virtualbox' provider... ==> oracle-19c-vagrant: Checking if box 'oraclelinux/7' version '7.9.184' is up to date... ==> oracle-19c-vagrant: A newer version of the box 'oraclelinux/7' for provider 'virtualbox' is ==> oracle-19c-vagrant: available! You currently have version '7.9.184'. The latest is version ==> oracle-19c-vagrant: '7.9.194'. Run `vagrant box update` to update. ==> oracle-19c-vagrant: Clearing any previously set forwarded ports... ==> oracle-19c-vagrant: Clearing any previously set network interfaces... ==> oracle-19c-vagrant: Preparing network interfaces based on configuration... oracle-19c-vagrant: Adapter 1: nat oracle-19c-vagrant: Adapter 2: bridged ==> oracle-19c-vagrant: Forwarding ports... oracle-19c-vagrant: 1521 (guest) => 1521 (host) (adapter 1) oracle-19c-vagrant: 5500 (guest) => 5500 (host) (adapter 1) oracle-19c-vagrant: 22 (guest) => 2222 (host) (adapter 1) ==> oracle-19c-vagrant: Running 'pre-boot' VM customizations... ==> oracle-19c-vagrant: Booting VM... ==> oracle-19c-vagrant: Waiting for machine to boot. This may take a few minutes... oracle-19c-vagrant: SSH address: 127.0.0.1:2222 oracle-19c-vagrant: SSH username: vagrant oracle-19c-vagrant: SSH auth method: private key oracle-19c-vagrant: Warning: Connection reset. Retrying... oracle-19c-vagrant: Warning: Remote connection disconnect. Retrying... oracle-19c-vagrant: Warning: Connection aborted. Retrying... ==> oracle-19c-vagrant: Machine booted and ready! ==> oracle-19c-vagrant: Checking for guest additions in VM... ==> oracle-19c-vagrant: Setting hostname... ==> oracle-19c-vagrant: Configuring and enabling network interfaces... ==> oracle-19c-vagrant: Mounting shared folders... oracle-19c-vagrant: /vagrant => ~/vagrant-boxes/OracleDatabase/19.3.0 ==> oracle-19c-vagrant: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> oracle-19c-vagrant: flag to force provisioning. Provisioners marked to run always will still run.
I could now reach the VM from anywhere on the Wi-Fi network but I still couldn’t login, as Vagrant (by default) wouldn’t allow password-based SSH into the VM. The workaround was to use SSH keys for passwordless login, and I already had the keys set up.
I copied this private key file and used the file to SSH to the VM server as a Vagrant user.
~\vagrant-boxes\OracleDatabase\19.3.0> cd .\.vagrant\machines\oracle-19c-vagrant\virtualbox\ ~\vagrant-boxes\OracleDatabase\19.3.0\.vagrant\machines\oracle-19c-vagrant\virtualbox> ls Directory: C:\Users\Sridhar Ravula\vagrant-boxes\OracleDatabase\19.3.0\.vagrant\machines\oracle-19c-vagrant\virtualbox Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2021-02-05 11:36 AM 40 action_provision -a---- 2021-02-13 8:51 AM 10 action_set_name -a---- 2021-02-13 8:51 AM 134 box_meta -a---- 2021-02-05 11:35 AM 1 creator_uid -a---- 2021-02-05 11:35 AM 36 id -a---- 2021-02-05 11:35 AM 32 index_uuid -a---- 2021-02-05 11:35 AM 1706 private_key -------------->>>>>>> -a---- 2021-02-13 8:51 AM 163 synced_folders -a---- 2021-02-05 11:35 AM 59 vagrant_cwd
Note: This key file cannot be used with PuTTY to SSH to the VM as PuTTY doesn’t understand its format. To use this key in PuTTY, I’d need to convert it to .ppk format as detailed here.
I’m sure there are other methods for setting up this kind of a lab server but this way seemed easiest to me and suited my needs. I hope it helps you set up something similar.
If you have any questions or thoughts, please leave them in the comments.