OpenHarmony 开发板的网络配置

系统 OpenHarmony
DHCP(动态主机配置协议)是一个局域网的网络协议。指的是由服务器控制一段IP地址范围,客户机登录服务器时就可以自动获得服务器分配的IP地址和子网掩码。

​想了解更多内容,请访问:​

​51CTO和华为官方合作共建的鸿蒙技术社区​

​https://ost.51cto.com​

一、目标

基于君正X2000开发板,移植OpenHarmony3.0系统后验证网络是否可用。

二、前言

首先,先说明下在开发板中为什么需要手动的进行网络配置,是因为OpenHarmony的网络模块中并没有类似Linux系统中内置的DHCP服务,目前OpenHarmony社区也在开发完善中,所以在开发板烧录后需要手动配置网络。

什么是DHCP呢?

这里简单说下:DHCP(动态主机配置协议)是一个局域网的网络协议。指的是由服务器控制一段IP地址范围,客户机登录服务器时就可以自动获得服务器分配的IP地址和子网掩码。有兴趣可以参看:​​DHCP​​。

三、环境与硬件设备

测试环境

硬件:君正X2000开发板

系统:OpenHarmony 3.0

硬件介绍

功能概述

君正X2000 Halley5开发板基于君正X2000芯片,支持显示,摄像头,千兆以太网,SD卡,USB,音视频编解码,麦克风等接口的开发平台,适用于智能商业、智能物联网、智能穿戴、人机交互、生物识别和图像识别等领域。

硬件级别

L1

硬件参数

四、网络配置

前置条件:开发板连接在路由器,路由器可以访问外网,假设路由器上的IP地址:192.168.32.1。

配置流程:配置网卡IP->添加网关->添加DNS。

配置步骤

(1)ping路由器地址

说明:网卡IP未配置前,PING 路由器 IP地址:192.168.32.1。

命令:ping 192.168.32.1。

/ # ping 192.168.32.1
PING 192.168.32.1 (192.168.32.1): 56 data bytes
ping: sendto: Network is unreachable

(2)查看网络配置

命令:ifconfig -a。

/ # ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:552 (552.0 B) TX bytes:552 (552.0 B)
/ # ifconfig -a
eth1 Link encap:Ethernet HWaddr 5E:BC:34:B1:7F:A1
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:552 (552.0 B) TX bytes:552 (552.0 B)
wlan0 Link encap:Ethernet HWaddr D4:9C:DD:A0:20:C0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

(3)配置网卡IP

命令:ifconfig eth1 192.168.32.202 netmask 255.255.255.0 up。

/ # ifconfig eth1 192.168.32.202 netmask 255.255.255.0 up
/ # ifconfig -a
eth1 Link encap:Ethernet HWaddr 5E:BC:34:B1:7F:A1
inet addr:192.168.32.202 Bcast:192.168.32.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:552 (552.0 B) TX bytes:552 (552.0 B)
wlan0 Link encap:Ethernet HWaddr D4:9C:DD:A0:20:C0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

(4)重新ping路由器地址

网卡IP配置后,PING路由器IP地址:192.168.32.1。

命令: ping 192.168.32.1。

/ # ping 192.168.32.1
PING 192.168.32.1 (192.168.32.1): 56 data bytes
64 bytes from 192.168.32.1: seq=0 ttl=64 time=0.892 ms
64 bytes from 192.168.32.1: seq=1 ttl=64 time=0.463 ms
^C
--- 192.168.32.1 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.463/0.677/0.892 ms

(5)测试

下载访问百度首页,在未添加网关前,PING 百度的IP地址:202.108.22.5。

命令:ping 202.108.22.5。

/ # ping 202.108.22.5
PING 202.108.22.5 (202.108.22.5): 56 data bytes
ping: sendto: Network is unreachable

(6)添加网关

命令:route add default gw 192.168.32.1。

/ # route add default gw 192.168.32.1

(7)再测试

在添加网关后,PING 百度的IP地址:202.108.22.5。

命令:ping 202.108.22.5。

/ # ping 202.108.22.5
PING 202.108.22.5 (202.108.22.5): 56 data bytes
64 bytes from 202.108.22.5: seq=0 ttl=51 time=41.694 ms
64 bytes from 202.108.22.5: seq=1 ttl=51 time=40.833 ms
64 bytes from 202.108.22.5: seq=2 ttl=51 time=40.753 ms
^C
--- 202.108.22.5 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 40.753/41.093/41.694 ms

(8)添加DNS

说明:在/etc/resolv.conf文件,添加nameserver,操作步骤如下:

编辑resolv.conf

命令:vi /etc/resolv.conf。

/ # vi /etc/resolv.conf

添加两个nameserver

命令:

  • nameserver 114.114.114.114。
  • nameserver 192.168.32.1。
nameserver 114.114.114.114
nameserver 192.168.32.1

(9)再次测试

下载一个网页,如:下载百度首页。

命令:wget www.baidu.com。

/ # wget www.baidu.com
Connecting to www.baidu.com (163.177.151.110:80)
saving to 'index.html'
index.html 100% |********************************| 2381 0:00:00 ETA
'index.html' saved

(10)查看下载

查看已下载在本地的网页内容(百度首页)。

命令:cat index.html。

/ # 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&amp;tpl=mn&amp;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>&copy;2017&nbsp;Baidu&nbsp;<a href=http://www.baidu.com/duty/>使用百度前必读</a>&nbsp; <a href=http://jianyi.baidu.com/ class=cp-feedback>意见反馈</a>&nbsp;京ICP证030173号&nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

至此说明网络配置完成了,提醒:由于没有DHCP服务,所以每次启动开发版本之后都需要进行手动配置。

​想了解更多内容,请访问:​

​51CTO和华为官方合作共建的鸿蒙技术社区​

​https://ost.51cto.com​

责任编辑:jianghua 来源: 鸿蒙社区
相关推荐

2022-01-07 21:11:27

鸿蒙HarmonyOS应用

2022-10-14 15:55:24

环境搭建鸿蒙

2021-10-11 14:14:42

鸿蒙HarmonyOS应用

2021-09-10 10:01:04

鸿蒙HarmonyOS应用

2022-03-03 19:21:50

Harmony鸿蒙操作系统

2021-12-16 15:14:54

鸿蒙HarmonyOS应用

2020-12-29 09:59:01

鸿蒙HarmonyOS智能家居

2020-12-16 10:05:48

鸿蒙开发板Onenet平台

2021-09-13 10:03:35

鸿蒙HarmonyOS应用

2022-02-24 16:39:41

OpenHarmonNiobe开发鸿蒙

2021-06-25 15:32:13

鸿蒙HarmonyOS应用

2021-09-08 15:44:56

鸿蒙HarmonyOS应用

2022-04-14 11:44:25

LiteOS线程鸿蒙

2020-10-20 09:32:43

HiSparkWi-FiIoT

2022-08-19 10:54:47

操作系统鸿蒙

2021-09-14 10:09:33

开源MowiSeptentrio

2013-10-14 10:22:22

开源开源开发板平板电脑

2011-04-22 09:32:56

开发板Ubuntu串口

2022-02-16 16:01:02

Hi3516开发板鸿蒙
点赞
收藏

51CTO技术栈公众号