一、Linux内核主要功能:

内核主要功能可分为以下几点:

(1).进程管理;

(2).内存管理;

(3).IO管理;

(4).文件系统;

(5).硬件的驱动程序;

(6).安全相关;(加密算法实现、API等)

2.内核设计为两个流派:

(1)微内核:精小,将功能全部以模块方式整合,耦合度较高

:windowssolaris等等

(2)单内核:所有功能都被整合在一起,都被整合在内核本身来使用。耦合度较低。linux虽然是单内核但是linux可以实现内核功能模块化,模块化的好处:模块选择机制灵活(其模块间的通讯是通过直接调用其他模块中的函数实现的,而不是消息传递)

如果一个程序频繁的产生系统调用,模式转换本身也会导致系统开销,所以在一个正常系统上,内核模式所占据的时间不能过多 正常应该是7/3,用户占据70%


二、Linux启动流程

1.init介绍

 init是Linux系统操作中不可缺少的程序之一,所谓的init进程,它是一个由内核启动的用户级进程。内核自行启动(已经被载入内存,开始运行,并已初始化所有的设备驱动程序和数据结构等)之后,就通过启动一个用户级程序init的方式,完成引导进程。所以init始终是第一个进程(也就是我们所说的父进程),内核会在过去曾使用过init的几个地方查找它,它的正确位置是/sbin/init。如果内核找不到init,它就会试着运行/bin/bash,如果运行失败,系统的启动也会失败。init启动起来之后会将没有装载的内核模块都装载进来,内核本身完成初始化的时候可能只启动了最基本的硬件,init来负责装载其他驱动程序,比如负责识别键盘鼠标等等

2.RHEL5的init是如何初始化的:

RHE5与RHEL6不同,RHEL6使用的是ubuntu中的upstart机制,upstart通过事件驱动加速了init启动速度,但兼容性不好

RHEL5 init如何初始化:

(1)开机加电自检(POST)开机-ROM+RAM(cpu会加载内存地址空间某一特定空间指令)

(2)启动boot

(3)加载MBR(加载446字节 bootloader 64字节的分区表) 为了负责启动操作系统的内核,会在内存中解压缩并负责启动内核的第一个指令

(4)加载内核(外围设备基本的硬件初始化,以及装载根文件系统(所有的访问的文件都在根文件系统,如果没有/ 则没有/sbin/init 也就意味着无法启动 )

(5)装载/sbin/init (则红帽6的upstart 则依赖于/etc/init/*.conf )

3. RHEL5 inittab:

(1)inittab的启动级别:

0:关机

6:重启

1:单用户模式(绝大数服务都不会被启动,仅修复系统之用)

2:无NFS文件系统的多用户模式

3:正常级别,文本模式

4:保留,未使用

5:带图形界面的正常级别

(2)切换启动级别

切换级别可以使用 init # 来完成,如切换到级别3:

[[email protected]~]# init 3

(4)查看当前级别

[[email protected]~]# who -r

        run-level 3  2013-12-04 21:40                   last=3  #这里表示上次在哪个级别切换回来的

[[email protected]~]# runlevel

N 3

(5)inittab配置文件

#可以看到只有一行生效,表示默认运行级别

[[email protected]~]# cat /etc/inittab


#默认运行级别

id:3:initdefault:


#只有::为空表示所有级别,

#sysinit为系统初始化的系统脚本

si::sysinit:/etc/rc.d/rc.sysinit


#wait表示切换进此级别时执行

l0:0:wait:/etc/rc.d/rc0

l1:1:wait:/etc/rc.d/rc1

l2:2:wait:/etc/rc.d/rc2

l3:3:wait:/etc/rc.d/rc3

l4:4:wait:/etc/rc.d/rc4

l5:5:wait:/etc/rc.d/rc5

l6:6:wait:/etc/rc.d/rc6


#当按下重启组合键的时候将重启,一般来说要禁用这三个键,注释即可

ca::ctrlaltdel:/sbin/shutdown-t3 -r now


#电源故障时将过2分钟关机

pf::powerfail:/sbin/shutdown-f -h +2 "Power Failure; System Shutting Down"

#如果上面参数生效,关机的过程如果已来电则使用 shutdown -c 命令来取消关机

pr:12345:powerokwait:/sbin/shutdown-c "Power Restored; Shutdown Cancelled"


#等待下次重新登录(重启终端)

1:2345:respawn:/sbin/mingettytty1

2:2345:respawn:/sbin/mingettytty2

3:2345:respawn:/sbin/mingettytty3

4:2345:respawn:/sbin/mingettytty4

5:2345:respawn:/sbin/mingettytty5

6:2345:respawn:/sbin/mingettytty6

x:5:respawn:/etc/X11/prefdm-nodaemon

而在RHEL6当中,会将initab切割成很多个片文件:

[[email protected]~]# ls /etc/init/

control-alt-delete.conf  plymouth-shutdown.conf  rc.conf             rcS-sulogin.conf          readahead-disable-services.conf  start-ttys.conf

init-system-dbus.conf    prefdm.conf             rcS.conf            readahead-collector.conf  serial.conf                      tty.conf

kexec-disable.conf       quit-plymouth.conf      rcS-emergency.conf  readahead.conf            splash-manager.conf

3.rc.sysinit配置文件

/etc/rc.d/rc.sysinit 为系统初始化的系统脚本,其主要作用如下所示:

1.激活selinux和udev

2.根据/etc/sysctl.conf文件设置内核参数

3.设置系统时钟

4.装载键映射

5.启用交换分区

6.设置主机名

7.根文件系统检测并将其挂载为读写

8.激活软RAID和LVM

9.检查和挂载其他文件系统在fstab中定义

10.清理操作


#参考文献:

http://www.chinaunix.net/old_jh/4/903087.html

4.服务(进程)的启动级别

我们知道服务的守护进程都是由init来启动的,但是其进程的所启动的级别定义是由chkconfig命令来管理的。 chkconfig是一个Linux系统下的服务管理程序,他主要是用来设置服务在Linux系统启动时在每个运行级别下的状态。

首先来看一下进程所在路径,如下所示

[[email protected]~]# ls  /etc/rc.d/rc3.d/

K01dnsmasq         K20rwhod         K74ipmi            K99readahead_later  S12syslog          S25pcscd       S90crond

K02NetworkManager  K24irda          K74nscd            S00microcode_ctl    S13cpuspeed        S26acpid       S90xfs

K02avahi-dnsconfd  K25squid         K74ntpd            S02lvm2-monitor     S13irqbalance      S26apmd        S95anacron

K02oddjobd         K30spamassassin  K80kdump           S03sysstat          S13portmap         S26haldaemon   S95atd

K05conman          K35dovecot       K85mdmpd           S04readahead_early  S14nfslock         S26hidd        S97yum-updatesd

K05saslauthd       K35winbind       K87multipathd      S05kudzu            S15mdmonitor       S28autofs      S98avahi-daemon

K10dc_server       K36mysqld        K88wpa_supplicant  S08ip6tables        S18rpcidmapd       S55sshd        S99firstboot

K10psacct         K50ibmasm        K89dund            S08mcstrans         S19rpcgssd         S56cups        S99local

K10tcsd            K50netconsole    K89netplugd        S09isdn             S22messagebus      S56rawdevices  S99smartd

K12dc_client       K50tux          K89pand            S10network          S23setroubleshoot  S56xinetd

K15httpd           K69rpcsvcgssd    K89rdisc           S11auditd           S25bluetooth       S80sendmail

K20nfs             K73ypbind        K91capi            S12restorecond      S25netfs           S85gpm


[[email protected]~]# ll -th /etc/rc.d/rc3.d/ | head -6

total324K

lrwxrwxrwx1 root root 16 Jan 24  2012 K36mysqld-> ../init.d/mysqld

lrwxrwxrwx1 root root 17 Jan 24  2012 S03sysstat-> ../init.d/sysstat

lrwxrwxrwx1 root root 17 Jan 23  2012 K35winbind-> ../init.d/winbind

lrwxrwxrwx1 root root 16 Jan 23  2012 K73ypbind-> ../init.d/ypbind

lrwxrwxrwx1 root root 14 Jan 23  2012 S26apmd ->../init.d/apmd

可以看到有很多以K开头或以S开头的文件,而且全部都是链接文件,那么这些字母开头都是有何含义呢?

再来看一下,以smartd服务为例其启动脚本的头部信息,如下所示:

[[email protected]~]# head -10 /etc/init.d/smartd

#!/bin/sh


#smartmontools init file for smartd

#Copyright (C) 2002-4 Bruce Allen<[email protected]>

# $Id:smartd.initd,v 1.2 2004/09/17 11:55:28 arjanv Exp $


# For RedHatand cousins:

#chkconfig: 2345 99 01

#以下几项也很关键

#description: Self Monitoring and Reporting Technology (SMART) Daemon

#processname: smartd

可以看到参数 chkconfig2345 90 01

2345级别下为S开头的链接

-为全关闭状态

S后的数字为 90

而非2345(0,1,6)级别下,默认K开头的链接,K开头后的数字为01

单独来查看smartd服务文件,可以看到,其编号为S99 与上面的chkconfig信息一致,如下所示:

[[email protected]~]# ll -th /etc/rc.d/rc3.d/ | grep sma

lrwxrwxrwx1 root root 16 Jan 23  2012S99smartd -> ../init.d/smartd

(2)服务软链接从何而来?

通过chkconfig来更新和查询系统服务的运行级信息,对于在某个启动级别为on的服务进程,则会在对应的启动级别下自动创建相关服务进程的软连接

语法参数选项:

--listname          #显示所有运行级系统服务的运行状态信息(on或off)。如果指定了name,那么只显示指定的服务在不同运行级的状态。

--add             #增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据。

--del             #删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据。

--level 级别号#指定读系统服务要在哪一个执行等级中开启或关毕。

#如:将服务smartd在启动级别里删除

[[email protected]~]# chkconfig --del smartd

[[email protected]~]# chkconfig --list | grep 'smartd'

#查看其链接文件

[[email protected]~]# ls /etc/rc.d/rc3.d/S*sma*

ls:/etc/rc.d/rc3.d/S*sma*: No such file or directory

#再将其服务状态设置为on并且在级别3启动

[[email protected]~]# chkconfig --level 3 smartd on

[[email protected]~]# chkconfig --list | grep smartd

smartd             0:off    1:off    2:on 3:on 4:on 5:on 6:off

#再次查看其服务链接文件:

[[email protected]~]# ls /etc/rc.d/rc3.d/S*sma*

/etc/rc.d/rc3.d/S99smartd

#将其服务号更改再次查看效果

#先将其服务移除

[[email protected]~]# chkconfig --del smartd

#更改参数为88

[[email protected]~]# grep 'chkconfig' /etc/init.d/smartd

#chkconfig: 2345 88 01

#假如启动项

[[email protected]~]# chkconfig --add smartd

[[email protected]~]# chkconfig --level 3 smartd  on

#再来查看其服务链接文件名

[[email protected]~]# ls /etc/rc.d/rc3.d/S*smartd*

/etc/rc.d/rc3.d/S88smartd

5.总结:

在此,我们可以总结以下几点:

(1)RHEL5的启动流程:POST-->加载bootloader(MBR) -->加载内核(初始化硬件)-->/sbin/init(/etc/inittab)

(2)inittab配置文件的总结以及与RHEL6的区别

(3)rc.sysinit配置文件总结

(4)启动级别 chkconfig的使用 以及服务启动脚本中参数# chkconfig: 234599 01的作用 chkconfig参数必须与descriptionprocessname 参数写在一起


三、基于内存的磁盘或内存系统:

ramdisk = initrd

#Linux初始RAM磁盘 (initrd)是在系统引导过程中挂载的一个临时根文件系统,用来支持两阶段的引导过程

rm fs =initramfs

#它在一个叫ramfs的cache实现上加了一层很薄的封装,其他内核开发人员编写了一个改进版tmpfs,这个文件系统上的数据可以写出到交换分区,而且可以设定一个tmpfs装载点的最大尺寸以免耗尽内存。initramfs就是tmpfs的一个应用。

内核先借助于一个虚拟根文件系统,将模块装载进来借助这个模块来挂载真实的根文件系统,因此内核要想启动一个文件系统,必须先要装载根文件系统;而根是可以切换的:Linux启动的时候先装载临时根文件系统,由临时根文件系统来获取模块然后再切换至真正根文件系统

#vmlinuz是可引导的、压缩的内核

[[email protected]~]# ls /boot/vmlinuz-2.6.18-194.el5

/boot/vmlinuz-2.6.18-194.el5

#与vmlinuz配对儿的则是initrd文件,initrd 映像中包含了支持 Linux 系统两阶段引导过程所需要的必要可执行程序和系统文件

[[email protected]~]# ls /boot/initramfs-2.6.32-358.el6.x86_64.img

/boot/initramfs-2.6.32-358.el6.x86_64.img

[[email protected]~]# uname -a

Linuxmode 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686 i686 i386 GNU/Linux

(2)Grub

在Red Hatlinux装载一个系统前,它必须由一个引导装载程序(boot loader,启动管理程序)中的特定指令告诉它去引导系统。这个程序一般是位于系统的主硬盘驱动器或是其他知道如何去开始linux内核驱动器上。

grub分为两段式引导加载:

1.stage:MBR 446                      #为了启动第二段,而第二段则可以显示gurb界面

2 stage/boot/grub                   #加载grub配置,来启动grub界面,

#可以看到此目录下有所启动支持的文件系统以及配置文件,grub启动是依靠其配置文件grub.conf

[[email protected]~]# ls /boot/grub/

device.map     fat_stage1_5  grub.conf         jfs_stage1_5  minix_stage1_5     splash.xpm.gzstage2        vstafs_stage1_5

e2fs_stage1_5  ffs_stage1_5 iso9660_stage1_5  menu.lst      reiserfs_stage1_5 stage1        ufs2_stage1_5  xfs_stage1_5

(3)grub主要功能

·选择启动内核映像或操作系统

·传递参数

e 编辑模式

b 引导启动

·基于密码保护

启用内核映像都要提供密码

编辑内核参数需要提供密码

(4)grub.conf

grub.conf位于/boot/grub/grub.conf

[[email protected]~]# cat /boot/grub/grub.conf

#grub.conf generated by anaconda

#

# Notethat you do not have to rerun grub after making changes to this file

#NOTICE:  You have a /boot partition.  This means that

#          all kernel and initrd paths arerelative to /boot/, eg.

#          root (hd0,0)

#          kernel /vmlinuz-version roroot=/dev/sda3

#          initrd /initrd-[generic-]version.img

#boot=/dev/sda

#设置启动默认的内核映像或系统(有title的信息表示这里的第0个,以此类推,每个title表示可以启动的映像)

default=0

#设置超时时间为5秒

timeout=5

#指定grub启动时的背景图片

splashp_w_picpath=(hd0,0)/grub/splash.xpm.gz

#隐藏菜单

hiddenmenu

#title信息,上面已做解释

titleCentOS (2.6.32-358.el6.x86_64)

#0块硬盘的第0个分区上这里都已hd开头

root (hd0,0)

#在根分区上找到vmlinuz,标示内核文件路径   #ro 以只读方式挂载根文件   #root= 表示内核接收的参数

    kernel /vmlinuz-2.6.32-358.el6.x86_64 roroot=UUID=0a659c34-06db-411a-9047-321792eb46b0rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=usrd_NO_MD crashkernel=auto.UTF-8 rd_NO_LVM rd_NO_DM rhgb quiet

#initrd的版本号一定要与实际匹配

    initrd /initramfs-2.6.32-358.el6.x86_64.img

#grub密码,一般都以MD5加密

    password --md5 xxxxxx

#linux有自带的grub MD5 密码算法生成工具--grub-md5-crypt,如下所示:

[[email protected]~]# grub-md5-crypt

Password:                                     #键入新密码

Retypepassword:                               #确认新密码

$1$cF9iT1$mnSE.A00AJB1m.vbUvBhK0               #生成结果

以上,我们已经生成MD5加密后的密码参数,将grub.conf中的密码参数修改为以下所示即可

password--md5 $1$cF9iT1$mnSE.A00AJB1m.vbUvBhK0

重启Linux,进入grub启动界面的时候提示用户需输入grub密码才可以进入当前title,如下所示

141624567.png

#一般建议将password参数加入到title信息最上面以保安全,修改完成如下所示,可以看到提示,只有键入密码才可以编辑grub

141648666.png

grub是自动访问磁盘分区的而boot是单独分区的,因为实现操作系统之前,grub需要访问这个设备的文件系统。

grub如何识别分区的:对于grub而言所有设备都是hd,分区标示:不同的硬盘使用hd{数字} 表示,如hd0、hd1、hd2等同一个硬盘上的不同分区被识别为{hd0,#}如上面所显示的root (hd0,0)


四、linux服务类型:

(1)守护进程:

·独立守护进程:每个进程自我管理,而在每个级别下都有与否的定义,可以使用chkconfig命令来查看其每个级别的定义

[[email protected]~]# chkconfig --list | head

NetworkManager    0:off    1:off    2:off    3:off    4:off    5:off    6:off

acpid              0:off    1:off    2:on 3:on 4:on 5:on 6:off

anacron            0:off    1:off    2:on 3:on 4:on 5:on 6:off

凡是在对应的级别下,有响应的自我管理的服务 能够在某个级别下关闭或启动的状态都为独立守护进程

·短暂(瞬时)守护进程:

短暂守护进程为触发更新,如有新任务触发时才会使其进行作业,有些进程启动起来半年没人访问几次,严重占用了系统资源,像这类的服务,建议将其做成短暂守护进程

(2)超级守护进程:xinted用于管理瞬时守护进程

#安装xinetd

[[email protected]~]# yum install xinetd

#再来查看chkconfig 列表

[[email protected]~]# chkconfig --list | tail -25

xinetd             0:off    1:off    2:off    3:on 4:on 5:on 6:off

ypbind             0:off    1:off    2:off    3:off    4:off    5:off    6:off

yum-updatesd       0:off    1:off    2:on 3:on 4:on 5:on 6:off

#以下为基于超级进程的服务

xinetdbased services:

    chargen-dgram:     off

    chargen-stream:    off

    cvs:               off

    rsync:            off

#这些服务的名称都有对应的一个脚本文件位于

[[email protected]~]# ls /etc/xinetd.d/

chargen-dgram   daytime-dgram   discard-stream  eklogin      klogin       rmcp           time-dgram

chargen-stream  daytime-stream  echo-dgram      ekrb5-telnet  krb5-telnet rsync          time-stream

cvs             discard-dgram   echo-stream     gssftp        kshell       tcpmux-server

#以rsync为例,如果想让其启动起来则可以

[[email protected] ~]# chkconfig rsync on

#这里没有级别一说

[[email protected]~]# chkconfig --list | tail -8

    discard-dgram:     off

    discard-stream:    off

    echo-dgram:        off

    echo-stream:       off

    rsync:             on

    tcpmux-server:     off

    time-dgram:        off

    time-stream:       off

#总结:瞬时的如果加on 则在超级守护进程列表下为on,如是独立的则在2345级别下为on反之关闭也一样


五、Linux内核模块

Linux系统内核位于/lib/modules/ ,如下所示:

[[email protected]~]# ls /lib/modules/              

2.6.18-194.el5

(1)查看Linux当前使用的内核

#可以通过uname来查看当前内核参数

[[email protected]~]# uname -r

2.6.18-194.el5

(2)内核组成部分:

Linux由3个重要部分组成,分别是

#vmlinuz是可引导的、压缩的内核, Linux能够使用硬盘空间作为虚拟内存,因此得名“vm”。vmlinuz是可执行的Linux内核,它位于/boot/vmlinuz,它一般是一个软链接

/boot/vmlinuz

#Linux初始RAM磁盘(initrd)是在系统引导过程中挂载的一个临时根文件系统,用来支持两阶段的引导过程

/boot/initrd

#在2.6版本的linux内核中,都包含一个压缩过的cpio格式打包文件。当内核启动时,会从这个打包文件中导出文件到内核的rootfs文件系统,然后内核检查rootfs中是否包含有init文件作为PID为1的第一个进程。这个init进程负责启动系统后续的工作,包括定位、挂载"真正的"根文件系统设备

/boot/initramfs

(3)显示内核所加载的模块信息

如果想知道一个模块的依赖关系则可以:

#查看指定模块详细信息

[[email protected]~]# modinfo e1000

filename:      /lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/net/e1000/e1000.ko

version:        7.3.21-k8-NAPI

license:        GPL

description:    Intel(R) PRO/1000 Network Driver

depends:        #依赖的关系模块

parm:

#如何装载模块:

#modprobe<模块名称>

[[email protected]~]# modprobe pcnet32

[[email protected]~]# lsmod | grep 32

pcnet32                33748  0

#卸载模块:

[[email protected]~]# modprobe -r pcnet32

[[email protected]~]# lsmod | grep 32

#插入模块

insmod <块路径>

[[email protected]~]# insmod /lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/net/pcnet32.ko

#提示此模块需要依赖关系模块才可以加载

insmod:error inserting'/lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/net/pcnet32.ko': -1 Unknownsymbol in module

#使用modinfo查看其pcnet32模块信息,可以看到其依赖mii模块,如下所示:

[[email protected]~]# modinfo pcnet32

filename:      /lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/net/pcnet32.ko

license:        GPL

description:    Driver for PCnet32 and PCnetPCI basedethercards

author:         Thomas Bogendoerfer

srcversion:     E10734EFA65F9BAD2B8082A

alias:         pci:v00001023d00002000sv*sd*bc02sc00i*

alias:          pci:v00001022d00002000sv*sd*bc*sc*i*

alias:          pci:v00001022d00002001sv*sd*bc*sc*i*

depends:        mii

vermagic:       2.6.32-358.el6.x86_64 SMP mod_unloadmodversions

parm:           debug:pcnet32 debug level (int)

parm:           max_interrupt_work:pcnet32 maximumevents handled per interrupt (int)

parm:           rx_copybreak:pcnet32 copy breakpointfor copy-only-tiny-frames (int)

parm:           tx_start_pt:pcnet32 transmit startpoint (0-3) (int)

parm:           pcnet32vlb:pcnet32 Vesa local bus(VLB) support (0/1) (int)

parm:           options:pcnet32 initial optionsetting(s) (0-15) (array of int)

parm:           full_duplex:pcnet32 full duplexsetting(s) (1) (array of int)

parm:           homepna:pcnet32 mode for 79C978cards (1 for HomePNA, 0 for Ethernet, default Ethernet (array of int)

#使用modprobe –r 命令将pcnet32模块移除将入mii模块再次加载pcnet32模块

#移除pcnet32模块

[[email protected]~]# modprobe -r pcnet32

#加载mii模块

[[email protected]~]# insmod /lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/net/mii.ko

#查看模块列表

[[email protected]~]# lsmod | grep mii

mii                     5376  0

#再次加载

[[email protected]~]# insmod /lib/modules/2.6.32-358.el6.x86_64/kernel/drivers/net/pcnet32.ko

[[email protected]~]# echo $?

0

[[email protected]~]# lsmod | grep pcnet

pcnet32                33748  0

mii                     5376  1 pcnet32

(4)总结:

·lsmod                         #显示被装载的内核模块

·modinfo                        #查看指定模块的详细信息

·modprobe                       #装载指定模块

·insmod/path/to/module_file    #加载模块

·rmmod mod_name                 #删除不必要的模块

·depmod                         #分析可载入模块的依赖关系

六、Linux之内核参数设定

通过/proc/sys来修改内核的工作特,文件的内容为参数的值;

凡具有写权限的文件,可通过修改其内容来改变内核工作特性,如下所示:

(1)通过修改对应特性文件来修改内核参数

echoNEW_VALUE > /proc/sys/to/some_file

(2)通过命令 sysctl来修改内核参数

sysctl some_file=<NEW_VALUE>

例:打开linux路由功能:

#查看其当前参数

[[email protected] ~]# cat /proc/sys/net/ipv4/ip_forward

0

#修改其参数为1

[[email protected] ~]# echo 1 > /proc/sys/net/ipv4/ip_forward

[[email protected] ~]# cat /proc/sys/net/ipv4/ip_forward

1

#通过sysctlw命令来修改其内核特性参数

#我们知道ip_forward的绝对路径为/proc/sys/net/ipv4/ip_forward 但这里参数名需要将路径的/ 更换为.如下所示

[[email protected]~]# sysctl -w net.ipv4.ip_forward=0

net.ipv4.ip_forward = 0

[[email protected] ~]# cat /proc/sys/net/ipv4/ip_forward

0

(5)使用sysctl -a查看所有内核参数

[r[email protected] ~]# sysctl -a

#sysctl配置文件位于/etc/sysctl.conf

[[email protected] ~]# grep -v "^#" /etc/sysctl.conf | grep -v"^$"

net.ipv4.ip_forward = 0

net.ipv4.conf.default.rp_filter = 1

net.ipv4.conf.default.accept_source_route = 0

kernel.sysrq = 0

kernel.core_uses_pid = 1

net.ipv4.tcp_syncookies = 1

net.bridge.bridge-nf-call-ip6tables = 0

net.bridge.bridge-nf-call-iptables = 0

net.bridge.bridge-nf-call-arptables = 0

kernel.msgmnb = 65536

kernel.msgmax = 65536

kernel.shmmax = 68719476736

kernel.shmall = 4294967296

(6)重新加载配置文件:

#可以使用-p参数来重新加载配置文件

[[email protected] ~]# sysctl -p

[[email protected] ~]# cat /proc/sys/net/ipv4/icmp_echo_ignore_all

0

[[email protected] ~]# echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all

[[email protected] ~]# cat /proc/sys/net/ipv4/icmp_echo_ignore_all

1

[[email protected] ~]# sysctl -p

[[email protected] ~]# cat /proc/sys/net/ipv4/icmp_echo_ignore_all

1

(7)查看Linux相关硬件信息

#显示当前主机所有pci控制器

[[email protected]~]# lspci

#查看USB相关信息

[[email protected]~]# lsusb

#查看CPU相关信息

[[email protected]~]# lscpu

#显示块设备相关信息

[[email protected]~]# lsblk

#用来显示开机信息

[[email protected]~]# dmesg