开发板通过网线连接电脑而上网

2024-04-24 22:52

本文主要是介绍开发板通过网线连接电脑而上网,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

简介

关闭win11的防火墙(之前不关也可以的,很奇怪)
一句话:!!!dhcp能自动分配IP即可联通外网!!!
原理也不懂,或许有其他方法也不清楚,但只要在/etc/netplan/01-netcfg.yaml设置dhcp: true利用netplan自动分配ip则可解决所有ping外网不通、git访问不了,apt-get出现Err:1 http://mirrors.163.com/ubuntu-ports focal InRelease Temporary failure resolving 'mirrors.163.com'错误等等问题.

电脑WIFI共享给网口

在这里插入图片描述

在这里插入图片描述

route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         orange.mshome.n 0.0.0.0         UG    100    0        0 eth0
link-local      0.0.0.0         255.255.0.0     U     1000   0        0 eth0
192.168.137.0   0.0.0.0         255.255.255.0   U     100    0        0 eth0
192.168.137.0   0.0.0.0         255.255.255.0   U     100    0        0 eth0

link
路由表的问题

/etc/netplan/01-netcfg.yaml

# this file describes the network interfaces available on your system
# For more information, see netplan(5).
network:version: 2renderer: NetworkManager# renderer: networkdethernets:eth0:dhcp4: trueaddresses: [192.168.137.23/24]gateway4: 192.168.137.1nameservers:addresses: [114.114.114.114, 192.168.137.1]

设置dhcp: true利用netplan自动分配ip的同时设置一个静态ip来实现ssh访问,而不用每次都是用串口来查看ip才能登录。
link:

  • 1
  • 2
  • 3
  • 校园网:(1) (2)

/etc/resolv.conf

自动生成的,dhcp不能分配IP时添加常见的DNS都不行!!

# Generated by NetworkManager
search mshome.net
nameserver 127.0.0.53

/etc/systemd/resolved.conf

#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details[Resolve]
DNS=114.114.114.114
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#DNSOverTLS=no
#Cache=yes
#DNSStubListener=yes
#ReadEtcHosts=yes

虚拟机

若想虚拟机ping开发板,参考这个应该可以。

测试

开启win11防火墙

重新开启防火墙,reboot重启开发板

# # # 查看ifconfig 没问题 # # # 
root@rong-virtual-machine:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.137.155  netmask 255.255.255.0  broadcast 192.168.137.255ether 00:22:33:44:55:66  txqueuelen 1000  (Ethernet)RX packets 115  bytes 20392 (20.3 KB)RX errors 0  dropped 13  overruns 0  frame 0TX packets 117  bytes 13373 (13.3 KB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0device interrupt 87  base 0x2000lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0loop  txqueuelen 1000  (Local Loopback)RX packets 248  bytes 19900 (19.9 KB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 248  bytes 19900 (19.9 KB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
# # # 155为dhcp分配的ip 23为设置的静态ip # # #
root@rong-virtual-machine:~# hostname -I
192.168.137.155 192.168.137.23
# # # ping外网ip # # #
root@rong-virtual-machine:~# 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=100 time=70.1 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=100 time=76.1 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=100 time=70.9 ms
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 70.093/72.364/76.065/2.639 ms
# # # ping百度域名 # # #
root@rong-virtual-machine:~# ping www.baidu.com
PING www.a.shifen.com (120.232.145.185) 56(84) bytes of data.
64 bytes from 120.232.145.185 (120.232.145.185): icmp_seq=1 ttl=51 time=10.3 ms
64 bytes from 120.232.145.185 (120.232.145.185): icmp_seq=2 ttl=51 time=13.4 ms
64 bytes from 120.232.145.185 (120.232.145.185): icmp_seq=3 ttl=51 time=11.6 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 9272ms
rtt min/avg/max/mdev = 10.289/11.751/13.409/1.281 ms

😨 😨 😨 居然没问题 😨 😨 😨

自测(插回电脑网口)

怀疑是电脑网口坏了,折腾了两天都不行,换到拓展坞的网口上,吃了个饭回来就好了😢 😢 😢
简介中的图片所示的以太网 2即拓展坞网口
更改为电脑上的以太网
在这里插入图片描述
重启开发板

root@rong-virtual-machine:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.137.207  netmask 255.255.255.0  broadcast 192.168.137.255ether 00:22:33:44:55:66  txqueuelen 1000  (Ethernet)RX packets 93  bytes 14302 (14.3 KB)RX errors 0  dropped 13  overruns 0  frame 0TX packets 81  bytes 8422 (8.4 KB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0device interrupt 87  base 0x2000lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0loop  txqueuelen 1000  (Local Loopback)RX packets 184  bytes 14969 (14.9 KB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 184  bytes 14969 (14.9 KB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0root@rong-virtual-machine:~# hostname -I
192.168.137.207
root@rong-virtual-machine:~# 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=100 time=71.7 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=100 time=71.0 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=100 time=76.4 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=100 time=71.9 ms
^C
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 71.020/72.746/76.352/2.108 ms
root@rong-virtual-machine:~# ping www.baidu.com
PING www.a.shifen.com (120.232.145.144) 56(84) bytes of data.
64 bytes from 120.232.145.144: icmp_seq=1 ttl=51 time=13.6 ms
64 bytes from 120.232.145.144: icmp_seq=2 ttl=51 time=14.1 ms
64 bytes from 120.232.145.144: icmp_seq=3 ttl=51 time=12.1 ms
64 bytes from 120.232.145.144: icmp_seq=4 ttl=51 time=11.6 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 12028ms
rtt min/avg/max/mdev = 11.586/12.857/14.089/1.029 ms

其中

root@rong-virtual-machine:~# hostname -I
192.168.137.207

只显示一个ip了,netplan配置文件中的静态ip没了

无静态ip

尝试执行netplan apply,静态ip生效,但是另一个又变回之前的155了 😳 😳 😳

root@rong-virtual-machine:~# netplan apply
root@rong-virtual-machine:~# hostname -I
192.168.137.155 192.168.137.23

老天爷 为什么 😭 😭 😭
what can I say!!

再次reboot

再次重启开发板

root@rong-virtual-machine:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.137.155  netmask 255.255.255.0  broadcast 192.168.137.255ether 00:22:33:44:55:66  txqueuelen 1000  (Ethernet)RX packets 96  bytes 14248 (14.2 KB)RX errors 0  dropped 12  overruns 0  frame 0TX packets 90  bytes 9701 (9.7 KB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0device interrupt 87  base 0x2000lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0loop  txqueuelen 1000  (Local Loopback)RX packets 184  bytes 15321 (15.3 KB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 184  bytes 15321 (15.3 KB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0root@rong-virtual-machine:~# hostname -I
192.168.137.155 192.168.137.200 192.168.137.23

出现了3个ip
执行netplan apply

root@rong-virtual-machine:~# netplan apply
root@rong-virtual-machine:~# hostname -I
192.168.137.155 192.168.137.23
root@rong-virtual-machine:~#

无敌了。兄弟 😮 😮 😮

开发板断电

root@rong-virtual-machine:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 192.168.137.155  netmask 255.255.255.0  broadcast 192.168.137.255ether 00:22:33:44:55:66  txqueuelen 1000  (Ethernet)RX packets 167  bytes 23894 (23.8 KB)RX errors 0  dropped 11  overruns 0  frame 0TX packets 156  bytes 15179 (15.1 KB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0device interrupt 87  base 0x2000lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0loop  txqueuelen 1000  (Local Loopback)RX packets 38  bytes 3871 (3.8 KB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 38  bytes 3871 (3.8 KB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0root@rong-virtual-machine:~# hostname -I
192.168.137.155 192.168.137.71 192.168.137.23
root@rong-virtual-machine:~# netplan apply
root@rong-virtual-machine:~# hostname -I
192.168.137.155 192.168.137.23

搞不懂了 😦 😦 😦

可以上网

root@rong-virtual-machine:~# wget zhihu.com
--2024-04-24 21:21:36--  http://zhihu.com/
Resolving zhihu.com (zhihu.com)... 103.41.167.234
Connecting to zhihu.com (zhihu.com)|103.41.167.234|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://www.zhihu.com/ [following]
--2024-04-24 21:21:36--  https://www.zhihu.com/
Resolving www.zhihu.com (www.zhihu.com)... 120.240.101.173, 111.45.69.246, 183.240.47.143, ...
Connecting to www.zhihu.com (www.zhihu.com)|120.240.101.173|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: //www.zhihu.com/signin?next=%2F [following]
--2024-04-24 21:21:36--  https://www.zhihu.com/signin?next=%2F
Reusing existing connection to www.zhihu.com:443.
HTTP request sent, awaiting response... 200 OK
Length: 40094 (39K) [text/html]
Saving to: ‘index.html’index.html          100%[===================>]  39.15K  --.-KB/s    in 0.1s2024-04-24 21:21:37 (271 KB/s) - ‘index.html’ saved [40094/40094]

断电后拔插网线

这篇关于开发板通过网线连接电脑而上网的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/933058

相关文章

电脑找不到mfc90u.dll文件怎么办? 系统报错mfc90u.dll丢失修复的5种方案

《电脑找不到mfc90u.dll文件怎么办?系统报错mfc90u.dll丢失修复的5种方案》在我们日常使用电脑的过程中,可能会遇到一些软件或系统错误,其中之一就是mfc90u.dll丢失,那么,mf... 在大部分情况下出现我们运行或安装软件,游戏出现提示丢失某些DLL文件或OCX文件的原因可能是原始安装包

电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案

《电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案》最近有不少兄弟反映,电脑突然弹出“mfc100u.dll已加载,但找不到入口点”的错误提示,导致一些程序无法正... 在计算机使用过程中,我们经常会遇到一些错误提示,其中最常见的就是“找不到指定的模块”或“缺少某个DL

MySQL 多表连接操作方法(INNER JOIN、LEFT JOIN、RIGHT JOIN、FULL OUTER JOIN)

《MySQL多表连接操作方法(INNERJOIN、LEFTJOIN、RIGHTJOIN、FULLOUTERJOIN)》多表连接是一种将两个或多个表中的数据组合在一起的SQL操作,通过连接,... 目录一、 什么是多表连接?二、 mysql 支持的连接类型三、 多表连接的语法四、实战示例 数据准备五、连接的性

MySQL中的分组和多表连接详解

《MySQL中的分组和多表连接详解》:本文主要介绍MySQL中的分组和多表连接的相关操作,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录mysql中的分组和多表连接一、MySQL的分组(group javascriptby )二、多表连接(表连接会产生大量的数据垃圾)MySQL中的

电脑死机无反应怎么强制重启? 一文读懂方法及注意事项

《电脑死机无反应怎么强制重启?一文读懂方法及注意事项》在日常使用电脑的过程中,我们难免会遇到电脑无法正常启动的情况,本文将详细介绍几种常见的电脑强制开机方法,并探讨在强制开机后应注意的事项,以及如何... 在日常生活和工作中,我们经常会遇到电脑突然无反应的情况,这时候强制重启就成了解决问题的“救命稻草”。那

MySQL中的交叉连接、自然连接和内连接查询详解

《MySQL中的交叉连接、自然连接和内连接查询详解》:本文主要介绍MySQL中的交叉连接、自然连接和内连接查询,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、引入二、交php叉连接(cross join)三、自然连接(naturalandroid join)四

python连接本地SQL server详细图文教程

《python连接本地SQLserver详细图文教程》在数据分析领域,经常需要从数据库中获取数据进行分析和处理,下面:本文主要介绍python连接本地SQLserver的相关资料,文中通过代码... 目录一.设置本地账号1.新建用户2.开启双重验证3,开启TCP/IP本地服务二js.python连接实例1.

Ubuntu中远程连接Mysql数据库的详细图文教程

《Ubuntu中远程连接Mysql数据库的详细图文教程》Ubuntu是一个以桌面应用为主的Linux发行版操作系统,这篇文章主要为大家详细介绍了Ubuntu中远程连接Mysql数据库的详细图文教程,有... 目录1、版本2、检查有没有mysql2.1 查询是否安装了Mysql包2.2 查看Mysql版本2.

Python3.6连接MySQL的详细步骤

《Python3.6连接MySQL的详细步骤》在现代Web开发和数据处理中,Python与数据库的交互是必不可少的一部分,MySQL作为最流行的开源关系型数据库管理系统之一,与Python的结合可以实... 目录环境准备安装python 3.6安装mysql安装pymysql库连接到MySQL建立连接执行S

Spring Boot 整合 MyBatis 连接数据库及常见问题

《SpringBoot整合MyBatis连接数据库及常见问题》MyBatis是一个优秀的持久层框架,支持定制化SQL、存储过程以及高级映射,下面详细介绍如何在SpringBoot项目中整合My... 目录一、基本配置1. 添加依赖2. 配置数据库连接二、项目结构三、核心组件实现(示例)1. 实体类2. Ma