研发小课堂丨5G不只是无线---5G流量到有线的转发

今年是5G大规模使用的元年,也是 5G 时代的元年, 5G 的大幕拉开,飞凌先后发布 5G网关FCU2301 和FCU2302 。随着网关的发布,越来越多的人开始关注如何让电脑的有线分享到 5G 的流量,下面我就来给大家展示一下, 5G 流量的转发给有线的流程。

第一步 设置自动 dhcpd

root@localhost:~# systemctl enable isc-dhcp-server.service

Synchronizing state of isc-dhcp-server.service with SysV service script with

/lib/systemd/systemd-sysv-install.

Executing: /lib/systemd/systemd-sysv-install enable isc-dhcp-server

第二步 设置静态 IP :(设置的 IP 网口为连接电脑的网口)

root@localhost:~# vi /etc/systemd/network/fm1-mac6.network

[Match]

Name=fm1-mac6

Kernel CommandLine=!root=/dev/nfs

[Network]

Address=192.168.2.1/24

第三步 设置 NAT 打开转发:

root@localhost:~# vi /etc/sysctl.conf

第四步设置转发:

root@localhost:~# iptables -t nat -A POSTROUTING -o enx001e101f0000 -j MASQUERADE

保存 iptables 配置:

root@localhost:~# netfilter-persistent save

run-parts: executing /usr/share/netfilter-persistent/plugins.d/15-ip4tables save

run-parts: executing /usr/share/netfilter-persistent/plugins.d/25-ip6tables save

root@localhost:~# netfilter-persistent reload

run-parts: executing /usr/share/netfilter-persistent/plugins.d/15-ip4tables start

run-parts: executing /usr/share/netfilter-persistent/plugins.d/25-ip6tables start

第五步 重启开发板,配置使 5G 模块可以正常上网,

以插入移动 SIM 卡测试 5G 上网为例,测试是否连接外网:

root@localhost:~# /root/ok104x_MH5000.sh

5G Complite !!!

root@localhost:~# ping www.baidu.com -I enx001e101f0000 -c 5

PING www.a.shifen.com (39.156.66.14) from 10.109.32.164 enx001e101f0000: 56(84)

bytes of data.

64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq=1 ttl=51 time=242 ms

64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq=2 ttl=51 time=60.4 ms

64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq=3 ttl=51 time=49.9 ms

64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq=4 ttl=51 time=57.9 ms

64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq=5 ttl=51 time=47.9 ms

--- www.a.shifen.com ping statistics ---

5 packets transmitted, 5 received, 0% packet loss, time 4004ms

rtt min/avg/max/mdev = 47.926/91.744/242.484/75.516 ms

测试 ping 百度,发送接收 5 包数据,丢包率为 0 , 5G 可上外网。如果 5G 模块不能连接外网,请检查 5G 拨号设置或 SIM 卡是否欠费。

查看 5G 拨号脚本为:

root@localhost:~# cat ok104x_MH5000.sh

#!/bin/sh

while true

do

if [ -c /dev/ttyUSB1 ]

then

sleep 4

echo "ATE0" > /dev/ttyUSB1

echo "AT^NDISDUP=1,1,\"cmnet\""> /dev/ttyUSB1

ifconfig enx001e101f0000 up

dhclient enx001e101f0000

echo "5G Complite !!!"

exit 0

fi

sleep 1

echo "waiting ttyUSB1 device ..."

done

如需测试其他网络环境,可以修改此脚本进行 5G 模块的拨号上网设置。

注: echo "AT^NDISDUP=1,1,\"cmnet\""> /dev/ttyUSB2 为移动 APN

echo "AT^NDISDUP=1,1,\"3gnet\""> /dev/ttyUSB2 为联通

echo "AT^NDISDUP=1,1,\"ctnet\""> /dev/ttyUSB2 为电信

第六步 网线一端接控制单元的 mac6 (设置静态 IP 的网口)  另一端接电脑网口,电脑端设置为 DHCP ,电脑会自动获取到 IP ,此时可以正常上网。

相关产品:飞凌嵌入式FCU2302控制单元

猜你喜欢

转载自blog.csdn.net/ningmengzier/article/details/107667451
5G
今日推荐