free5GC 小試身手
此示範我們將利用 free5GC 核網 及 UE/RAN 模擬器操作一些簡單的網路應用:
- ping + tcpdump
- wget
- ptt (
ssh bbsu@ptt.cc
)
ping + tcpdump
首先將 free5GC 核網及 UERANSIM 啟動 (free5gc 需要一個終端機, ueransim 需要兩個終端機)。
再開啟新的終端機登入 ueransim:
ssh 192.168.56.102 -l ubuntu
用 ifconfig
確認 uesimtun0
通道已建立,並用 ping
試試藉由
uesimtun0
能否連通:
$ ping google.com
PING google.com (172.217.27.142) 56(84) bytes of data.
64 bytes from tsa03s02-in-f14.1e100.net (172.217.27.142): icmp_seq=1 ttl=63 time=3.98 ms
64 bytes from tsa03s02-in-f14.1e100.net (172.217.27.142): icmp_seq=2 ttl=63 time=3.87 ms
64 bytes from tsa03s02-in-f14.1e100.net (172.217.27.142): icmp_seq=3 ttl=63 time=4.06 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 3.872/3.970/4.060/0.076 ms
$ ping -I uesimtun0 google.com
PING google.com (172.217.27.142) from 60.60.0.1 uesimtun0: 56(84) bytes of data.
64 bytes from tsa03s02-in-f14.1e100.net (172.217.27.142): icmp_seq=1 ttl=61 time=5.85 ms
64 bytes from tsa03s02-in-f14.1e100.net (172.217.27.142): icmp_seq=2 ttl=61 time=4.87 ms
64 bytes from tsa03s02-in-f14.1e100.net (172.217.27.142): icmp_seq=3 ttl=61 time=4.76 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 4.760/5.160/5.847/0.487 ms
先用 route -n
觀察現有的 routing table, 顯示出關於兩個網路介面
enp0s3
及 enp0s8
的規則:
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.2.2 0.0.0.0 UG 100 0 0 enp0s3
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s3
10.0.2.2 0.0.0.0 255.255.255.255 UH 100 0 0 enp0s3
192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s8
其中 10.0.2.0/24
網路 及 enp0s3
介面為 VirtualBox NAT 網卡所建立。我們先關閉此介面:
$ sudo ifconfig enp0s3 down
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s8
只剩 Host-only 192.168.56.0/24
網路。執行 ping
看看:
$ ping 8.8.8.8
ping: connect: Network is unreachable
發現無法連線,但執行:
$ ping -I uesimtun0 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 60.60.0.1 uesimtun0: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=61 time=7.17 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=61 time=5.41 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=61 time=5.15 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2005ms
rtt min/avg/max/mdev = 5.150/5.907/7.165/0.895 ms
則有反應,因為我們要求 ping
走 free5GC 核網路徑。想要讓 ping 8.8.8.8
成功,我們可以用 uesimtun0
介面( IP 為 60.60.0.1 )當作新的預設閘道:
$ sudo ip r add default dev uesimtun0
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 uesimtun0
192.168.56.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s8
如此所有 192.168.56.0/24
以外的封包都會走 uesimtun0
。因此再執行便可成功:
$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=61 time=5.02 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=61 time=6.31 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=61 time=5.41 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 5.017/5.581/6.312/0.541 ms
...
但若想執行:
$ ping google.com
ping: google.com: Temporary failure in name resolution
則得到無法辨認網域網址。要解決此問題,我們可以更改檔案
/etc/resolv.conf
(但注意要記得回復):
sudo nano /etc/resolv.conf
暫時將 nameserver IP 改成 8.8.8.8
nameserver 8.8.8.8
這時已可以看到反應:
$ ping google.com
PING google.com (216.58.200.46) 56(84) bytes of data.
64 bytes from tsa01s08-in-f46.1e100.net (216.58.200.46): icmp_seq=1 ttl=61 time=5.19 ms
64 bytes from tsa01s08-in-f46.1e100.net (216.58.200.46): icmp_seq=2 ttl=61 time=50.4 ms
64 bytes from tsa01s08-in-f46.1e100.net (216.58.200.46): icmp_seq=3 ttl=61 time=5.66 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 5.191/20.423/50.414/21.207 ms
要進一步確認 ping
過程的確藉由 free5GC 核網,我們可以再開
另一個終端機登入 ueransim
,執行下列指令:
$ sudo tcpdump -n -i any host 60.60.0.1 or 192.168.56.101
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked v1), capture size 262144 bytes
並在原來終端機再下 ping 8.8.8.8
指令。幾秒後兩邊都按 Ctrl-C。
可以觀察到相關封包的確藉由 uesimtun0
送出及回傳。
$ sudo tcpdump -n -i any host 60.60.0.1 or 192.168.56.101
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on any, link-type LINUX_SLL (Linux cooked v1), capture size 262144 bytes
10:24:56.138729 IP 192.168.56.101.38412 > 192.168.56.102.38740: sctp (1) [HB REQ]
10:24:56.138783 IP 192.168.56.102.38740 > 192.168.56.101.38412: sctp (1) [HB ACK]
10:24:58.456532 IP 60.60.0.1 > 8.8.8.8: ICMP echo request, id 33, seq 1, length 64
10:24:58.457416 IP 192.168.56.102.2152 > 192.168.56.101.2152: UDP, length 100
10:24:58.462136 IP 192.168.56.101.2152 > 192.168.56.102.2152: UDP, length 92
10:24:58.462324 IP 8.8.8.8 > 60.60.0.1: ICMP echo reply, id 33, seq 1, length 64
10:24:59.458823 IP 60.60.0.1 > 8.8.8.8: ICMP echo request, id 33, seq 2, length 64
10:24:59.459031 IP 192.168.56.102.2152 > 192.168.56.101.2152: UDP, length 100
10:24:59.464214 IP 192.168.56.101.2152 > 192.168.56.102.2152: UDP, length 92
10:24:59.464396 IP 8.8.8.8 > 60.60.0.1: ICMP echo reply, id 33, seq 2, length 64
10:25:00.461293 IP 60.60.0.1 > 8.8.8.8: ICMP echo request, id 33, seq 3, length 64
10:25:00.462178 IP 192.168.56.102.2152 > 192.168.56.101.2152: UDP, length 100
10:25:00.474941 IP 192.168.56.101.2152 > 192.168.56.102.2152: UDP, length 92
10:25:00.475561 IP 8.8.8.8 > 60.60.0.1: ICMP echo reply, id 33, seq 3, length 64
10:25:01.463946 IP 60.60.0.1 > 8.8.8.8: ICMP echo request, id 33, seq 4, length 64
10:25:01.464523 IP 192.168.56.102.2152 > 192.168.56.101.2152: UDP, length 100
10:25:01.469297 IP 192.168.56.101.2152 > 192.168.56.102.2152: UDP, length 92
10:25:01.470314 IP 8.8.8.8 > 60.60.0.1: ICMP echo reply, id 33, seq 4, length 64
wget
網路上任意找個 檔案下載。例如:
wget https://golang.org/dl/go1.15.8.darwin-amd64.pkg
看是否能下載 Golang 1.15.8 Mac 版本。
ptt (ssh bbsu@ptt.cc
)
直接登入 PTT 試試 SSH 連線:
ssh bbsu@ptt.cc
Youtube
你也可以試著用 UERANSIM 及 free5GC 使用 Youtube 觀看影片。
你只要安裝有 Desktop 介面的 VM (例如 Ubuntu Desktop),並按照之前安裝使用
UERANSIM 的步驟,藉由 uesimtun0
通道連只 free5GC 即可。
若要減輕你主機的負擔,你也可以試著安裝較輕型的 Desktop VM Lubuntu (在 lubuntu.me 官網。但由於觀看影片仍需較大的運算資源, 你仍需為這 VM 加上 2 個 CPU 及 2048 MB 的記憶體。
可參考影片 在 Lubuntu 使用 Youtube