本文主要是介绍开发板通过网线连接电脑而上网,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
简介
关闭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]
断电后拔插网线
这篇关于开发板通过网线连接电脑而上网的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!