# Installing Ueransim ### 24 April 2023 Let's take a look at the VM station. We already has two VM, the plain Ubuntu and the free5gc one. :::info ![](https://i.imgur.com/jd64YPa.png) ::: We would like to follow the tutorial from [here](https://www.free5gc.org/installations/stage-3-sim-install/). ## First: Install ueransim VM 1. Clone and name the VM ```ueransim``` :::info ![](https://i.imgur.com/WSAwQoK.png) ::: 2. Create new mac addresses for all network cards. The bash script is as below. We need to put in inside an .sh file, then execute it. ```bash #!/bin/bash # Install macchanger if not already installed if ! command -v macchanger &> /dev/null then sudo apt install macchanger -y fi # Get a list of network interfaces interfaces=$(ls /sys/class/net) # Loop through each interface and change its MAC address for interface in $interfaces do # Skip the loopback interface if [ "$interface" != "lo" ] then # Bring the interface down sudo ip link set dev $interface down # Generate a random MAC address and assign it to the interface sudo macchanger -r $interface # Bring the interface up sudo ip link set dev $interface up fi done # Show the new MAC addresses ip link show ``` :::info Before ![](https://i.imgur.com/dCSSYjq.png) Running script ![](https://i.imgur.com/DII1Dqa.png) After ![](https://i.imgur.com/R9zuPOE.png) ::: 3. It is essential to verify that the virtual machine (VM) has internet access and can be accessed via SSH. As observed earlier, the VM has two network interfaces: "Host Only" and "NAT." The NAT interface allows the VM to download macchanger, confirming that internet access is indeed available. To make sure we can connect to SSH, we check the IP address using ```ip addr``` :::info ![](https://i.imgur.com/sI88FqX.png) ::: We get 192.168.70.133 as the IP address of ueransim. Then, we connect using PUTTY because I'm using Windows and it is convenient to use PUTTY. :::info ![](https://i.imgur.com/0y2ImAF.png) ![](https://i.imgur.com/V0p6ziB.png) Successfully connected using SSH ::: 4. Change the hostname to ```ueransim```. :::info ![](https://i.imgur.com/X2U5xNG.png) ![](https://i.imgur.com/HZ3lHNQ.png) ^Additionally, it is recommended to edit the /etc/hosts file using the command "sudo nano /etc/hosts" to ensure that the hostname matches, thereby avoiding any potential issues with resolving the hostname to the loopback address. Furthermore, to enhance clarity for readers of this document, creating a new user specifically for ueransim is advisable to prevent confusion. ![](https://i.imgur.com/98FLFK0.png) Don't forget to run the command below so that the new username can do sudo ![](https://i.imgur.com/MMgfbxV.png) ::: 5. Change static IP address to ```192.168.56.102```. I did this using Virtual Network Editor in Vmware. :::info ![](https://i.imgur.com/YFfZ48p.png) ![](https://i.imgur.com/QU899En.png) ::: 6. Reboot both. This step does not need to be screenshot. 7. ```ping 192.168.56.101``` from ueransim, and also ```ping 192.168.56.102``` from free5gc. :::success ![](https://i.imgur.com/3DvAIjC.png) ![](https://i.imgur.com/P5erlPp.png) ::: ## Second: Install UERANSIM 1. Download UERANSIM using these commands ```bash cd ~ git clone https://github.com/aligungr/UERANSIM cd UERANSIM git checkout v3.1.0 ``` * First command changes the current working directory to the home directory of the logged-in user. The tilde (~) represents the home directory, so this command takes you to the user's home directory. * Second command clones a Git repository from the specified [URL](https://github.com/aligungr/UERANSIM) to the current working directory. Git is a version control system that allows us to track changes in files and collaborate with others. This command creates a copy of the repository's files on your local machine. * Third command changes the current working directory to the directory of the newly cloned repository, which is named "UERANSIM". This command is used to navigate into the cloned repository's directory so that we can work with the files and folders inside it. * Fourth command checks out a specific branch or tag in the Git repository. In this case, it checks out the tag "v3.1.0". Tags in Git are used to mark specific points in the repository's history, such as releases or stable versions. Checking out a tag allows us to switch to that specific version of the code and work with it. :::success ![](https://i.imgur.com/ubnoMgo.png) success ::: 2. Update and upgrade ueransim VM using these commands ```bash sudo apt update sudo apt upgrade ``` The first command updates the package lists on the system, and the second command upgrades the installed packages to their latest versions. :::success ![](https://i.imgur.com/qNn8cXJ.png) ![](https://i.imgur.com/5IjCPHg.png) success ::: 3. Install the required tools using these commands ```bash sudo apt install make sudo apt install g++ sudo apt install libsctp-dev lksctp-tools sudo apt install iproute2 sudo snap install cmake --classic ``` * The first command installs the "make" package on a Linux-based system using APT. "make" is a popular build tool used in software development to automate the building process of software projects. The sudo prefix is used to execute the command with administrative privileges, which may be necessary for installing system-level packages. * The second command installs the "g++" package on a Linux-based system using APT. "g++" is a GNU Compiler Collection package that provides the C++ compiler. * The third command installs the "libsctp-dev" and "lksctp-tools" packages on a Linux-based system using APT. "libsctp-dev" is a development library for Stream Control Transmission Protocol (SCTP), a transport layer protocol used in networking, while "lksctp-tools" provides user-space tools for SCTP. * The fourth command installs the "iproute2" package on a Linux-based system using APT. "iproute2" is a collection of utilities for managing network interfaces, IP addresses, routing tables, and other networking-related tasks in Linux. * The fifth command installs the "cmake" package as a classic snap on a Linux-based system using Snap. Snap is a package management system that allows you to install software packages as self-contained "snaps" that include all dependencies. "cmake" is a popular build tool used in software development for configuring and building software projects. :::success ![](https://i.imgur.com/F5FFNhb.png) ![](https://i.imgur.com/Wdxzgrt.png) ![](https://i.imgur.com/RlgJzLa.png) ![](https://i.imgur.com/83v6Tsp.png) ![](https://i.imgur.com/cDgM8kV.png) ![](https://i.imgur.com/rCM212i.png) ![](https://i.imgur.com/XokkWgC.png) ![](https://i.imgur.com/UI1hEPz.png) ::: 4. Build UERANSIM using these commands ``` cd ~/UERANSIM make ``` The first command changes the current working directory to the "UERANSIM" directory, and the second command attempts to build the UERANSIM software project using the "make" build tool. :::success ![](https://i.imgur.com/MVusYBH.png) ![](https://i.imgur.com/kAVlDBF.png) ::: 5. Go to free5gc VM using SSH, then remove obselete tools using these commands ``` sudo apt remove cmdtest sudo apt remove yarn ``` The first command removes the "cmdtest" package, and the second command removes the "yarn" package. :::success ![](https://i.imgur.com/w8FFLIx.png) ![](https://i.imgur.com/QuT1tvG.png) ![](https://i.imgur.com/oL00J3i.png) ::: 6. Install Node.js and Yarn ``` curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update sudo apt-get install -y nodejs yarn ``` The commands download and add the GPG public key for the Yarn package manager, add a package repository entry for Yarn, update the system's package lists, and finally install Node.js and Yarn packages on the system using APT. These commands are commonly used in JavaScript development environments to set up the necessary tools for managing JavaScript packages and running JavaScript code on the server-side. :::success ![](https://i.imgur.com/bofX6ps.png) ![](https://i.imgur.com/UnVCtxf.png) ![](https://i.imgur.com/CM33w5v.png) ![](https://i.imgur.com/gvrEOgO.png) ![](https://i.imgur.com/k1SPvEe.png) ![](https://i.imgur.com/1W39gfT.png) ::: :::info Upon further investigation, I have discovered that the app I installed under the previous user, "gopalatius," is not easily accessible when logged in with the second user, "free5gc." My initial intention was to use a different user for the purpose of creating easily distinguishable screenshots. However, it appears more feasible to stick with the first user I created during the setup of free5gc. Note: Step 5 and 6 has already been done when installing free5gc before. ::: 7. Run Webconsole server using these commands ```bash cd ~/free5gc/webconsole go run server.go ``` The first command changes the current directory to the "webconsole" directory within the "free5gc" directory, and the second command compiles and runs the "server.go" Go program, starting a server or web application. These commands are commonly used in Go development environments to navigate to a specific directory and run Go programs. :::success ![](https://i.imgur.com/nAbja4h.png) ![](https://i.imgur.com/sVawJb7.png) ::: 8. Using web browser from host machine, enter URL http://192.168.56.101:5000 :::success ![](https://i.imgur.com/sEbd7cE.png) ::: 9. Login using username ```admin``` and password ```free5gc``` 10. Go to Subscribers, and create a new data. Change "Operator Code Type" to OP. Leave rest unchanged then submit. :::success ![](https://i.imgur.com/1VfnQ0s.png) We can close the web console server after this ::: 11. Edit ```~/free5gc/config/amfcfg.yaml``` and change ngaplpList IP to ```192.168.56.101``` :::success Before ![](https://i.imgur.com/fnQL4Qg.png) After ![](https://i.imgur.com/6UMzS01.png) ::: 12. Edit ```~/free5gc/config/smfcfg.yaml``` and in the entry inside userplane_information / up_nodes / UPF / interfaces / endpoints, change the IP to ```192.168.56.101``` :::success Before ![](https://i.imgur.com/5XVHeqP.png) After ![](https://i.imgur.com/3s11Vmp.png) ::: 13. Edit ```~/free5gc/config/upfcfg.yaml``` and change gtpu IP to ```192.168.56.101``` :::success Before ![](https://i.imgur.com/PiTEIGN.png) After ![](https://i.imgur.com/swx2OjR.png) ::: 14. Back to ueransim VM using SSH, edit ```~/UERANSIM/config/free5gc-gnb.yaml``` and change the ngapIp IP, as well as the gtpIp IP, to 192.168.56.102 :::success Before ![](https://i.imgur.com/X4sCW1r.png) After ![](https://i.imgur.com/06fx6PZ.png) ::: 15. Examine file ```~/UERANSIM/config/free5gc-ue.yaml``` and see if the settings is consistent with those in free5GC (via WebConsole) :::success ![](https://i.imgur.com/rrT5AA4.png) Same ::: 16. Back to free5gc VM using SSH. Enter these commands ```bash sudo sysctl -w net.ipv4.ip_forward=1 sudo iptables -t nat -A POSTROUTING -o ens33 -j MASQUERADE sudo systemctl stop ufw sudo iptables -I FORWARD 1 -j ACCEPT ``` * The first command uses the "sysctl" command with administrative privileges (via "sudo") to modify the value of the "net.ipv4.ip_forward" kernel parameter to "1". This enables IP forwarding on the system, allowing it to route packets between different network interfaces or subnets. IP forwarding is often needed when setting up a system to act as a router or gateway between multiple networks. * The second command uses the "iptables" command with administrative privileges (via "sudo") to append a rule to the "nat" table's "POSTROUTING" chain. The "-t" option specifies the table, in this case, "nat". The "-A" option indicates that the rule should be appended to the chain. The "-o" option specifies the outgoing network interface (replace "<dn_interface>" with the actual interface name) to which the rule should apply. The "-j" option specifies the action to take, in this case, "MASQUERADE", which is a form of Network Address Translation (NAT) that allows devices on a private network to access the internet using the public IP address of the router. This rule is commonly used in network setups where a system acts as a gateway for other devices to access the internet. * The third command uses the "systemctl" command with administrative privileges (via "sudo") to stop the "ufw" service, which is the Uncomplicated Firewall service used in Ubuntu and other Debian-based Linux distributions. Stopping the "ufw" service disables the firewall rules configured by "ufw" and effectively disables the firewall. This command is commonly used when temporarily disabling the firewall for testing or troubleshooting purposes. * The fourth command is adding a new rule to the FORWARD chain of the iptables firewall, allowing all packets to be forwarded between network interfaces without being blocked. This can be useful in certain network configurations where you want to allow all traffic to pass through the system without being filtered or blocked by the firewall. :::success ![](https://i.imgur.com/Gh72F9m.png) ::: 17. Run free5gc using ```bash cd ~/free5gc ./run.sh ``` :::success ![](https://i.imgur.com/C0uGml1.png) ::: 18. Run three terminals for UERANSIM using SSH. In terminal 1: SSH into ueransim, make sure UERANSIM is built, and configuration files have been changed correctly, then execute nr-gnb. ```bash cd ~/UERANSIM build/nr-gnb -c config/free5gc-gnb.yaml ``` :::success ![](https://i.imgur.com/UWW1LAA.png) ::: In terminal 2: SSH into ueransim, and execute nr-ue with admin right :::success ![](https://i.imgur.com/5H9kYGl.png) ::: In terminal 3: SSH into ueransim, and ping ```192.168.56.101``` to see ```free5gc``` is alive. Then, use ```ifconfig``` to see if the tunnel ```uesimtun0``` has been created (by nr-ue) :::success ![](https://i.imgur.com/W9vOOyb.png) ![](https://i.imgur.com/QKGq4eJ.png) ::: 19. ping google.com using that interface ```bash= ping -I uesimtun0 google.com ``` :::success ![](https://i.imgur.com/4TpPQqj.png) Free5gc is running properly :) :::