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

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

相关文章

sysmain服务可以禁用吗? 电脑sysmain服务关闭后的影响与操作指南

《sysmain服务可以禁用吗?电脑sysmain服务关闭后的影响与操作指南》在Windows系统中,SysMain服务(原名Superfetch)作为一个旨在提升系统性能的关键组件,一直备受用户关... 在使用 Windows 系统时,有时候真有点像在「开盲盒」。全新安装系统后的「默认设置」,往往并不尽编

Mac电脑如何通过 IntelliJ IDEA 远程连接 MySQL

《Mac电脑如何通过IntelliJIDEA远程连接MySQL》本文详解Mac通过IntelliJIDEA远程连接MySQL的步骤,本文通过图文并茂的形式给大家介绍的非常详细,感兴趣的朋友跟... 目录MAC电脑通过 IntelliJ IDEA 远程连接 mysql 的详细教程一、前缀条件确认二、打开 ID

Go语言连接MySQL数据库执行基本的增删改查

《Go语言连接MySQL数据库执行基本的增删改查》在后端开发中,MySQL是最常用的关系型数据库之一,本文主要为大家详细介绍了如何使用Go连接MySQL数据库并执行基本的增删改查吧... 目录Go语言连接mysql数据库准备工作安装 MySQL 驱动代码实现运行结果注意事项Go语言执行基本的增删改查准备工作

python连接sqlite3简单用法完整例子

《python连接sqlite3简单用法完整例子》SQLite3是一个内置的Python模块,可以通过Python的标准库轻松地使用,无需进行额外安装和配置,:本文主要介绍python连接sqli... 目录1. 连接到数据库2. 创建游标对象3. 创建表4. 插入数据5. 查询数据6. 更新数据7. 删除

在 Spring Boot 中连接 MySQL 数据库的详细步骤

《在SpringBoot中连接MySQL数据库的详细步骤》本文介绍了SpringBoot连接MySQL数据库的流程,添加依赖、配置连接信息、创建实体类与仓库接口,通过自动配置实现数据库操作,... 目录一、添加依赖二、配置数据库连接三、创建实体类四、创建仓库接口五、创建服务类六、创建控制器七、运行应用程序八

解决hive启动时java.net.ConnectException:拒绝连接的问题

《解决hive启动时java.net.ConnectException:拒绝连接的问题》Hadoop集群连接被拒,需检查集群是否启动、关闭防火墙/SELinux、确认安全模式退出,若问题仍存,查看日志... 目录错误发生原因解决方式1.关闭防火墙2.关闭selinux3.启动集群4.检查集群是否正常启动5.

在Linux系统上连接GitHub的方法步骤(适用2025年)

《在Linux系统上连接GitHub的方法步骤(适用2025年)》在2025年,使用Linux系统连接GitHub的推荐方式是通过SSH(SecureShell)协议进行身份验证,这种方式不仅安全,还... 目录步骤一:检查并安装 Git步骤二:生成 SSH 密钥步骤三:将 SSH 公钥添加到 github

Redis客户端连接机制的实现方案

《Redis客户端连接机制的实现方案》本文主要介绍了Redis客户端连接机制的实现方案,包括事件驱动模型、非阻塞I/O处理、连接池应用及配置优化,具有一定的参考价值,感兴趣的可以了解一下... 目录1. Redis连接模型概述2. 连接建立过程详解2.1 连php接初始化流程2.2 关键配置参数3. 最大连

电脑提示d3dx11_43.dll缺失怎么办? DLL文件丢失的多种修复教程

《电脑提示d3dx11_43.dll缺失怎么办?DLL文件丢失的多种修复教程》在使用电脑玩游戏或运行某些图形处理软件时,有时会遇到系统提示“d3dx11_43.dll缺失”的错误,下面我们就来分享超... 在计算机使用过程中,我们可能会遇到一些错误提示,其中之一就是缺失某个dll文件。其中,d3dx11_4

C#连接SQL server数据库命令的基本步骤

《C#连接SQLserver数据库命令的基本步骤》文章讲解了连接SQLServer数据库的步骤,包括引入命名空间、构建连接字符串、使用SqlConnection和SqlCommand执行SQL操作,... 目录建议配合使用:如何下载和安装SQL server数据库-CSDN博客1. 引入必要的命名空间2.