13

Some background: I am attempting to connect to an Oracle database. I have a username, password, IP address, port, and service name. I only have access to this database from an Ubuntu EC2 instance on AWS because the Oracle database is located inside another organization. Due to this, I do not have access to a DNS hostname for this machine.

I downloaded the "Oracle Instant Client with SQL Plus" client package from Oracle's website and extracted it to a folder. When I try to run it, I get this message:

ORA-24454: client host name is not set

Tony Hinkle
  • 7,673
  • 1
  • 15
  • 40
Karl Johnson
  • 351
  • 1
  • 2
  • 6

7 Answers7

22

After two hours, I figured it out.

Oracle's documentation for the error didn't seem terribly descriptive at first:

ORA-24454: client host name is not set

Cause: The network host name in files like /etc/hosts was not set.

Action: Set the host name and try again.

Now, the command worked on my machine (Ubuntu laptop), but it didn't work on EC2. I mucked around with the HOSTNAME variable for a bit and tried to figure out if there was a way to override the "client host name" in sqlplus's settings -- no dice. I finally compared my machine's /etc/hosts to the one in EC2, and noticed this line that wasn't in EC2:

127.0.1.1 my-laptop-hostname

I didn't know this before, but apparently it's normal on Debian-based machines to map the system's hostname to this IP address. I didn't even know that 127.0.1.1 was a loopback IP; I just knew about 127.0.0.1.

What's more, it seems sqlplus relies on this line being present. Still no idea why.

Anyway, the fix is simple:

$ sudo /bin/bash -c "echo '127.0.1.1 ${HOSTNAME}' >> /etc/hosts"
Giacomo1968
  • 222
  • 2
  • 14
Karl Johnson
  • 351
  • 1
  • 2
  • 6
  • 1
    This solution worked for me on a Mac Book Pro. – axiopisty Jan 03 '18 at 21:04
  • 1
    Thank you! I was having problems getting a connection to an Oracle database using Python and pyodbc. The missing piece I needed was this: `echo "127.0.0.1 \`hostname\`" >> /etc/hosts`. – L42 Jan 26 '18 at 15:34
  • 1
    Very oddly, I found that this also worked for me on a MacBook Pro, while I was running docker wnameless/oracle-xe-11g, whether connecting directly via IP, by "localhost" or by "my-host-name", I needed to have this line in /etc/hosts pointing the loopback 127.0.0.1 IP at my hostname. Upon adding it, they all worked, upon removing it, everything broke, adding it again, everything is fine again. Very odd. – turiyag Aug 04 '18 at 21:30
6

It's been mentioned in a comment above, but this line fixed this issue for me on my MacBook Pro, running docker wnameless/oracle-xe-11g on port 1521.

sudo /bin/bash -c "echo '127.0.0.1 ${HOSTNAME}' >> /etc/hosts"

The following commands then all worked just fine:

sqlplus system/oracle@localhost:1521/xe
sqlplus system/oracle@127.0.0.1:1521/xe
sqlplus system/oracle@my-personal-hostname:1521/xe

Very odd, but that's the fix.

turiyag
  • 161
  • 1
  • 2
4

This was due to a VPC setting which the EC2 was created under, was set to no:

Under Your VPCs -> Summary tab,

DNS hostnames: no

In order to avoid manual resolution as answered by others, set the value of DNS hostnames to yes

Arif Basri
  • 41
  • 2
3

I had this problem in my macOS

Please make sure that you entered your hostname correctly on your /etc/hosts file

to do that> hostname command shows the "real hostname of your mac" and the the line below to /etc/hosts

127.0.0.1 your_host_name.local
Giacomo1968
  • 222
  • 2
  • 14
Melih
  • 131
  • 2
  • Did not have to add the .local extension just the 127.0.0.1 `hostname` For SQL*Plus: Release 19.0.0.0.0 – kisna Jun 10 '20 at 19:09
1

This issue happened to me, but was not resolved solely by the solution above. If you're using the 11g/12g client, you will get a different error.

In order to resolve the error, do the following:

  1. hostname -A returns the same hostname that appears in /etc/sysconfig/network
  2. Verify that the hostname is in your /etc/hosts as noted above (127.0.0.1 hostname)
Giacomo1968
  • 222
  • 2
  • 14
Bren1818
  • 111
  • 1
1

For people using one of the virtual machines Oracle provides VPN can be a factor here.

If connected, disconnecting from the VPN fixes the problem.

For some reason the Oracle client doesn't like being connected to a VPN, despite the fact that the network traffic for the Oracle Database won't leave the local machine

armitage
  • 1,418
  • 2
  • 14
  • 20
Cristik
  • 111
  • 2
1

In addition to the top 2 answers (Thanks!), I had to set the HOSTNAME variable in my ~/Library/LaunchAgents/environment.plist file on MacBook running Catalina as it was not already set.

tinlyx
  • 2,735
  • 4
  • 29
  • 53