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
相关推荐
未济4 天前
linux 配置环境变量
linux
傲世仙尊4 天前
目录即文件-Ext文件系统收尾篇
linux·c语言
虎头金猫4 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
_艾伦 耶格尔.4 天前
进程间通信
linux
AI职业加油站4 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
Liuqy-054 天前
Linux IO编程——静态库、动态库
linux
wuyk5554 天前
《WiFi 嵌入式物联网开发全套实战》| 第 16 章 ESP32 AP+STA 双模共存原理与工程坑点
网络·stm32·物联网
此冬歌咏4 天前
K8s 节点故障实战:优雅驱逐 31 秒,硬故障 331 秒,以及那个永远 Pending 的 Pod
运维·k8s
彧azz4 天前
Linux 环境下 Redis 学习总结:数据类型、持久化、锁、事务、主从与缓存问题
linux·redis·笔记·学习·面试
-梅4 天前
linux(8) 软硬链接
linux·运维·服务器