Setting listener.ora and tnsnames.ora on Amazon EC2

Every time you start your Amazon EC2 instance, your public and private DNS change. This is a problem because we have to modify the files listener.ora and tnsnames.ora many times. If not, your listener (among other things) will not work.

The following bash script creates the two files with the private ip that you pass as argument and starts the listener. The old files are renamed in the same folder (just in case you want to recover them).

Check that the LISTENER_DIR variable is correct in your system.



if [ $# -ne $EXPECTED_ARGS ]
echo "Usage: `basename $0` {private_ip}"
exit 0

cp ${LISTENER_DIR}/listener.ora ${LISTENER_DIR}/listener.ora.old

echo "LISTENER =" > ${LISTENER_DIR}/listener.ora
echo " (DESCRIPTION_LIST =" >> ${LISTENER_DIR}/listener.ora
echo " (DESCRIPTION =" >> ${LISTENER_DIR}/listener.ora
echo " (ADDRESS = (PROTOCOL = TCP)(HOST = "${1}")(PORT = 1521))" >> ${LISTENER_DIR}/listener.ora
echo " )" >> ${LISTENER_DIR}/listener.ora
echo " )" >> ${LISTENER_DIR}/listener.ora

lsnrctl start

cp ${LISTENER_DIR}/tnsnames.ora ${LISTENER_DIR}/tnsnames.ora.old

echo "ORCL =" > ${LISTENER_DIR}/tnsnames.ora
echo " (DESCRIPTION =" >> ${LISTENER_DIR}/tnsnames.ora
echo " (ADDRESS = (PROTOCOL = TCP)(HOST = "${1}")(PORT = 1521))" >> ${LISTENER_DIR}/tnsnames.ora
echo " (CONNECT_DATA =" >> ${LISTENER_DIR}/tnsnames.ora
echo " (SERVER = DEDICATED)" >> ${LISTENER_DIR}/tnsnames.ora
echo " (SERVICE_NAME = orcl)" >> ${LISTENER_DIR}/tnsnames.ora
echo " )" >> ${LISTENER_DIR}/tnsnames.ora
echo " )" >> ${LISTENER_DIR}/tnsnames.ora


  1. Great content material and great layout. Your website deserves all of the positive feedback it’s been getting.
    see this

  2. This comment has been removed by the author.


  3. ERPTREE Offering Oracle fusion HCM online training, Oracle Fusion SCM Online Training, Oracle fusion financials online
    training, Oracle fusion hcm training, Oracle fusion scm training, Oracle fusion financials training,
    Oracle fusion dba online training in Hyderabad, Bangalore,Gurgon, Noida, India, Dubai, UAE, USA, Kuwait, UK, Singapore, Saudi Arabia, Canada,
    Delhi, Chennai, Kolkata, Pune, Mumbai, Ahmedabad.

    Oracle fusion HCM Online Training

    Oracle Fusion HCM Training

  4. It was really a nice article and i was really impressed by reading this AWS Online Training

  5. Thanks for sharing great article, Hope you will post many more articles like this.

    Oracle Fusion Financials Online Training

  6. Hey Really Thanks for sharing the best information regarding oracle,hope you will write more great blogs.

    oracle fusion financials online training

    oracle fusion financials training in hyderabad

  7. I really enjoy the blog.Much thanks again. Really Great AWS Online Training Bangalore

  8. This concept is a good way to enhance the knowledge.thanks for sharing. please keep it up salesforce Online Training Hyderabad