ubuntu22.04.5配置ip并使用远程工具连接

本帖主要记录下ubuntu系统的ip配置,以及如何使用工具连接

用惯了redhat系列的小斌几乎没用过ubuntu,今天收到需求要在ubuntu上部署服务。结果配个IP搞了十几分钟,网上的文章太多,看得我都迷糊了,弄完一重启,ip又消失了,王德发!所以这里做记录。

操作系统是ubuntu22.04.5

配置ip

1.先备份

复制代码
sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak

2.编辑(注意缩进只能用空格)

复制代码
vim /etc/netplan/50-cloud-init.yaml

写入以下内容

复制代码
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
  version: 2
  ethernets:
    ens33:
      dhcp4: no
      addresses: [192.168.44.56/16]
      gateway4: 192.168.255.1
      nameservers:
        addresses: [114.114.114.114, 8.8.8.8]

3.检查语法并生效

复制代码
sudo netplan try

中间需要按个回车

4.验证

复制代码
ip -4 a show ens33

5.重点,不然重启后ip会丢失

复制代码
sudo touch /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

vim  /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg  

编辑文件并写入

复制代码
network: {config: disabled}

这样重启后ip就不会消失了

配置ssh远程连接

Ubuntu 22.04 默认禁止 root 密码登录,安装时就没让你设 root 密码。我们需要普通用户登录,然后切换到root用户

紧接着给root用户设置密码

复制代码
sudo passwd root       # 给 root 重设密码

设完密码后,默认仍不许 SSH 用 root 登,需要再改 SSH 配置:

复制代码
vim   /etc/ssh/sshd_config

找到并改成

复制代码
PermitRootLogin yes

保存后

复制代码
sudo systemctl restart ssh
相关推荐
Leinwin3 小时前
OpenClaw 多 Agent 协作框架的并发限制与企业化规避方案痛点直击
java·运维·数据库
2401_865382503 小时前
信息化项目运维与运营的区别
运维·运营·信息化项目·政务信息化
漠北的哈士奇3 小时前
VMware Workstation导入ova文件时出现闪退但是没有报错信息
运维·vmware·虚拟机·闪退·ova
如意.7594 小时前
【Linux开发工具实战】Git、GDB与CGDB从入门到精通
linux·运维·git
Thera7774 小时前
C++ 高性能时间轮定时器:从单例设计到 Linux timerfd 深度优化
linux·开发语言·c++
运维小欣4 小时前
智能体选型实战指南
运维·人工智能
yy55274 小时前
Nginx 性能优化与监控
运维·nginx·性能优化
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ5 小时前
Linux 查询某进程文件所在路径 命令
linux·运维·服务器
05大叔7 小时前
网络基础知识 域名,JSON格式,AI基础
运维·服务器·网络
安当加密7 小时前
无需改 PAM!轻量级 RADIUS + ASP身份认证系统 实现 Linux 登录双因子认证
linux·运维·服务器