SIPS Server實作
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
前言
因為我有自己的伺服器,所以打算開三台VM去實作出這個架構,再透過bridge去建置三台電腦的內網環境
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
先放一張別人做的SIP運作的原理過程圖來源
簡單的說SIP會有幾種請求
方法 |
敘述 |
INVITE |
邀請建立會議(Session) |
ACK |
回覆確認邀請(INVITE)的回覆已收到 |
OPTIONS |
用來傳送 midcall訊號(mid-session 資訊)並不改變 Session 狀態 |
BYE |
結束一個已連結的 Session |
CANCEL |
取消一個已發出邀請但尚未連結的 Session |
REGISTER |
註冊使用者的 URL |
我要透過這些方法讓兩台UAC(兩支電話)可以透過server互相通話~
首先先裝好Opensips在SIP Server
我踩了一堆坑最後找到這篇成功裝起來,原本是用make all去編譯所有c檔案去裝起來,一開始我用x64的Ubuntu 22.04 LTS(server版的),因為是用PVE去操作,所以沒辦法跟本機共用剪貼簿,搞了半天發現好像x64的library不能編opensips的c files,去看了一下官方的document,確實是這樣,所以又搞了i863的ubuntu,後來也改用desktop版,不然沒有辦法複製很痛苦,最後最後用Ubuntu 22.04 LTS(desktop版)上透過裝package的方式直接搞好了==
SIP Server
我是參考這篇ref
作法如下:
首先
sudo apt-get update
然後還要裝curl、mysql-server、vim、apache2
建議是直接拿root去跑所有command
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
到這個網站複製這三行command
載到這邊可以先apt update
一下
csdn教學是有去確認這台電腦有沒有其他版本,因為我是剛從ubuntu官網載下來的乾淨ubuntu,所以我就跳過這步了,要確認就照著她的教學做
再來是裝opensips-cli,跟裝opensips一樣,到網站選你的ubuntu版本,複製command
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
把他的modules全部都裝起來避免發生什麼錯誤,這邊會跑比較久
apt-get install opensips-*
設定他的資料庫,這邊如果你前面mysql-server沒弄好就會出錯,預設的mysql帳密是root/,密碼是沒東西,他如果要你輸入密碼你按enter就好了,不用按空白鍵。
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
等他跑好就差不多了
最後用這兩個指令去啟動opensips
用systemctl status opensips
可以去查看伺服器狀態
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
有看到綠色的active(running)就成功了
最後還要記得設定opensips.cfg,我這邊是在"/etc/opensips.cfg",把socket設成這台機器的ip,預設得文件裡面已經有udp了,理論上加tcp應該也可,但我沒試
找自己的ip可以用ifconfig,我這台的ip是10.50.40.112,我socket就設定成10.50.40.112:5060
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
這邊要記得Load usrloc.so
跟registrar.so
這兩個module,如果要用本機資料庫好像還要Load auth_db.so
,他的資料庫好像是分成你可以用本機當資料庫或是裝mysql來當資料庫
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
都設定好了之後就要去新增使用者,我是用opensips-cli這個工具去裝的,用法就是像這樣:
Add the username@domain.com user with the S3cureP4s$ password.
opensips-cli -x user add username@domain.com S3cureP4s$
我這邊username是9001,domain是10.50.40.112,密碼我設password
所以我下這行opensips-cli -x user add 9001@10.50.40.112 password
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
這樣就成功新增了
UAC
我用的是windows透過zoiper連線我的SIP Server(UAS),先用zoiper登入
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
設定proxy
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
這邊有抓到SIP的UDP服務TCP剛剛沒設定如果有時間可以試看看其他協定
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
成功連上了
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
同樣做法也把9002設定到另一台VM
Wireshark
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
嘗試打電話給9001發現time out了,回到SIP server那台用wireshark看看發生什麼事
安裝wireshark看這篇
這邊先整理一下資訊
有三台VM
資訊 |
SIP server |
UAC1 |
UAC2 |
系統版本 |
ubuntu |
Windows 11 |
Windows 11 |
IP |
10.50.40.112 |
10.50.40.174 |
10.50.40.168 |
call-ID |
server |
9002 |
9001 |
安裝好後下filter指令ip.addr == 10.50.40.174 && sip
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
點開來看REGISTER的request,發現都有回200 ok,那問題可能是出在server沒辦法發Request給兩台UAC,所以A發給server可以,但是server發給B不行,於是我到兩台UAC分別去ping測試,原先我的懷疑是我的虛擬機沒設定好網卡或是橋接器導致他們不在同一個內網,無法連到server,所以我去ping了之後發現果然失敗了,但是檢查設定,都有在同一個橋接器裡面
UAC1
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
UAC2
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Server
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
後來問朋友發現原來Wiindows預設會關ICMP,就是Ping的服務,去防火牆的寫入規則找到ICMP把他改成啟用就可以了,最後也是順利ping到了…
ㄟ那到底是哪裡有問題?
於是我想說:說不定zoiper的介面有什麼設定是我漏掉的,於是我到youtube找有沒有人也在做類似的事情,找到這個影片,才發現原來登入zioper後,還要自己設定Call-id,超級傻眼,原來只是我沒設定call-id害我弄半天沒辦法讓兩台通話,最後也是成功讓兩台互通,接下來就是拿WireShark去分析過程中擷取的封包~
通話成功的影片
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
可以看到有REGISTER、INVITE Trying、Ringing、ACK、BYE其實過程就跟上面那張圖一樣
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →















