目录
引言
飞凌嵌入式为了降低ELF2学习板的价格,板子上没有集成WiFi功能,要想利用WiFi上网,需要另外购买额外的模块。不过ELF 2板载一个千兆网卡,可以利用它连接路由器上网。今天分享一个借助PC的网络共享能力,实现借用PC的WiFi来实现上网的方法。
Windows 11的网络共享设置
我在B站曾经分享过“利用电脑的网络共享让开发板联网”的视频,其思想也是适用于ELF2学习板的。不过当时视频是针对Windows 10电脑的,个别操作和Windows 11不同,今天再介绍一下Windows 11的操作。
整个相同的工作原理如下图所示。开发板通过有线网络连接到电脑的网口,再借助电脑WiFi的网络共享能力实现上网。
和Windows 10不同,要启用共享能力,在Windows 11中必须从控制面板开始,而不是从网络设置那里开始。
打开控制面板,在其中选择“网络和Internet”。
然后进入“网络与共享中心”。
在其中点击WiFi 右侧的“连接”进入网口的状态对话框。
在其中点击“属性”按钮。在WLAN属性对话框中选择“共享”标签,然后勾选其中两个选项就可以实现共享上网了。
此时有线网口被自动设置为192.168.137.1,它充当DHCP服务器的作用,为开发板提供上网服务。
开发板的网络设置
修改配置为DHCP
开发板的默认配置为静态IP,eth0 IP为192.168.0.232。需要将其改为DHCP才能利用电脑的网络共享上网。
利用vi /etc/network/interface修改配置文件,设置动态IP的配置文件内容为:
auto eth0
iface eth0 inet dhcp
设置完后使用sync文件同步指令,重启开发板或者重启服务,配置生效。
root@elf2-buildroot:~# sync
root@elf2-buildroot:~# ifdown -a
[ 781.654896] rk_gmac-dwmac fe1b0000.ethernet eth0: Link is Down
root@elf2-buildroot:~# ifup -a
[ 786.095899] rk_gmac-dwmac fe1b0000.ethernet eth0: PHY [stmmac-0:01] driver [RTL8211F Gigabit Ethernet] (irq=POLL)
[ 786.334501] dwmac4: Master AXI performs any burst length
[ 786.334619] rk_gmac-dwmac fe1b0000.ethernet eth0: No Safety Features support found
[ 786.334672] rk_gmac-dwmac fe1b0000.ethernet eth0: IEEE 1588-2008 Advanced Timestamp supported
[ 786.335320] rk_gmac-dwmac fe1b0000.ethernet eth0: registered PTP clock
[ 786.335370] rk_gmac-dwmac fe1b0000.ethernet eth0: configuring for phy/rgmii-rxid link mode
udhcpc: started, v1.36.1
udhcpc: broadcasting discover
[ 789.406927] rk_gmac-dwmac fe1b0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx
[ 789.407086] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
udhcpc: no lease, forking to background
root@elf2-buildroot:~# [ 790.416871] rk_gmac-dwmac fe1b0000.ethernet eth0: Link is Down
[ 793.460159] rk_gmac-dwmac fe1b0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx
[ 795.483497] rk_gmac-dwmac fe1b0000.ethernet eth0: Link is Down
[ 798.526818] rk_gmac-dwmac fe1b0000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx
[ 799.536787] rk_gmac-dwmac fe1b0000.ethernet eth0: Link is Down
[ 802.580100] rk_gmac-dwmac fe1b0000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx
测试网络连通性
这时再使用ifconfig就可以看到动态分配的IP了。
root@elf2-buildroot:~# ifconfig
eth0 Link encap:Ethernet HWaddr 0E:6A:22:A5:A7:8B
inet addr:192.168.137.185 Bcast:192.168.137.255 Mask:255.255.255.0
inet6 addr: fe80::c6a:22ff:fea5:a78b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:72 errors:0 dropped:0 overruns:0 frame:0
TX packets:46 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9939 (9.7 KiB) TX bytes:4728 (4.6 KiB)
Interrupt:127
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:69 errors:0 dropped:0 overruns:0 frame:0
TX packets:69 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9301 (9.0 KiB) TX bytes:9301 (9.0 KiB)
然后可以使用ping和wget测试是否真的能够上网。
root@elf2-buildroot:~# ping www.baidu.com
PING www.a.shifen.com (103.235.46.102) 56(84) bytes of data.
64 bytes from 103.235.46.102 (103.235.46.102): icmp_seq=1 ttl=49 time=76.9 ms
64 bytes from 103.235.46.102 (103.235.46.102): icmp_seq=2 ttl=49 time=84.8 ms
64 bytes from 103.235.46.102 (103.235.46.102): icmp_seq=3 ttl=49 time=78.3 ms
64 bytes from 103.235.46.102 (103.235.46.102): icmp_seq=4 ttl=49 time=73.1 ms
64 bytes from 103.235.46.102 (103.235.46.102): icmp_seq=5 ttl=49 time=73.0 ms
64 bytes from 103.235.46.102 (103.235.46.102): icmp_seq=6 ttl=49 time=72.9 ms
64 bytes from 103.235.46.102 (103.235.46.102): icmp_seq=7 ttl=49 time=72.9 ms
64 bytes from 103.235.46.102 (103.235.46.102): icmp_seq=8 ttl=49 time=79.4 ms
^C
--- www.a.shifen.com ping statistics ---
9 packets transmitted, 8 received, 11.1111% packet loss, time 8725ms
rtt min/avg/max/mdev = 72.891/76.414/84.824/4.043 ms
root@elf2-buildroot:~# curl http://www.baidu.com
-bash: curl: command not found
root@elf2-buildroot:~# wget http://www.baidu.com
Connecting to www.baidu.com (103.235.46.115:80)
saving to 'index.html'
index.html 100% |********************************| 2381 0:00:00 ETA
'index.html' saved
root@elf2-buildroot:~# cat index.html
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=百度一下 class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>新闻</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>地图</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>视频</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>贴吧</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>登录</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">登录</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">更多产品</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>关于百度</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a> 京ICP证030173号 <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>
结语
使用网络共享能力可以解决EFL2开发板没有WiFi的问题,轻松实现上网。