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

相关推荐
rqtz1 小时前
【Linux-shell】探索Dialog 工具在 Shell 图形化编程中的高效范式重构
linux·运维·重构
行止62 小时前
LVS+Keepalived高可用群集
linux·lvs·keepalived
风好衣轻2 小时前
【环境配置】在Ubuntu Server上安装5090 PyTorch环境
linux·pytorch·ubuntu
华清远见成都中心3 小时前
Linux嵌入式和单片机嵌入式的区别?
linux·运维·单片机·嵌入式
ldinvicible3 小时前
基于ARM ubuntu如何进行交叉编译
arm开发·数据库·ubuntu
lisanmengmeng3 小时前
rabbitMQ 高可用
linux·分布式·rabbitmq
小妖6664 小时前
ubuntu 22.04 更换阿里源 (wsl2 参照)
linux·运维·ubuntu
凉、介4 小时前
SylixOS 下的消息队列
linux·wpf·sylixos
egoist20234 小时前
【Linux仓库】进程概念与基本操作【进程·贰】
linux·运维·服务器·指令·进程操作·理解进程
dessler4 小时前
ZooKeeper-监控(Monitor)
linux·运维·zookeeper