0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

Linux系统中一些重要的配置文件介绍

马哥Linux运维 来源:博客园 2024-02-19 17:39 次阅读

1.网卡配置文件

[root@testcentos7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens33"
UUID="4cf09cae-5418-44e9-8450-422230bd68fc"
DEVICE="ens33"
ONBOOT="yes"
IPADDR="192.168.52.130"
PREFIX="24"
GATEWAY="192.168.52.2"
DNS1="119.29.29.29"
解释每个字段的含义:
TYPE="Ethernet":指定网络接口类型为以太网
PROXY_METHOD="none":不使用代理方法。
BROWSER_ONLY="no":不仅限于浏览器。
BOOTPROTO="none":手动配置 IP 地址,不使用 DHCP。
DEFROUTE="yes":将此接口设置为默认路由。
IPV4_FAILURE_FATAL="no":IPv4 连接失败不会导致系统失败。
IPV6INIT="yes":启用 IPv6。
IPV6_AUTOCONF="yes":启用 IPv6 自动配置。
IPV6_DEFROUTE="yes":将此接口设置为 IPv6 默认路由。
IPV6_FAILURE_FATAL="no":IPv6 连接失败不会导致系统失败。
IPV6_ADDR_GEN_MODE="stable-privacy":使用稳定的隐私地址生成模式。
NAME="ens33":接口名称为 ens33。
UUID="4cf09cae-5418-44e9-8450-422230bd68fc":接口的唯一标识符。
DEVICE="ens33":接口设备名称为 ens33。
ONBOOT="yes":在系统引导时自动启用该接口。
IPADDR="192.168.52.130":指定 IPv4 地址为 192.168.52.130。
PREFIX="24":IPv4 子网掩码前缀为 24,即 255.255.255.0。
GATEWAY="192.168.52.2":指定默认网关为 192.168.52.2。
DNS1="119.29.29.29":指定首选 DNS 服务器为 119.29.29.29。

2./etc/hosts

系统文件,用于配置主机名与 IP 地址的映射关系。当系统需要解析主机名时,会首先查找 /etc/hosts 文件,如果在该文件中找到了相应的映射关系,则直接使用对应的 IP 地址进行通信,而不需要进行 DNS 查询。

[root@testcentos7 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 localhost:将 localhost 主机名映射到回环地址 127.0.0.1,即本地主机。
::1 localhost:将 IPv6 的 localhost 主机名映射到回环地址 ::1,即本地主机。

3./etc/hostname

主机名称配置文件

3.1.修改主机名称的三种方法

1.重启后生效

[root@testcentos7 ~]# vim /etc/hostname
hehe

2.临时修改

临时修改主机名称 重启系统失效 退出重新连接即可生效
[root@hehe ~]# hostname web
[root@hehe ~]# exit

3.临时加永久修改主机名称

临时+永久 同时修改了配置文件 重启会读取主机名的配置文件 重点
[root@web ~]# hostnamectl set-hostname nihaoshuai
[root@web ~]# cat /etc/hostname
nihaoshuai

4./etc/resolv.conf

用于 DNS 解析的配置信息。DNS 解析是将主机名转换为 IP 地址的过程,在 Linux 中,通常使用 resolver 库提供的函数来进行 DNS 解析。该文件由网络管理程序根据网络配置自动生成,但也可以手动编辑此文件以更改 DNS 解析配置。

[root@testcentos7 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 119.29.29.29
search localdomain

注意事项

1.如果网卡配置了DNS,resolv.conf会被覆盖

2.网卡配置DNS必须重启才能生效

3.如果网卡没有配置DNS不影响resolv.conf

4.resolv.conf配置DNS直接生效不需要重启 建议在resolv.conf配置不在网卡配置

[root@testcentos7 ~]# cat /etc/resolv.conf Generated by NetworkManager nameserver 223.5.5.5 nameserver 114.114.114.114 nameserver 8.8.8.8

5.安装查询IP

[root@testcentos7 ~]# yum -y install bind-utils
[root@testcentos7 ~]# nslookup www.baidu.com
Server:119.29.29.29
Address:119.29.29.29#53
Non-authoritative answer:
www.baidu.comcanonical name = www.a.shifen.com.
Name:www.a.shifen.com
Address: 220.181.38.150
Name:www.a.shifen.com
Address: 220.181.38.149
Name:www.a.shifen.com
Address: 240e:83:205:5a:0b05f:346b
Name:www.a.shifen.com
Address: 240e:83:205:58:0b09f:36bf

6./etc/fstab

系统文件,用于配置在系统启动时自动挂载的文件系统。它定义了文件系统的挂载点、设备、文件系统类型、挂载选项等信息。

[root@testcentos7 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Jan 10 1704 2024
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=dbee441f-bdcd-41db-824c-3f461eb48952 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/mapper/centos-root:指定要挂载的设备或文件系统。
/:指定文件系统的挂载点,即根目录。
xfs:指定文件系统的类型。
defaults:指定挂载选项,表示使用

7./etc/rc.local

在早期版本的 Linux 中,/etc/rc.local 是一个可执行脚本文件,用于在系统引导过程中作为最后一个启动脚本运行。它允许用户在系统启动时自定义一些额外的命令或脚本。 然而,在现代的 Linux 发行版中,使用 systemd 作为初始化系统,因此 /etc/rc.local 文件可能已不再被使用。相反,可以使用 systemd 的单元文件来管理启动和运行服务。

[root@testcentos7 ~]# cat /etc/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local

8./etc/profile

系统级别的 Bash shell 配置文件,它包含了所有用户的全局 shell 配置。当用户登录时,该文件会被加载并执行。 在 /etc/profile 文件中可以定义全局的环境变量、设置 PATH 环境变量、配置系统的默认语言等。

[root@testcentos7 ~]# cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
if [ -x /usr/bin/id ]; then
if [ -z "$EUID" ]; then
# ksh workaround
EUID=`/usr/bin/id -u`
UID=`/usr/bin/id -ru`
fi
USER="`/usr/bin/id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /usr/sbin
pathmunge /usr/local/sbin
else
pathmunge /usr/local/sbin after
pathmunge /usr/sbin after
fi
HOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
umask 002
else
umask 022
fi
for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge

9./etc/motd

远程连接提示配置文件

10./var/log/messages

系统日志文件,记录了系统的各种事件、错误和警告信息。它是许多 Linux 发行版中常见的日志文件之一,用于存储系统级别的日志数据。在 /var/log/messages 文件中,您可以找到诸如系统启动消息、网络连接信息、硬件故障报告、登录和注销事件等系统事件的记录。这些日志可以帮助系统管理员和用户跟踪问题、分析故障和监视系统状况。

[root@testcentos7 ~]# cat /var/log/messages
Jan 10 1745 localhost journal: Runtime journal is using 6.0M (max allowed 48.6M, trying to leave 72.9M free of 480.0M available → current limit 48.6M).
Jan 10 1745 localhost kernel: Initializing cgroup subsys cpuset
Jan 10 1745 localhost kernel: Initializing cgroup subsys cpu
Jan 10 1745 localhost kernel: Initializing cgroup subsys cpuacct
Jan 10 1745 localhost kernel: Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 1659 UTC 2020
Jan 10 1745 localhost kernel: Command line: BOOT_IMAGE=/vmlinuz-3.10.0-1160.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=zh_CN.UTF-8
Jan 10 1745 localhost kernel: [Firmware Bug]: TSC doesn't count with P0 frequency!
Jan 10 1745 localhost kernel: e820: BIOS-provided physical RAM map:
Jan 10 1745 localhost kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009ebff] usable
Jan 10 1745 localhost kernel: BIOS-e820: [mem 0x000000000009ec00-0x000000000009ffff] reserved
Jan 10 1745 localhost kernel: BIOS-e820: [mem 0x00000000000dc000-0x00000000000fffff] reserved
Jan 10 1745 localhost kernel: BIOS-e820: [mem 0x0000000000100000-0x000000003fedffff] usable
Jan 10 1745 localhost kernel: BIOS-e820: [mem 0x000000003fee0000-0x000000003fefefff] ACPI data
Jan 10 1745 localhost kernel: BIOS-e820: [mem 0x000000003feff000-0x000000003fefffff] ACPI NVS
Jan 10 1745 localhost kernel: BIOS-e820: [mem 0x000000003ff00000-0x000000003fffffff] usable
Jan 10 1745 localhost kernel: BIOS-e820: [mem 0x00000000f0000000-0x00000000f7ffffff] reserved
Jan 10 1745 localhost kernel: BIOS-e820: [mem 0x00000000fec00000-0x00000000fec0ffff] reserved
Jan 10 1745 localhost kernel: BIOS-e820: [mem 0x00000000fee00000-0x00000000fee00fff] reserved
Jan 10 1745 localhost kernel: BIOS-e820: [mem 0x00000000fffe0000-0x00000000ffffffff] reserved
Jan 10 1745 localhost kernel: NX (Execute Disable) protection: active
Jan 10 1745 localhost kernel: SMBIOS 2.7 present.
Jan 10 1745 localhost kernel: DMI: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 11/12/2020
Jan 10 1745 localhost kernel: Hypervisor detected: VMware
Jan 10 1745 localhost kernel: vmware: TSC freq read from hypervisor : 3193.910 MHz

11./var/log/secure

系统日志文件,记录了与系统安全相关的事件、错误和警告信息。它是许多 Linux 发行版中常见的日志文件之一,用于存储与安全相关的日志数据。在 /var/log/secure 文件中,您可以找到诸如登录和注销事件、使用 sudo 的记录、认证失败尝试以及其他与系统安全相关的事件的记录。这些日志可以帮助系统管理员和用户跟踪安全问题、分析入侵尝试和监视系统安全状况


[root@testcentos7 ~]# cat /var/log/secure
Jan 10 17:26:51 localhost polkitd[956]: Loading rules from directory /etc/polkit-1/rules.d
Jan 10 17:26:51 localhost polkitd[956]: Loading rules from directory /usr/share/polkit-1/rules.d
Jan 10 17:26:51 localhost polkitd[956]: Finished loading, compiling and executing 2 rules
Jan 10 17:26:51 localhost polkitd[956]: Acquired the name org.freedesktop.PolicyKit1 on the system bus
Jan 10 17:26:55 localhost sshd[1521]: Server listening on 0.0.0.0 port 22.
Jan 10 17:26:55 localhost sshd[1521]: Server listening on :: port 22.
Jan 10 17:28:51 localhost login: pam_unix(login session opened for user root by LOGIN(uid=0)
Jan 10 17:28:51 localhost login: ROOT LOGIN ON tty1
Jan 10 18:03:54 localhost polkitd[956]: Registered Authentication Agent for unix-process:1868:222974 (system bus name :1.25 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8)
Jan 10 18:03:55 localhost polkitd[956]: Unregistered Authentication Agent for unix-process:1868:222974 (system b





审核编辑:刘清

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 以太网
    +关注

    关注

    40

    文章

    5076

    浏览量

    166235
  • Linux系统
    +关注

    关注

    4

    文章

    567

    浏览量

    26913
  • DNS
    DNS
    +关注

    关注

    0

    文章

    199

    浏览量

    19604

原文标题:Linux系统中一些重要的配置文件

文章出处:【微信号:magedu-Linux,微信公众号:马哥Linux运维】欢迎添加关注!文章转载请注明出处。

收藏 人收藏

    评论

    相关推荐

    linux下的一些文件的简单操作

    Linux 应用编程中最需要掌握的基础就是文件 I/O的操作,学习过linux或者有过了解的应该都会听过一句话:linux中一切皆
    发表于 01-11 15:40 349次阅读
    <b class='flag-5'>linux</b>下的<b class='flag-5'>一些</b><b class='flag-5'>文件</b>的简单操作

    基于libconfig进行配置文件解析

    本文介绍基于libconfig进行配置文件解析
    的头像 发表于 06-08 10:18 845次阅读
    基于libconfig进行<b class='flag-5'>配置文件</b>解析

    关于linux内核配置文件

    linux怎样选择内核配置文件
    发表于 12-08 21:21

    FreeRTOS配置文件

    FreeRTOS的时候,我们常常需要根据自己的需求来配置FreeRTOS,而且不同的架构的MCU在使用的时候配置也不同。FreeRTOS的系统配置文件为FreeRTOSConfig.h,在该
    发表于 08-20 08:09

    ICD配置文件的详细介绍配置内容的详细概述

    配置文件配置文件是利用SCL语言描述变电站设备对象模型后生成的文件,用于在不同厂商的配置工具之间交换配置信息。
    的头像 发表于 06-02 11:16 1.7w次阅读
    ICD<b class='flag-5'>配置文件</b>的详细<b class='flag-5'>介绍</b>和<b class='flag-5'>配置</b>内容的详细概述

    Linux教程之网络配置文件配置方法及常用网络操作命令

    本文档的主要内容详细介绍的是Linux教程之网络配置文件配置方法及常用网络操作命令详细资料免费下载主要目标是1.掌握网络配置文件
    发表于 11-07 11:49 9次下载
    <b class='flag-5'>Linux</b>教程之网络<b class='flag-5'>配置文件</b>与<b class='flag-5'>配置</b>方法及常用网络操作命令

    需要了解的Linux 系统中一些针对文件系统的节能技巧

    文件系统Linux 系统重要组成部分,文件系统配置和使用对整个
    发表于 04-27 19:22 549次阅读

    SHARC音频模块:配置文件对裸机框架进行配置重要

    详细介绍如何从一个配置文件配置裸机框架的重要方面。
    的头像 发表于 06-27 06:02 2191次阅读
    SHARC音频模块:<b class='flag-5'>配置文件</b>对裸机框架进行<b class='flag-5'>配置</b>的<b class='flag-5'>重要</b>性

    ARM Linux中一些重要的宏及地址定义

    ARM Linux中一些重要的宏及地址定义
    的头像 发表于 06-22 17:02 2502次阅读

    Python进行配置文件的教程免费下载

    本文档的主要内容详细介绍的是Python进行配置文件的教程免费下载。
    发表于 09-30 16:41 6次下载
    Python进行<b class='flag-5'>配置文件</b>的教程免费下载

    配置文件和例程文件的使用

    上期讲述了AMetal平台驱动框架中的硬件层,介绍了硬件层的驱动是如何实现及其硬件层接口的定义,逐渐深入了解AMetal平台。接下来向大家介绍配置文件和例程文件的使用,以此可灵活使用相
    的头像 发表于 04-07 11:49 1698次阅读
    <b class='flag-5'>配置文件</b>和例程<b class='flag-5'>文件</b>的使用

    linux修改网卡ip配置文件

    Linux是一种开源的操作系统,因此,它给用户提供了很高的自由度,可以根据个人需要进行各种定制和配置。其中,修改网络接口配置文件是常见的操作,可以通过修改网卡ip
    的头像 发表于 11-17 10:51 1232次阅读

    springboot的全局配置文件有几种

    Spring Boot是一种快速开发框架,其通过提供配置文件来实现对应用程序的配置。全局配置文件在Spring Boot中起着非常重要的作用,可以用于
    的头像 发表于 12-03 15:28 490次阅读

    php的配置文件是什么

    中,配置文件的名称默认为php.ini。该文件通常位于PHP安装目录下的conf文件夹中。当PHP解释器启动时,会自动加载php.ini文件,并根据其中的
    的头像 发表于 12-04 15:55 801次阅读

    oracle配置文件类型关联

    Oracle是一种业界领先的关系型数据库管理系统,它在大型企业中被广泛使用。Oracle的配置文件对于数据库的稳定运行和性能优化至关重要。在这篇文章中,我们将详细讨论Oracle的一些
    的头像 发表于 12-06 10:17 227次阅读