# How to Install Kamailio and Open5GS

## Prepare the System

```bash
apt update
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696258389012/b66d8007-8902-4b2b-970f-55adaa722b84.png align="center")

```bash
apt upgrade -y 
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696258476359/3678629e-7699-4dc3-8fed-384ad1318d0e.png align="center")

```bash
hostnamectl set-hostname sip.telco-sec.com
```

### Install Dependencies

```bash
apt install -y mysql-server tcpdump screen ntp ntpdate git-core dkms gcc flex bison libmysqlclient-dev make libssl-dev libcurl4-openssl-dev libxml2-dev libpcre3-dev bash-completion g++ autoconf rtpproxy libmnl-dev libsctp-dev libradcli-dev libradcli4
```

### Allow SSH Root Login

```bash
sudo sed -i -e '/^#PermitRootLogin/s/^.*$/PermitRootLogin yes/' /etc/ssh/sshd_config

sudo systemctl restart sshd
```

## Install Kamailio

```bash
apt install -y kamailio* 
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696258692066/2a22bb72-a03b-4a45-91b6-95d8e441dd83.png align="center")

```bash
rfs@volte:/etc/kamailio$ sudo su
root@volte:/etc/kamailio# mysql_secure_installation
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1696258756066/1ad8574d-6b7e-4096-85c7-065bcdced446.png align="center")

```bash
nano /etc/kamailio/kamailio.cfg
```

```bash
#!define WITH_MYSQL
#!define WITH_AUTH
#!define WITH_USRLOCDB
```

```bash
alias="ims.mnc001.mcc001.3gppnetwork.org"
listen=udp:192.168.1.195:5060 advertise 192.168.1.195:5060
listen=tcp:192.168.1.195:5060 advertise 192.168.1.195:5060
modparam("rtpproxy", "rtpproxy_sock", "udp:192.168.1.195:7722")
```

```bash
adduser --quiet --system --group --disabled-password \
        --shell /bin/false --gecos "Kamailio" \
        --home /var/run/kamailio kamailio
```

```bash
chown kamailio:kamailio /var/run/kamailio
```

```bash
sudo systemctl restart kamailio
```

### Configure RTPProxy

```bash
vi /etc/default/rtpproxy 
# Defaults for rtpproxy

# The control socket.
#CONTROL_SOCK="unix:/var/run/rtpproxy/rtpproxy.sock"
# To listen on an UDP socket, uncomment this line:
#CONTROL_SOCK=udp:127.0.0.1:22222
CONTROL_SOCK=udp:127.0.0.1:7722

# Additional options that are passed to the daemon.
EXTRA_OPTS="-l 192.168.1.195 -d DBUG:LOG_LOCAL0"
```

```bash
sudo systemctl restart rtpproxy
sudo systemctl daemon-reload
```

```bash
sudo apt install -y debhelper default-libmysqlclient-dev gperf  libavcodec-dev libavfilter-dev libavformat-dev libavutil-dev libbencode-perl libcrypt-openssl-rsa-perl libcrypt-rijndael-perl libdigest-crc-perl libdigest-hmac-perl libevent-dev libhiredis-dev libio-multiplex-perl libio-socket-inet6-perl libiptc-dev libjson-glib-dev libnet-interface-perl libpcap0.8-dev libsocket6-perl libspandsp-dev libswresample-dev libsystemd-dev libxmlrpc-core-c3-dev markdown dkms module-assistant keyutils libnfsidmap2 nfs-common rpcbind libxtables-dev libip6tc-dev libip4tc-dev
```
