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 啦。。。。

相关推荐
Apipi*3 小时前
30天速通Linux 第六章信号及信号处理
linux·运维·信号处理
天启HTTP4 小时前
爬虫防封核心原理:IP轮换机制与风控规避逻辑
linux·服务器·网络·爬虫·tcp/ip
广州浮点FLOATLIC7 小时前
许可证服务器迁移后软件打不开:研发 IT 怎样定位连接问题
linux·服务器·数据库
BLUcoding7 小时前
接口服务公网超时排查记录:SecureRandom 阻塞问题分析与解决
java·linux·springboot·aes·securerandom
AIgorithmGEEK7 小时前
[Linux]从手写报头到内核套路:序列化、反序列化与自定义协议全链路
linux·运维·服务器·网络·序列化·反序列化
Nil2087 小时前
leetcode 139单词拆分
linux·运维·服务器
Starry-sky(jing)7 小时前
BUG: unable to handle kernel paging request 完整排查:dmesg 四要素与三路定罪
linux·运维·服务器·内核·排障
mounter6257 小时前
从硬件互连到操作系统变革:CXL 技术演进与 Linux 内核工程挑战
linux·运维·服务器
xh didida9 小时前
Linux -- 基础IO
linux·服务器·开发语言·c++
zly350010 小时前
centos7 mount设备挂载 /dev/sda1/硬盘挂载
linux·运维·服务器