Starting an Oracle XE listener on Amazon EC2 instance

I have written a few posts regarding getting Oracle listener working on Oracle, I though I would post and independent piece of writing regarding this subject.

I have installed Oracle 11 express version, there are two ways to get Oracle working. The issue is that every time that you reboot an Amazon instance you will get a new IP address and name. When you create Oracle for the first time it uses the server name in the .ora files. This means that when you reboot the server the Oracle listener will fail to start.


Modify the listener.ora and tnsnames.ora files to contain a stack name for the serve and then map the static name to an ever changing host file where the information is inserted when the service is started. The other way is to register the server with Amazons route 53 service. This would allow you to set a FQDN in the two files and when the server is restarted it would work.

As I use more of Amazon AWS then I am starting to use Route 53 even more, but if you just want to get Oracle working without the added expense of Route 53 then the below solution will work.

Modify the tnsnames.ora file

vi /u01/app/oracle/product/11.2.0/xe/network/admin/tnsnames.ora

My tns file looks like this

# tnsnames.ora Network Configuration File:

XE =
(ADDRESS = (PROTOCOL = TCP)(HOST = servername)(PORT = 1521))

(SID = PLSExtProc)

This is a read only file so you will need to use


To save the file

You also need to change the listener.ora file as this also contains the host name of the server.

vi /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora 

My file looks like this

# listener.ora Network Configuration File:

(ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
(PROGRAM = extproc)

(ADDRESS = (PROTOCOL = TCP)(HOST = servername)(PORT = 1521))


This is a read only file so you will need to use


To save the file

You need to create the following file, to recreate the hosts file every time the server is rebooted, this will allow the oracle to work properly.

The script file I called createhostfile.ksh and the contents is

getip=`/sbin/ifconfig eth0 | grep ‘inet addr’ | awk ‘{print $2}’ | sed -e ‘s/.*://’`
newhost=”${getip} servername
rm -f /etc/hosts
echo “ localhost localhost.localdomain” > /etc/hosts
echo $newhost >> /etc/hosts

Note that server name must match what is used in the tnsnames and listener ora files.

To create the file

mdir /opt/scripts

cd /opt/scripts

vi createhostfile.ksh

paste the script above

chmod 755 createhostfile.ksh

Now we can change the oracle-xe file that is used to start and stop oracle.

vi /etc/init.d/oracle-xe

After all of the comment insert the following line


This will call the host file creating every time that oracle is started


One Comment on “Starting an Oracle XE listener on Amazon EC2 instance”

  1. […] Starting an Oracle XE listener on Amazon EC2 instance […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s