Connecting to Oracle from Your Host to a VirtualBox Guest

thatjeffsmith Personal Tech 16 Comments

Tell Others About This Story:

This isn’t a SQL Developer post per-se, however if you are using the Oracle Developer Day VirtualBox 12c image, you will find this useful.

A few of you have noticed that it’s difficult to connect to your Oracle Database from your computer if it’s running on this image. One Twitter friend asked just yesterday…

Need help with connecting @OracleSQLDev on host computer to @virtualbox guest OS (Oracle Developer Day). Any thoughts?

Now, I should note that you can indeed easily run your tools directly from inside the image, SQL Developer and APEX included. But if you want to run your browser and/or tools from OUTSIDE the image and talk to the database, then you might need to keep reading.

The simple answer is that port 1521 isn’t open in the Firewall

This is easy to fix.

You'll need the root password, same as oracle's on this image

You’ll need the root password, same as oracle’s on this image

Now once this port (1521 is the default for the Oracle Listener for TCP connections although 1522 is also popular) is open, you can connect from outside the image.

You can also just wipe all the firewall rules. This is a ‘play’ image running on your personal machine, so there’s probably nothing to worry about doing something like:

[text] [[email protected] ~]# iptables –flush
[[email protected] ~]# /etc/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ] [/text]

Either way, once the firewall is no longer stopping you from talking over port 1521…

You have two options to connect into your VirtualBox guest:

  • Get an IP address for the image that your Host can ‘see’
  • Setup Port Forwarding

Get an IP Address

What I do, from trial-and-error, is setup a 2nd network adapter.

You'll need to reboot your image after any networking changes

You’ll need to reboot your image after any networking changes

And then once your image is up and running, see if you got an IP assigned.

In *NIX this is done via

[text] [[email protected] ~]$ /sbin/ifconfig
eth1 Link encap:Ethernet HWaddr 08:00:27:22:79:4F
inet addr:192.168.0.18 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe22:794f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5931 errors:0 dropped:0 overruns:0 frame:0
TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:393510 (384.2 KiB) TX bytes:1242 (1.2 KiB)
[/text]

So I can connect directly onto 192.168.0.18, probably.

[text] Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\jdsmith>ping 192.168.0.18

Pinging 192.168.0.18 with 32 bytes of data:
Reply from 192.168.0.18: bytes=32 time<1ms TTL=64
Reply from 192.168.0.18: bytes=32 time<1ms TTL=64
Reply from 192.168.0.18: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.0.18:
Packets: Sent = 3, Received = 3, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
Control-C
[/text]

Let’s see what happens in SQL Developer.

I don't normally connect by IP, but when I do...

I don’t normally connect by IP, but when I do…

So why don’t I always just do this?

Well, when I enable my corporate VPN, this no longer works for me. Or, the IP address CAN change.

If only there were a better way?

Port Forwarding

Basically I can tell VirtualBox to take traffic from a local port and transfer it to a port on the guest port. So I want to talk on port 1521 and have it go to the listener port on our Developer Day image.

Pretty straightforward...

Pretty straightforward…

You remembered to open up port 1521 in the Linux Firewall, yes? Good.

Now connect!

Remember in 12c, you reference PDBs by their SERVICE, not the SID

Remember in 12c, you reference PDBs by their SERVICE, not the SID

Disclaimer: I’m not a VirtualBox OR Networking Guru

Trial and error, I figured this out. If you want REAL advice, try the VirtualBox forums, they’re very good.

Related Posts Plugin for WordPress, Blogger...
Tell Others About This Story:

Comments 16

    1. thatjeffsmith Post
      Author
  1. I am able to ping to the Guest VM ip from main host OS, however while trying to connect SQL Developer, its giving and error, Network Adapter could not established the connection.

    1. thatjeffsmith Post
      Author

      yes

      [email protected]

  2. just a note for 12.0.1.2 developer day vm from here:

    http://www.oracle.com/technetwork/database/enterprise-edition/databaseappdev-vm-161299.html

    everything is already set up (vm network is nat with 1521 port forwarding) , except you need to enable networking inside vm linux, which is on top right corner – just click on network icon and enable connection – then you’ll be able to connect from the host

    took me while, playing with linux firewall and vm networking which was not needed 🙂

  3. I forgot say that I have also installed oracle client on win8 and even if i try to connect through tnsnames.ora (connection type), I have the same error.

  4. I forgot add some about computer connections:
    So, I have two IP addresses 192.168.1.102 (win8.1) and 192.168.1.111 VM.
    Ping between above addresses is ok.

    1. thatjeffsmith Post
      Author
      1. Hi. Thank You for so fast answer. I read your post and unfortunately it doesn’t work. I have such a situation first time.

  5. Hello Jeff.
    I have problem with connection between sqldeveloper (windows 8.1) and VM (oracle database 11g) .
    If I work on VM, sqldeveloper works without any problems, but if I would like to connect through sqldeveloper on Win8.1, automatically get error:
    TNS-12170 timeout.
    I don’t where is the problem, because I did many similar installations and I’ve never seen something like this.
    May You help me?
    Thanks a lot

  6. Man!!! Thanks a ton for the help! I was going nutz trying to connect to the orcl instance on my VM from host. Read many threads, done many stuff and nothing! But then, found your tip and voilà! I never considered that the problem was in the ports. I assumed those ports were automatically added on the firewall exceptions during the Oracle installation (come on, it should be like that).

  7. Thank you so much!
    My host browser could not be connected to the apex on my VBox machine, and with the quick fix to open the ports did the trick!

    Thank you!

  8. Hi Jeff,

    I have installed Oracle EBS r12.2.3 vision instance on my Oracle Virtualbox.
    I have Oracle 11g running on windows 8.1 and now I want to connect SQL Developer to Oracle EBS schemas.

Leave a Reply

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