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
相关推荐
头疼的程序员1 分钟前
计算机网络:自顶向下方法(第七版)第八章 学习分享(三)
网络·学习·计算机网络
C++ 老炮儿的技术栈2 分钟前
GCC编译时无法向/tmp 目录写入临时汇编文件,因为设备空间不足,解决
linux·运维·开发语言·汇编·c++·git·qt
@insist12313 分钟前
网络工程师-核心考点:网络管理体系与 SNMP 协议全解析
网络·智能路由器·网络工程师·软考·软件水平考试
Agent产品评测局14 分钟前
企业数据处理自动化落地,抓取分析全流程实现方案 —— 2026企业级智能体选型与技术路径深度解析
运维·人工智能·ai·自动化
爱莉希雅&&&38 分钟前
linux中MySQL数据库备份恢复的四种方法(更新中)
linux·数据库·mysql·数据库备份·mysqldumper
我科绝伦(Huanhuan Zhou)1 小时前
分享一个网络智能运维系统
运维·网络
codeejun1 小时前
每日一Go-44、Go网络栈深度拆解--从 TCP 到 HTTP 的资源复用艺术
网络·tcp/ip·golang
鬼先生_sir1 小时前
Spring Cloud 微服务监控实战:SkyWalking + Prometheus+Grafana 全栈解决方案
运维·spring cloud·grafana·prometheus·skywalking
信创DevOps先锋1 小时前
DevOps工具链选型新趋势:本土化适配与安全可控成企业核心诉求
运维·安全·devops
藤谷性能1 小时前
Ubuntu 22.04:安装SEGGER Embedded Studio
ubuntu·nrf52832·ses·embedded studio