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
相关推荐
RisunJan8 分钟前
Linux命令-readonly(Bash 内建设置只读变量)
linux
techdashen31 分钟前
从网络栈继续往下:micro:bit、2.4GHz、调制方式,以及一个不太靠谱但很有趣的想法
网络·fpga开发
碎碎念_49240 分钟前
网络通信基础:IP协议、ARP协议、DHCP
网络·arp·dhcp·ip协议
Geeys1 小时前
淘宝电商运营新手入门完整教程|零基础开店引流
大数据·网络·人工智能
TTBIGDATA1 小时前
【Ambari Plus】10.HBase 安装
大数据·运维·hadoop·ambari·hdp·cdh·bigtop
FlightYe1 小时前
FFmpeg移动端硬解机制
linux·网络·ffmpeg·音视频·实时音视频·视频编解码
笨笨没好名字2 小时前
Leetcode刷题python3版第一周(下)
linux·算法·leetcode
艾伦_耶格宇2 小时前
【ELK】-2 ELK的搭建
运维·elk
huainingning2 小时前
锐捷ACL单向TCP互通组网-通过Established状态回包实现
服务器·网络·tcp/ip
xcLeigh2 小时前
KES运维自动化与脚本体系实战
运维·数据库·自动化·脚本·数据迁移·kes