ubuntu 22.04版本修改服务器名、ip,dns信息的操作方法

总结
1、ubuntu修改服务器名重启后生效的方法是直接修改/etc/hostname文件

2、ubuntu 22.04操作系统配置ip和dns信息,一般只需要使用netplan命令行工具来配置就行,在/etc/netplan/在目录下创建一个yaml文件就可以实现ip和dns的配置,当然如果/etc/netplan下有多个yaml文件,则所有/etc/netplan/*.yaml文件都将被netplan命令行使用,参见官方文档https://ubuntu.com/server/docs/network-configuration和https://manpages.ubuntu.com/manpages/jammy/man5/netplan.5.html

3、个人不建议使用/etc/resolve.conf来配置ubuntu 22.04操作系统的dns信息,因为太复杂了,这个文件是被systemd-resolved服务托管。ubuntu操作系统/etc/resolve.conf中默认使用的是 nameserver 127.0.0.53回环地址,/etc/resolve.conf文中有这么一句话This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8). Do not edit。说明这个文件是被systemd-resolved这个服务托管的。通过 netstat -tnpl| grep systemd-resolved 查看到这个服务是监听在 53 号端口上。为啥要用127.0.0.53作为回环地址而不是127.0.0.1,因为127网段都是回环地址(127.0.0.1 - 127.255.255.254),不过通常用大家只喜欢用127.0.0.1来表示而已,53表示dns端口
3.1、新安装的ubuntu 22.04环境不做其他改动的情况下,/etc/resolv.conf是/run/systemd/resolve/stub-resolv.conf的软链接,如果只是手工更改/etc/resolv.conf中的内容,重启会后发现/etc/resolv.conf中的内容又恢复成原样了,比如注释/etc/resolv.conf文件中的nameserver 127.0.0.53这一行,重启系统后被注释掉的nameserver 127.0.0.53这一行又回来了,如果不想重启后/etc/resolv.conf中的内容恢复成原样,则执行systemctl stop systemd-resolved和systemctl disable systemd-resolved,或把/etc/resolv.conf对应的软链接删除,再手工建立一个/etc/resolv.conf
3.2、使用/etc/netplan/00-installer-config.yaml配置DNS 172.22.10.66并执行netplan apply使之生效,再修改/etc/systemd/resolved.conf内容里的DNS为172.22.136.2,然后执行systemctl restart systemd-resolved,发现/etc/resolv.conf中的内容没变还是127.0.0.53,再执行resolvectl status可以看到/etc/systemd/resolved.conf中的DNS 172.22.136.2存在,/etc/netplan/00-installer-config.yaml中的DNS 172.22.10.66也在,就是没有/etc/resolv.conf中的127.0.0.53。重启操作系统后/etc/resolv.conf中的内容没变还是127.0.0.53,重启操作系统后执行resolvectl status还是只有/etc/systemd/resolved.conf中的DNS 172.22.136.2和/etc/netplan/00-installer-config.yaml中的DNS 172.22.10.66,没有/etc/resolv.conf中的127.0.0.53

4、ubuntu官方不建议使用/etc/resolve.conf来配置ubuntu 的dns信息,ubuntu对于/etc/resolv.conf的官方描述:If you require DNS for your temporary network configuration, you can add DNS server IP addresses in the file /etc/resolv.conf. In general, editing /etc/resolv.conf directly is not recommended, but this is a temporary and non-persistent configuration.

5、ubuntu 22.04查看dns信息的命令是resolvectl status,该命令可以看到全局dns信息和某个网卡的dns信息,全局DNS服务器信息一般来自配置文件/etc/systemd/resolved.conf,仅在/etc/resolv.conf不是一个指向/run/systemd/resolve/stub-resolv.conf, /usr/lib/systemd/resolv.conf, /run/systemd/resolve/resolv.conf 之一的软连接的情况下,且/etc/systemd/resolved.conf中dns被注释掉的情况下,全局DNS服务器才会读取自/etc/resolv.conf,所以这就是不建议大家使用/etc/resolve.conf来配置ubuntu 的dns信息的原因。

修改服务器名
修改服务器名为FRSBachDEV3,重启后也生效的方法
vi /etc/hostname
FRSBachDEV3
备注:如果/etc/hostname文件中的内容写成hostname FRSBachDEV3,那么重启后服务器名就变成了hostnameFRSBachDEV3

修改IP
https://ubuntu.com/server/docs/network-configuration
https://manpages.ubuntu.com/manpages/jammy/man5/netplan.5.html
netplan是一个命令行工具,用于ubuntu上配置网络,所有/etc/netplan/*.yaml文件都将被使用

root@FRSBachDEV3:~# cat /etc/netplan/00-installer-config.yaml
network:ethernets:ens160:dhcp4: trueversion: 2
root@FRSBachDEV3:~# vim /etc/netplan/00-installer-config.yaml
network:ethernets:ens160:dhcp4: falseaddresses: [172.22.136.147/22]routes:- to: defaultvia: 172.22.136.1nameservers:search: [dai.netdai.com,netdai.com]addresses: [172.22.10.66,172.22.10.67]version: 2

备注:
dhcp4中的4表示ipv4
gateway4中的4表示ipv4,不过gateway4已经被废弃,配置了gateway4再执行netplan apply的话会报错** (generate:1426): WARNING **: 09:54:13.918: gateway4 has been deprecated, use default routes instead.See the ‘Default routes’ section of the documentation for more details.
routes项填写网关地址
addresses项填写ip地址
nameservers项填写dns地址或搜索域,其中addresses子项是dns地址列表,search子项是搜索域名列表
version: 2这一项表示YAML版本是2,curtin,MaaS等目前使用的YAML的版本是1

root@FRSBachDEV3:~# netplan applyroot@FRSBachDEV3:~# cat /etc/resolv.conf
nameserver 127.0.0.53
options edns0 trust-ad
search dai.netdai.com netdai.comroot@FRSBachDEV3:~# ifconfig
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500inet 172.22.136.147  netmask 255.255.252.0  broadcast 172.22.139.255inet6 fe80::250:56ff:fe94:522d  prefixlen 64  scopeid 0x20<link>ether 00:50:56:94:52:2d  txqueuelen 1000  (Ethernet)RX packets 45071  bytes 3394009 (3.3 MB)RX errors 0  dropped 40  overruns 0  frame 0TX packets 765  bytes 78732 (78.7 KB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536inet 127.0.0.1  netmask 255.0.0.0inet6 ::1  prefixlen 128  scopeid 0x10<host>loop  txqueuelen 1000  (Local Loopback)RX packets 2331  bytes 168025 (168.0 KB)RX errors 0  dropped 0  overruns 0  frame 0TX packets 2331  bytes 168025 (168.0 KB)TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

查看网关

root@FRSBachDEV3:~# ip route | grep default
default via 172.22.136.1 dev ens160 proto staticroot@FRSBachDEV3:~# nmcli dev show|grep GATEWAY
IP4.GATEWAY:                            172.22.136.1
IP6.GATEWAY:                            --
IP4.GATEWAY:                            --
IP6.GATEWAY:                            --

查看dns

root@FRSBachDEV3:~# resolvectl status
GlobalProtocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stubLink 2 (ens160)Current Scopes: DNSProtocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 172.22.10.66DNS Servers: 172.22.10.66 172.22.10.67DNS Domain: dai.netdai.com netdai.com

实验:如何才会使用到/etc/resolve.conf中的dns信息

/etc/systemd/resolved.conf中dns为172.22.136.2
root@FRSBachDEV3:~# cat /etc/systemd/resolved.conf |grep DNS=
DNS=172.22.136.2/etc/resolv.conf来自软链接/run/systemd/resolve/stub-resolv.conf
root@FRSBachDEV3:~# ll /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Aug  9  2022 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.confroot@FRSBachDEV3:~# cat /run/systemd/resolve/stub-resolv.conf
nameserver 127.0.0.53
options edns0 trust-ad
search dai.netdai.com netdai.com/run/systemd/resolve/resolv.conf有来自/etc/systemd/resolved.conf中dns 172.22.136.2,也有来自/etc/netplan/00-installer-config.yaml中dns 172.22.10.66 172.22.10.67,就是没有来自/etc/resolv.conf的127.0.0.53
root@FRSBachDEV3:~# cat /run/systemd/resolve/resolv.conf
nameserver 172.22.136.2
nameserver 172.22.10.66
nameserver 172.22.10.67
search dai.netdai.com netdai.com/etc/systemd/resolved.conf中dns 172.22.136.2和/etc/netplan/00-installer-config.yaml中dns 172.22.10.66 172.22.10.67,就是没有来自/etc/resolv.conf的127.0.0.53
root@FRSBachDEV3:~# resolvectl status
GlobalProtocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupportedresolv.conf mode: stub
Current DNS Server: 172.22.136.2DNS Servers: 172.22.136.2Link 2 (ens160)Current Scopes: DNSProtocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 172.22.10.66DNS Servers: 172.22.10.66 172.22.10.67DNS Domain: dai.netdai.com netdai.com删除/etc/resolv.conf来自软链接,并手工建立/etc/resolv.conf文件,其中dns为172.22.136.3
root@FRSBachDEV3:~# ll /etc/resolv.conf
-rw-r--r-- 1 root root 946 Oct 12 10:49 /etc/resolv.confroot@FRSBachDEV3:~# cat /etc/resolv.conf
nameserver 172.22.136.3
options edns0 trust-ad
search dai.netdai.com netdai.com保留/etc/systemd/resolved.conf中dns 172.22.136.2的情况下,重启systemd-resolved,发现还是用的/etc/systemd/resolved.conf中dns 172.22.136.2而没有使用手工建立/etc/resolv.conf文件的dns 172.22.136.3
root@FRSBachDEV3:~# systemctl restart systemd-resolved
root@FRSBachDEV3:~# resolvectl status
GlobalProtocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: foreignDNS Servers: 172.22.136.2Link 2 (ens160)
Current Scopes: DNSProtocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupportedDNS Servers: 172.22.10.66 172.22.10.67DNS Domain: dai.netdai.com netdai.com注释掉/etc/systemd/resolved.conf中dns再重启systemd-resolved,发现这个时候才真正用上了手工建立/etc/resolv.conf文件的dns 172.22.136.3
root@FRSBachDEV3:~# vim /etc/systemd/resolved.conf
root@FRSBachDEV3:~# cat /etc/systemd/resolved.conf |grep DNS
#DNSroot@FRSBachDEV3:~# systemctl restart systemd-resolved
root@FRSBachDEV3:~# resolvectl status
GlobalProtocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupportedresolv.conf mode: foreign
Current DNS Server: 172.22.136.3DNS Servers: 172.22.136.3DNS Domain: dai.netdai.com netdai.comLink 2 (ens160)
Current Scopes: DNSProtocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupportedDNS Servers: 172.22.10.66 172.22.10.67DNS Domain: dai.netdai.com netdai.comroot@FRSBachDEV3:~# cat /run/systemd/resolve/resolv.conf
nameserver 172.22.136.3
nameserver 172.22.10.66
nameserver 172.22.10.67
search dai.netdai.com netdai.com

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/107884.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C#,数值计算——分类与推理Gaumixmod的计算方法与源程序

1 文本格式 using System; using System.Collections.Generic; namespace Legalsoft.Truffer { public class Gaumixmod { private int nn { get; set; } private int kk { get; set; } private int mm { get; set; } private double…

【SA8295P 源码分析 (一)】62 - Android GVM Kernel 内核 make bootimage 过程分析

【SA8295P 源码分析】62 - Android GVM Kernel 内核 make bootimage 过程分析 一、make bootimage 命令执行过程分析1.1 source buid/envsetup.sh 分析1.2 lunch msmnile_gvmq-userdebug 分析1.3 make bootimage:step 1 之 加载配置文件过程分析1.4 make bootimage:step 2 之…

CEC2013(MATLAB):墨西哥蝾螈优化算法(Mexican Axolotl Optimization,MAO)求解CEC2013

一、墨西哥蝾螈优化算法MAO 墨西哥蝾螈优化算法&#xff08;Mexican Axolotl Optimization&#xff0c;MAO&#xff09;由Yenny Villuendas-Rey 1等人于2021年提出&#xff0c;该算法具有较强的平衡全局搜索与局部搜索能力。 参考文献&#xff1a; [1]Villuendas-Rey, Yenny,…

opencv定位图片中的图案?

使用opencv模板匹配方式。 这种方式针对从原始图片中直接扣小图情况比较好。 import cv2 as cv2def find_positions(image_path, small_image_path):# 读取大图和小图large_image cv2.imread(image_path)small_image cv2.imread(small_image_path)# 小图规格small_image_h, …

07-ConfigurationClassPostProces的解析

文章目录 如何解析Component,Service,Configurationd,Bean,Import等注解1. 源码描述2. 类继承结构图3. 解析流程4. 具体的注解解析 如何解析Component,Service,Configurationd,Bean,Import等注解 1. 源码描述 BeanFactoryPostProcessor used for bootstrapping processing of…

Android Fragment 基本概念和基本使用

Android Fragment 基本概念和基本使用 一、基本概念 Fragment&#xff0c;简称碎片&#xff0c;是Android 3.0&#xff08;API 11&#xff09;提出的&#xff0c;为了兼容低版本&#xff0c;support-v4库中也开发了一套Fragment API&#xff0c;最低兼容Android 1.6。 过去s…

学术特稿 | 著名书法家项国就:中国古代书法章草美学展现的形式分析

、 论文入编&#xff1a;大型综合美术类核心期刊《新美域》杂志2023年第七期。 中国古代书法章草美学展现的形式分析 摘要&#xff1a;本文旨在探讨中国古代书法风格章草的美学特点、审美价值以及代表性作品和艺术家。章草的美学特点体现在简洁流畅的笔画、清晰规整的字形结构以…

【JAVA】日志打印java.util.logging.*函数自定义格式,并且显示调用时行号

1、JAVA自带的这样&#xff1a; 代码如下&#xff1a; import java.util.logging.*; Logger logger Logger.getLogger(MyLogger.class.toString()); logger.info("123");显示效果&#xff1a; 这样的格式&#xff0c;看起来不太好看&#xff0c;比如&#xff1a;会…

【Unity3D编辑器开发】Unity3D中实现Transform组件拓展,快速复制、粘贴、复原【非常实用】

推荐阅读 CSDN主页GitHub开源地址Unity3D插件分享简书地址我的个人博客 大家好&#xff0c;我是佛系工程师☆恬静的小魔龙☆&#xff0c;不定时更新Unity开发技巧&#xff0c;觉得有用记得一键三连哦。 一、前言 在开发中&#xff0c;常常会遇到频繁复制粘贴物体的坐标、旋转…

小程序需带参数跳转

1、需要生成二维码的数据 直接在浏览器中替换成自己的appid&#xff0c;secret及可生成一个access_token https://api.weixin.qq.com/cgi-bin/token?grant_typeclient_credential&appidwxxxxx&secretxxxxx用access_token https://api.weixin.qq.com/wxa/getwxacode…

数据库、数据中台、数据仓库、数据湖区别

数据时代&#xff0c;各行业的企业都已经开始通过数据库来沉淀数据&#xff0c;但是真的论起数据库、数据仓库、数据中台&#xff0c;还是新出现的数据湖&#xff0c;它们的概念和区别&#xff0c;可能知道的人就比较少了&#xff0c;今天我们详细来比较了解一下。 一、数据仓…

Oracle基础学习

文章目录 1. oracle数据库安装2. sqlplus连接数据库方式3. 创建用户信息4. 基本概念5. 基本SQL语句6. Springboot开发 1. oracle数据库安装 安装教程 安装包地址 2. sqlplus连接数据库方式 无用户信息登录 使用用户信息登录 登录最高权限管理员&#xff0c;如果不加上as …

Spring Cloud Alibaba—Sentinel 控制台安装

1、Sentinel 控制台包含如下功能: 查看机器列表以及健康情况&#xff1a;收集 Sentinel 客户端发送的心跳包&#xff0c;用于判断机器是否在线。 监控 (单机和集群聚合)&#xff1a;通过 Sentinel 客户端暴露的监控 API&#xff0c;定期拉取并且聚合应用监控信息&#xff0c;最…

如何通过内网穿透实现远程连接NAS群晖drive并挂载电脑硬盘?

文章目录 前言1.群晖Synology Drive套件的安装1.1 安装Synology Drive套件1.2 设置Synology Drive套件1.3 局域网内电脑测试和使用 2.使用cpolar远程访问内网Synology Drive2.1 Cpolar云端设置2.2 Cpolar本地设置2.3 测试和使用 3. 结语 前言 群晖作为专业的数据存储中心&…

Access denied for user ‘itstar‘@‘%localhost‘ to database ‘sc‘

今天发现数据库报这个错&#xff0c;经过排查&#xff0c;原因如下 原因一 本地装了两个版本的mysql&#xff0c;连错数据库了。 原因二 连上正确的数据库后&#xff0c;还是报这个错&#xff0c;发现是当前用户没有这个数据库的权限&#xff0c;开通权限。问题解决 Dupli…

为什么要把 String 设计为不可变?

将字符串设计为不可变具有多个重要的原因&#xff1a; 线程安全性&#xff1a; 不可变字符串可以在多线程环境中共享而无需额外的同步措施。因为字符串不会改变&#xff0c;多个线程可以同时访问它而不会导致竞态条件或数据不一致性。 缓存和性能优化&#xff1a; 字符串不可变…

Day1力扣打卡

打卡记录 最长相邻不相等子序列 I&#xff08;脑筋急转弯&#xff09; 链接 思路&#xff1a;形如 11100110001 要达到最大&#xff0c;必须在重复数字选出一个&#xff0c;即在111中取一个1&#xff0c;在00中取一个0&#xff0c;以此类推最终便得到最长相邻不相等子序列。 c…

Elasticsearch 8.11 中的合并更少,摄取更快

作者&#xff1a;ADRIEN GRAND Elasticsearch 8.11 改进了管理索引缓存的方式&#xff0c;从而减少了段合并。 我们对 Elasticsearch 8.11 从索引缓存回收内存的方式进行了重大更改&#xff0c;这有助于减少合并开销&#xff0c;从而加快索引速度。 使用我们的日志跟踪&#x…

maven 常用知识速记

创建项目 maven archetype:generate依赖范围 有如下依赖示例&#xff1a; <dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.7</version><scope>test</scope> </dependency>其中…

力扣刷题 day46:10-16

1.最大整除子集 给你一个由 无重复 正整数组成的集合 nums &#xff0c;请你找出并返回其中最大的整除子集 answer &#xff0c;子集中每一元素对 (answer[i], answer[j]) 都应当满足&#xff1a; answer[i] % answer[j] 0 &#xff0c;或 answer[j] % answer[i] 0 如果存在…