wsl2 配置ubuntu 固定ip

提示:环境搭建

文章目录

  • 前言
  • [一、安装sshd 服务](#一、安装sshd 服务)
    • [1. ubuntu 子系统安装 openssh-server](#1. ubuntu 子系统安装 openssh-server)
    • [2.配置sshd 开启密码链接](#2.配置sshd 开启密码链接)
    • [3.配置sshd 服务开机启动](#3.配置sshd 服务开机启动)
  • 二、配置固定IP
    • [1 查看i](#1 查看i)
    • [2 查看路由](#2 查看路由)
    • [3 查看wsl虚拟网卡](#3 查看wsl虚拟网卡)
    • [4 配置wsl 子系统网卡](#4 配置wsl 子系统网卡)
    • [4 设置生效](#4 设置生效)
  • 三、问题
    • [1. ssh 无法远程](#1. ssh 无法远程)

前言

提示:版本
主机 :win11
子系统:Ubuntu 24.04.2 LTS


提示:以下是本篇文章正文内容,下面案例可供参考

一、安装sshd 服务

1. ubuntu 子系统安装 openssh-server

代码如下(示例):

c 复制代码
apt install openssh-server -y

2.配置sshd 开启密码链接

代码如下(示例):

bash 复制代码
vim  /etc/ssh/sshd_config
bash 复制代码
# 去掉注释,改为yes
PasswordAuthentication yes

3.配置sshd 服务开机启动

bash 复制代码
systemctl enable ssh
systemctl restart ssh

二、配置固定IP

1 查看i

bash 复制代码
(base) root@DESKTOP-2AP8ULH:~# hostname -I
172.29.116.82

2 查看路由

bash 复制代码
(base) root@DESKTOP-2AP8ULH:~# ip route
default via 172.29.112.1 dev eth0 proto kernel
default via 172.29.112.1 dev eth0 proto static
172.29.112.0/20 dev eth0 proto kernel scope link src 172.29.116.82

3 查看wsl虚拟网卡

bash 复制代码
ipconfig /all

还是 管理员 powershell 中

bash 复制代码
New-NetIPAddress -IPAddress 172.29.116.82 -PrefixLength 20 -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))"

4 配置wsl 子系统网卡

编辑网卡

bash 复制代码
vim /etc/netplan/01-netcfg.yaml
bash 复制代码
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: no
      addresses: [172.29.116.82/20]
      routes:
        - to: default
          via: 172.29.112.1
          metric: 100   
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

4 设置生效

bash 复制代码
netplan apply

重启子系统验证是否生效

wsl shutdown


三、问题

1. ssh 无法远程

权限拒绝,拒绝访问

bash 复制代码
ssh user@localhost
Permission denied

sshd 日志

bash 复制代码
pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0>
Failed password for root from 127.0.0.1 port 52556 ssh2
pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0>
Failed password for root from 172.29.112.1 port 51702 ssh2

检查 /etc/ssh/sshd_config 配置项

bash 复制代码
PermitRootLogin yes
PasswordAuthentication yes

ok 啦。。。。

相关推荐
Nebula嵌入式15 分钟前
【C语言】09-深入解析main函数
linux·c语言·开发语言·嵌入式
Dxy12393102161 小时前
Linux 编译安装 Python 3.12.10(多版本共存,不破坏系统Python)
linux·运维·python
黑桃小柒72 小时前
小,最终显示为TCP WINDOW FULL,TCP ZeroWindow。 仔细分析了下LWIP源码,还以为是内存管理出了问题,跟 ...
网络·网络协议·tcp/ip
xz驱动分享3 小时前
Linux DMA 子系统学习笔记
linux·dma·rk3588·嵌入式软件
w67820074 小时前
Prisma不能优雅的支持DTO,试试Vona ORM吧
linux·运维·ubuntu
Darkwanderor4 小时前
Linux系统编程实战项目:模拟实现shell
linux·c++
杨某不才6 小时前
如何能让Linux服务器对shell 终端 + sftp 文件传输长期保活
linux·运维·服务器
vance046 小时前
免费Cloudflare隧道隐藏公网IP
linux·tcp/ip·github
三言老师7 小时前
文本工具组合统计服务器日志数据
linux·运维·服务器
mounter6257 小时前
认识 Tetragon:基于 eBPF 的安全监控与强制执行工具
linux·ebpf·cve·kernel