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

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

相关文章

Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式

《Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式》本文详细介绍如何使用Java通过JDBC连接MySQL数据库,包括下载驱动、配置Eclipse环境、检测数据库连接等关键步骤,... 目录一、下载驱动包二、放jar包三、检测数据库连接JavaJava 如何使用 JDBC 连接 mys

Qt使用QSqlDatabase连接MySQL实现增删改查功能

《Qt使用QSqlDatabase连接MySQL实现增删改查功能》这篇文章主要为大家详细介绍了Qt如何使用QSqlDatabase连接MySQL实现增删改查功能,文中的示例代码讲解详细,感兴趣的小伙伴... 目录一、创建数据表二、连接mysql数据库三、封装成一个完整的轻量级 ORM 风格类3.1 表结构

MySQL中的表连接原理分析

《MySQL中的表连接原理分析》:本文主要介绍MySQL中的表连接原理分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、背景2、环境3、表连接原理【1】驱动表和被驱动表【2】内连接【3】外连接【4编程】嵌套循环连接【5】join buffer4、总结1、背景

SpringBoot连接Redis集群教程

《SpringBoot连接Redis集群教程》:本文主要介绍SpringBoot连接Redis集群教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 依赖2. 修改配置文件3. 创建RedisClusterConfig4. 测试总结1. 依赖 <de

qt5cored.dll报错怎么解决? 电脑qt5cored.dll文件丢失修复技巧

《qt5cored.dll报错怎么解决?电脑qt5cored.dll文件丢失修复技巧》在进行软件安装或运行程序时,有时会遇到由于找不到qt5core.dll,无法继续执行代码,这个问题可能是由于该文... 遇到qt5cored.dll文件错误时,可能会导致基于 Qt 开发的应用程序无法正常运行或启动。这种错

电脑提示xlstat4.dll丢失怎么修复? xlstat4.dll文件丢失处理办法

《电脑提示xlstat4.dll丢失怎么修复?xlstat4.dll文件丢失处理办法》长时间使用电脑,大家多少都会遇到类似dll文件丢失的情况,不过,解决这一问题其实并不复杂,下面我们就来看看xls... 在Windows操作系统中,xlstat4.dll是一个重要的动态链接库文件,通常用于支持各种应用程序

java连接opcua的常见问题及解决方法

《java连接opcua的常见问题及解决方法》本文将使用EclipseMilo作为示例库,演示如何在Java中使用匿名、用户名密码以及证书加密三种方式连接到OPCUA服务器,若需要使用其他SDK,原理... 目录一、前言二、准备工作三、匿名方式连接3.1 匿名方式简介3.2 示例代码四、用户名密码方式连接4

MySQL 表的内外连接案例详解

《MySQL表的内外连接案例详解》本文给大家介绍MySQL表的内外连接,结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录表的内外连接(重点)内连接外连接表的内外连接(重点)内连接内连接实际上就是利用where子句对两种表形成的笛卡儿积进行筛选,我

Apache 高级配置实战之从连接保持到日志分析的完整指南

《Apache高级配置实战之从连接保持到日志分析的完整指南》本文带你从连接保持优化开始,一路走到访问控制和日志管理,最后用AWStats来分析网站数据,对Apache配置日志分析相关知识感兴趣的朋友... 目录Apache 高级配置实战:从连接保持到日志分析的完整指南前言 一、Apache 连接保持 - 性

电脑蓝牙连不上怎么办? 5 招教你轻松修复Mac蓝牙连接问题的技巧

《电脑蓝牙连不上怎么办?5招教你轻松修复Mac蓝牙连接问题的技巧》蓝牙连接问题是一些Mac用户经常遇到的常见问题之一,在本文章中,我们将提供一些有用的提示和技巧,帮助您解决可能出现的蓝牙连接问... 蓝牙作为一种流行的无线技术,已经成为我们连接各种设备的重要工具。在 MAC 上,你可以根据自己的需求,轻松地