Welcome to LQ.
Redhat EL 5, Fedora, the ns2 dependencies :
# yum install \
libX11-devel libXext-devel libXau-devel libXmu-devel gcc-c++
# yum remove tcl tk
.. to prevent that ns2 picks up some wrong tcl, tk.
Be aware, that the latest version is ns-allinone-2.34 .
Please tell the reasons to use version 2.31 :
is of general interest to me, and some other LQ members.
More install info
http://nsnam.isi.edu/nsnam/index.php/User_Information
And : LQ Search → "Tag Name" = ns2
http://www.linuxquestions.org/questions/search.php
.....
Example : mkdir ns2 && cd /home/<user>/ns2/
tar xvf ns-allinone-2.31.tar.gz
cd ns-allinone-2.31/
./install
.....