Installing NS-2 and NS-3 on Fedora
ns (Network Simulator) is a discrete-event simulator used primarily for research and educational purposes in networking. The two major versions—ns-2 and ns-3—are substantially different in architecture and usage patterns. This guide covers installation on current Fedora systems.
Installing ns-2 on Fedora
Note: ns-2 is legacy software and requires significant compatibility workarounds on modern systems. Consider ns-3 unless you need specific ns-2 functionality or existing scripts.
Prerequisites
Install base development tools and X11 libraries:
sudo dnf install gcc gcc-c++ make libX11-devel libXt-devel libXmu-devel
Download and extract
wget https://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.34/ns-allinone-2.34.tar.gz/download -O ns-allinone-2.34.tar.gz
tar xf ns-allinone-2.34.tar.gz
cd ns-allinone-2.34
Build and install
ns-2 requires compatibility with older compiler versions. Use the modern gcc with appropriate flags:
CXX=g++ CC=gcc ./install
If you encounter build failures with modern gcc (likely), patch the code or use a container with an older compiler. Alternatively, consider using Docker with a compatible base image.
Environment configuration
Add the following to your shell configuration file (~/.bashrc for bash, ~/.zshrc for zsh):
export NS_HOME=$HOME/ns-allinone-2.34
export PATH=$NS_HOME/bin:$NS_HOME/tcl8.4.18/unix:$NS_HOME/tk8.4.18/unix:$PATH
export LD_LIBRARY_PATH=$NS_HOME/otcl-1.13:$NS_HOME/ns-2.34/lib:/usr/local/lib:$LD_LIBRARY_PATH
export TCL_LIBRARY=$NS_HOME/tcl8.4.18/library
Reload your shell configuration:
source ~/.bashrc
Verify installation:
nam
ns
Installing ns-3 on Fedora
ns-3 is the recommended choice for new projects. It features a cleaner C++ API and better maintainability.
Prerequisites
Install required dependencies:
sudo dnf install libxml2 libxml2-devel gcc gcc-c++ make automake autoconf \
binutils openssh-clients openssl python3 python3-devel mercurial scons \
flex bison tcpdump valgrind gdb sqlite-devel
For additional Python bindings support, also install:
sudo dnf install python3-dev
Download and extract
mkdir -p ~/ns-workspace
cd ~/ns-workspace
wget https://www.nsnam.org/release/ns-allinone-3.42.tar.bz2
tar xjf ns-allinone-3.42.tar.bz2
cd ns-allinone-3.42
(Replace 3.42 with the latest stable version available)
Build
./build.py
This script downloads and configures ns-3 along with dependencies. Proceed to the ns-3 directory:
cd ns-3.42
Configure with Waf
Configure for optimized builds with examples enabled:
./waf -d optimized configure --enable-examples
./waf
For development builds with debugging symbols:
./waf configure
./waf
Validate installation
Run an example simulation:
./waf shell
cd build/optimized/examples
./udp/udp-echo
Inspect the generated pcap trace file:
tcpdump -tt -r udp-echo-0-1.pcap
Or view with more detail:
tcpdump -tt -r udp-echo-0-1.pcap -v
Running Python scripts
ns-3 supports Python-based simulations. Create a simple test script:
#!/usr/bin/env python3
import sys
sys.path.insert(0, '/path/to/ns-3.42/build/optimized/bindings/python')
import ns.core as ns_core
import ns.network as ns_network
import ns.internet as ns_internet
def main():
ns_core.LogComponentEnable("UdpEchoServerApplication", ns_core.LOG_LEVEL_INFO)
ns_core.LogComponentEnable("UdpEchoClientApplication", ns_core.LOG_LEVEL_INFO)
ns_core.Simulator.Stop(ns_core.Seconds(10.0))
ns_core.Simulator.Run()
ns_core.Simulator.Destroy()
if __name__ == "__main__":
main()
Run it with:
./waf shell python3 your_script.py
Troubleshooting
ns-2 compilation failures: Modern gcc versions may reject ns-2’s code. Options include using --std=gnu++98 flags or running ns-2 in a container based on Fedora 15 or CentOS 6.
Missing modules in ns-3: If examples don’t build, ensure all optional dependencies are installed. Check the configure output for warnings about missing features.
Python bindings not found: Ensure you’re running scripts with ./waf shell to set up the correct library paths.
Performance: For large simulations, build with optimization flags and allocate sufficient RAM. Monitor with htop or vmstat.
Thanks for your tuorial :)
I got a problem… I cannot find this path build/optimized/examples/
Any suggestions on how to run udp-echo example ?
thanks a lot!
Glad that you find this tutorial useful.
Try ‘./build.py –enable-examples –enable-tests’ when building ns-3.
There is a more detailed tutorial for ns-3 now from nsnam.org: http://www.nsnam.org/docs/release/3.15/tutorial/singlehtml/index.html , I also suggest it.
Install ns-allinone-2.35 in fedora 18
NS2 stands for network simulator and it is not in fedora repository but it’s allinone package is available on isi.edurecently ns-2.35 RC7 is there with updated tcl and tk library but still it is not support gcc-4.5 series (does not like the X:() construct) so i made 2 patches.
After apply those patches you can follow below steps.
Installation of NS-2.35
Open Terminal, Give the following command one by one
su (press enter and enter your root or super user password)
yum groupinstall “X Software Tools” {development software tools}
exit (to come out of root user mode)
Once installed, download the NS-2.35 allinone software from the following link. https://dl.dropbox.com/u/24623828/ns-allinone-2.35.tar.gz
Copy that file to /home/pradeep (This is my home folder)
Open terminal again and execute the following commands one by one
tar zxvf ns-allinone-2.35.tar.gz
cd ns-allinone-2.35
Install Dependences :
yum install autoconf
yum install automake
yum install gcc-c++
yum install libX11-devel
yum install xorg-x11-proto-devel
yum install libXt-devel
yum install libXmu-devel
Build ns-allinone-2.35
Go to you download directory and extract package (tar -xvf tarball), go to extracted directory and run
#./install
You may possibly get one error during your installation is linkstate/ls.h error
If you get the above error, open the file (~ns-2.35/linkstate/ls.h) using gedit or any text editor
Go to line number 137 and change this line (void eraseAll() { erase(baseMap::begin(), baseMap::end()); }) to
void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }
again you try the command ./install and this time the installation will be successful.
Once installed the PATH information will be provided to you.
Copy the PATH and LD_LIBRARY_PATH Variable to /home/madhurpremg/NS2/nsallinone-2.35/.bash_profile (see a dot in the beginning)
Input the path information in .bash_profile file like this
export PATH=$PATH: {don’t put}
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: here.
Once done, save the file and close
execute the command
source .bash_profile
try ns or nam to see whether your installation succeeded.
Add PATH in .bashrc
vim ~/.bashrc
Add the following lines to the end of it. Remember replace “/opt/” by your installation path like “/home/username”. And accordingly also change the version numbers. This is for ns 2.35.
# LD_LIBRARY_PATH
OTCL_LIB=/home/madhurpremg/NS2//ns-allinone-2.35/otcl-1.14
NS2_LIB=/home/madhurpremg/NS2//ns-allinone-2.35/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$USR_LOCAL_LIB
# TCL_LIBRARY
TCL_LIB=/home/madhurpremg/NS2//ns-allinone-2.35//tcl8.5.8/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/home/madhurpremg/NS2//ns-allinone-2.35/tcl8.5.8/unix:/home/madhurpremg/NS2//ns-allinone-2.35//tk8.5.8/unix
NS=/home/madhurpremg/NS2//ns-allinone-2.35/ns-2.35/
NAM=/home/madhurpremg/NS2//ns-allinone-2.35/nam-1.15/
PATH=$PATH:$XGRAPH:$NS:$NAM
Let it take effect immediately
source ~/.bashrc
Note: the step described above is important; otherwise, you cannot run ns successfully.
or you can restart your X windows.i.e. logout and then login, or reboot your system, to make it work.)
Now, the installation has been completed. If you try:
$ ns
Then a “%” will appear on the screen.type “exit” to quit the mode and back to “$
Validate ns-2.35
Go to ns-2.35 directory and run
#./validate (take almost 1 hour so keep patience)