Author’s note: in the current Developer Day image, port forwarding on 1521 is there out-of-the-box for easy connections to your Database.
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.
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:
[root@localhost ~]# iptables --flush [root@localhost ~]# /etc/init.d/iptables save iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
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.
And then once your image is up and running, see if you got an IP assigned.
In *NIX this is done via
[oracle@localhost ~]$ /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)
So I can connect directly onto 192.168.0.18, probably.
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
Let’s see what happens in SQL Developer.
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.
You remembered to open up port 1521 in the Linux Firewall, yes? Good.
Now connect!
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.
27 Comments
Thank you Jsmith .. Worked for me 🙂
I’m using second method “Port Forwarding” to access database on Host Machine(Windows 10).
1. Unable to ping VM on Host.
2. While trying to connect Oracle Sql Developer, getting error “An existing connection was forcibly closed by the Remote Host”.
Please confirm your connection is set to localhost:1521 and that you’re using our Virtualbox appliance.
Hostname: localhost
Port:1521
SID:
Service name : “VBUS123”
I believe, above information insure configuration is same you explained in Reply.
So not our vbox…I’m not sure what’s wrong without knowing your VM network settings.
Great post.
Note that you can setup the image using static ip address; that will negate the use of 2nd adapter.
Man… years later this is STILL the answer! Thank you Jeff for Port Forwarding trick!
This worked for me! Thanks for this post
Thanks that helped a lot.
How do you logon to a user that has access to edit the firewall ?
Im logged on to the Oracle account – and the SYSTEM menu is not available.
I can SU to root in a terminal window, but cant work out how to start the Firewall GUI editor
Nice work. Thank you
Just login to the VM as root if you’d like, the password is ‘oracle’
Thank your very much. Your simple solution saved lot of my time. Thanks again. It is really appreciated.
You’re very welcome!
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.
Hi, do you have a direct email I can send questions to?
yes
[email protected]
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 🙂
Hi. Jeff
I read carefully again your post and additionally I found website
https://cdivilly.wordpress.com/2014/11/05/remote-debug-oracle-database-in-a-virtualbox-vm-using-sql-developer/
where is reference to your website 🙂 and when I combined two websites than it started to works.
Thank you so much.
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.
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.
did you read my post, the easiest thing to do is setup port forwarding, do that and it doesn’t matter what your IP addresses are
Hi. Thank You for so fast answer. I read your post and unfortunately it doesn’t work. I have such a situation first time.
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
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).
And as usual the simplest solution wins..
Thanks!
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!
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.