1. Wsl启动后
1)Windows下ip
ipconfig
以太网适配器 vEthernet (WSL (Hyper-V firewall)):
连接特定的 DNS 后缀 . . . . . . . :
IPv4 地址 . . . . . . . . . . . . : 172.19.32.1
子网掩码 . . . . . . . . . . . . : 255.255.240.0
默认网关. . . . . . . . . . . . . :
该虚拟网卡在网络邻居里是看不到的。
ping 172.19.32.1
正在 Ping 172.19.32.1 具有 32 字节的数据:
来自 172.19.32.1 的回复: 字节=32 时间<1ms TTL=128
来自 172.19.32.1 的回复: 字节=32 时间<1ms TTL=128
来自 172.19.32.1 的回复: 字节=32 时间<1ms TTL=128
来自 172.19.32.1 的回复: 字节=32 时间<1ms TTL=128
2)Ubuntu下ip
ip addr show eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.19.37.221 netmask 255.255.240.0 broadcast 172.19.47.255
RX packets 56 bytes 10337 (10.3 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 18 bytes 1256 (1.2 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ping 172.19.32.1
PING 172.19.32.1 (172.19.32.1) 56(84) bytes of data.
64 bytes from 172.19.32.1: icmp_seq=1 ttl=128 time=0.330 ms
64 bytes from 172.19.32.1: icmp_seq=2 ttl=128 time=0.298 ms
64 bytes from 172.19.32.1: icmp_seq=3 ttl=128 time=0.383 ms
64 bytes from 172.19.32.1: icmp_seq=4 ttl=128 time=0.351 ms
64 bytes from 172.19.32.1: icmp_seq=5 ttl=128 time=0.286 ms
2. 分析
1)把WSL的虚拟交换机桥接到物理网卡上
WSL的虚拟交换机连接到物理网卡
在windows搜索框中搜索“Hyper-V 管理器 ”,点击虚拟交换机,把内部网络改为外部网络。
ubuntuIP_47">2)ubuntu设置静态IP
#!/bin/bash
# 清空现有 IP 配置
sudo ip addr flush dev eth0
# 设置静态 IP 和子网掩码
sudo ip addr add 192.168.32.100/24 dev eth0
# 设置默认网关(通常为路由器 IP)
sudo ip route add default via 192.168.32.1
保存并退出(Ctrl+O
→ Enter
→ Ctrl+X
)。
步骤 2:赋予脚本执行权限
sudo chmod +x /usr/local/bin/set_static_ip.sh
步骤 3:设置脚本开机自动运行
编辑 ~/.bashrc
或全局配置文件 /etc/profile
:
echo "/usr/local/bin/set_static_ip.sh" >> ~/.bashrc
步骤 4:立即执行脚本
source ~/.bashrc
4. 验证静态 IP
ip addr show eth0 | grep "inet "
# 应输出类似:inet 192.168.32.100/24 scope global eth0
以下脚本待测试
# 创建脚本
sudo tee /usr/local/bin/set_static_ip.sh << 'EOF'
#!/bin/bash
sudo ip addr flush dev eth0
sudo ip addr add 192.168.32.100/24 dev eth0
sudo ip route add default via 192.168.32.1
EOF
# 设置权限并添加到启动项
sudo chmod +x /usr/local/bin/set_static_ip.sh
echo "/usr/local/bin/set_static_ip.sh" >> ~/.bashrc
# 立即生效
source ~/.bashrc
3. Ubuntu搭建tftp服务器
tftp 命令的作用和 nfs 命令一样,都是用于通过网络下载东西到 DRAM 中,只是 tftp 命令使用的 TFTP 协议, Ubuntu 主机作为 TFTP 服务器。因此需要在 Ubuntu 上搭建 TFTP 服务器,需要安装 tftp-hpa 和 tftpd-hpa,命令如下
sudo apt-get install tftp-hpa tftpd-hpa
sudo apt-get install xinetd
和 NFS 一样, TFTP 也需要一个文件夹来存放文件,在用户目录下新建一个目录,/home/xxx/tftp ,xxx为用户名,命令如下
mkdir tftp
chmod 777 tftp
新建文件夹/etc/xinetd.d,
sudo mkdir /etc/xinetd.d
新建文件/etc/xinetd.d/tftp
sudo vi /etc/xinetd.d/tftp
server tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /home/xxx/tftp/
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
:wq保存退出,:q仅退出
完了以后启动 tftp 服务,命令如下:
sudo service tftpd-hpa start
打开/etc/default/tftpd-hpa 文件 ,修改
sudo vi /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/xxx/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="-l -c -s"
TFTP_DIRECTORY 就是我们上面创建的 tftp 文件夹目录,以后我们就将所有需要通过TFTP 传输的文件都放到这个文件夹里面,并且要给予这些文件相应的权限。
最后输入如下命令, 重启 tftp 服务器:
sudo service tftpd-hpa restart
tftp 服务器已经搭建好了,接下来就是使用了。将 zImage 镜像文件拷贝到 tftp文件夹中,并且给予 zImage 相应的权限,命令如下:
cp zImage /home/xxx/tftp/
cd /home/xxx/tftp/
chmod 777 zImage
4. uboot设置ip
修改环境变量
setenv ipaddr 192.168.32.50
setenv ethaddr 00:04:9f:04:d2:35
setenv gatewayip 192.168.32.1
setenv netmask 255.255.255.0
setenv serverip 192.168.32.100
saveenv
查看环境变量
print
只能在 uboot 中 ping 其他的机器,其他机器不能 ping uboot,因为 uboot 没有对 ping命令做处理,如果用其他的机器 ping uboot 的话会失败!
=> ping 192.168.32.100
Using FEC1 device
host 192.168.32.100 is alive
5. Uboot中通过tftp下载镜像
tftp 命令不需要输入文件在 Ubuntu 中的完整路径,只需要输入文件名即可。比如我们现在将 tftp文件夹里面的 zImage 文件下载到开发板 DRAM 的 0X80800000 地址处,命令如下
tftp 80800000 zImage