• RPM 与 DPKG 使用


    前言

    上篇文章中,我们介绍了 RPM 和 DPKG 的由来及其功能。这篇文章,我们着重介绍下这两种软件管理器的使用。

    顺藤摸瓜

    在嵌入式开发中,我们经常会有研究某个命令源码的需求。比如想知道 ifconfig 的实现原理。
    step 1,查找命令所在位置

    # whereis ifconfig
    ifconfig: /usr/sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz
    
    • 1
    • 2

    step 2,查找二进制文件所属的 RPM 包

    # rpm -qf /usr/sbin/ifconfig
    net-tools-2.0-0.25.20131004git.el7.x86_64
    
    • 1
    • 2

    可知,ifconfig 是 net-tools 工具集中的一个子工具。想要分析 ifconfig 源码,只要下载 net-tools 源码就可以了。

    进阶

    1、查看软件包文件列表

    # rpm -ql net-tools
    /bin/netstat
    /sbin/arp
    /sbin/ether-wake
    /sbin/ifconfig
    /sbin/ipmaddr
    /sbin/iptunnel
    /sbin/mii-diag
    /sbin/mii-tool
    /sbin/nameif
    /sbin/plipconfig
    /sbin/route
    /sbin/slattach
    /usr/lib/systemd/system/arp-ethers.service
    /usr/share/doc/net-tools-2.0
    /usr/share/doc/net-tools-2.0/COPYING
    /usr/share/locale/cs/LC_MESSAGES/net-tools.mo
    /usr/share/locale/de/LC_MESSAGES/net-tools.mo
    /usr/share/locale/et_EE/LC_MESSAGES/net-tools.mo
    /usr/share/locale/fr/LC_MESSAGES/net-tools.mo
    /usr/share/locale/pt_BR/LC_MESSAGES/net-tools.mo
    /usr/share/man/de/man5/ethers.5.gz
    /usr/share/man/de/man8/arp.8.gz
    /usr/share/man/de/man8/ifconfig.8.gz
    /usr/share/man/de/man8/netstat.8.gz
    /usr/share/man/de/man8/plipconfig.8.gz
    /usr/share/man/de/man8/route.8.gz
    /usr/share/man/de/man8/slattach.8.gz
    /usr/share/man/fr/man5/ethers.5.gz
    /usr/share/man/fr/man8/arp.8.gz
    /usr/share/man/fr/man8/ifconfig.8.gz
    /usr/share/man/fr/man8/netstat.8.gz
    /usr/share/man/fr/man8/plipconfig.8.gz
    /usr/share/man/fr/man8/route.8.gz
    /usr/share/man/fr/man8/slattach.8.gz
    /usr/share/man/man5/ethers.5.gz
    /usr/share/man/man8/arp.8.gz
    /usr/share/man/man8/ether-wake.8.gz
    /usr/share/man/man8/ifconfig.8.gz
    /usr/share/man/man8/ipmaddr.8.gz
    /usr/share/man/man8/iptunnel.8.gz
    /usr/share/man/man8/mii-diag.8.gz
    /usr/share/man/man8/mii-tool.8.gz
    /usr/share/man/man8/nameif.8.gz
    /usr/share/man/man8/netstat.8.gz
    /usr/share/man/man8/plipconfig.8.gz
    /usr/share/man/man8/route.8.gz
    /usr/share/man/man8/slattach.8.gz
    /usr/share/man/pt/man8/arp.8.gz
    /usr/share/man/pt/man8/ifconfig.8.gz
    /usr/share/man/pt/man8/netstat.8.gz
    /usr/share/man/pt/man8/route.8.gz
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53

    rpm 软件包通常采用默认路径安装,各安装文件会分门别类安装在适当的目录文件下。使用 rmp -ql 软件包名 可以查询到已安装软件包中包含的所有文件及各自安装路径。我们可以只过滤 bin 文件

    # rpm -ql net-tools | grep bin
    /bin/netstat
    /sbin/arp
    /sbin/ether-wake
    /sbin/ifconfig
    /sbin/ipmaddr
    /sbin/iptunnel
    /sbin/mii-diag
    /sbin/mii-tool
    /sbin/nameif
    /sbin/plipconfig
    /sbin/route
    /sbin/slattach
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    二、查看软件包的详细信息

    # rpm -qi net-tools
    Name        : net-tools
    Version     : 2.0
    Release     : 0.25.20131004git.el7
    Architecture: x86_64
    Install Date: Thu 03 Sep 2020 11:49:41 AM CST
    Group       : System Environment/Base
    Size        : 938978
    License     : GPLv2+
    Signature   : RSA/SHA256, Fri 23 Aug 2019 05:36:04 AM CST, Key ID 24c6a8a7f4a80eb5
    Source RPM  : net-tools-2.0-0.25.20131004git.el7.src.rpm
    Build Date  : Fri 09 Aug 2019 09:10:26 AM CST
    Build Host  : x86-02.bsys.centos.org
    Relocations : (not relocatable)
    Packager    : CentOS BuildSystem <http://bugs.centos.org>
    Vendor      : CentOS
    URL         : http://sourceforge.net/projects/net-tools/
    Summary     : Basic networking tools
    Description :
    The net-tools package contains basic networking tools,
    including ifconfig, netstat, route, and others.
    Most of them are obsolete. For replacement check iproute package.
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    三、查询软件包的依赖关系

    # rpm -qR net-tools
    /bin/sh
    libc.so.6()(64bit)
    libc.so.6(GLIBC_2.14)(64bit)
    libc.so.6(GLIBC_2.2.5)(64bit)
    libc.so.6(GLIBC_2.3)(64bit)
    libc.so.6(GLIBC_2.3.4)(64bit)
    libc.so.6(GLIBC_2.4)(64bit)
    libselinux.so.1()(64bit)
    rpmlib(CompressedFileNames) <= 3.0.4-1
    rpmlib(FileDigests) <= 4.6.0-1
    rpmlib(PayloadFilesHavePrefix) <= 4.0-1
    rtld(GNU_HASH)
    systemd-units
    rpmlib(PayloadIsXz) <= 5.2-1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    DPKG

    dpkg 也类似
    一、查询软件包文件列表

    $ dpkg -L net-tools | grep bin
    /bin
    /bin/netstat
    /sbin
    /sbin/ifconfig
    /sbin/ipmaddr
    /sbin/iptunnel
    /sbin/mii-tool
    /sbin/nameif
    /sbin/plipconfig
    /sbin/rarp
    /sbin/route
    /sbin/slattach
    /usr/sbin
    /usr/sbin/arp
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    二、查看软件包(已安装)的详细信息

    $ dpkg -s net-tools
    Package: net-tools
    Status: install ok installed
    Priority: important
    Section: net
    Installed-Size: 844
    Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
    Architecture: amd64
    Multi-Arch: foreign
    Version: 1.60+git20180626.aebd88e-1ubuntu1
    Depends: libc6 (>= 2.14), libselinux1 (>= 1.32)
    Description: NET-3 networking toolkit
     This package includes the important tools for controlling the network
     subsystem of the Linux kernel.  This includes arp, ifconfig, netstat,
     rarp, nameif and route.  Additionally, this package contains utilities
     relating to particular network hardware types (plipconfig, slattach,
     mii-tool) and advanced aspects of IP configuration (iptunnel, ipmaddr).
     .
     In the upstream package 'hostname' and friends are included. Those are
     not installed by this package, since there is a special "hostname*.deb".
    Homepage: http://sourceforge.net/projects/net-tools/
    Original-Maintainer: net-tools Team <team+net-tools@tracker.debian.org>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
  • 相关阅读:
    如何在Ubuntu部署Emlog,并将本地博客发布至公网可远程访问
    【k8s】(五)kubernetes1.29.4离线部署之-初始化第一个控制平面
    制糖行业脱色技术A30MP树脂材料
    vcruntime140.dll丢失的解决方法?教你如何修复好dll文件
    正则表达式高阶(一)
    torch.clamp
    网络原理之封装和分用,网络编程套接字
    Centos搭建k8s集群
    说透缓存一致性与内存屏障
    C++设计模式-适配器(Adapter)
  • 原文地址:https://blog.csdn.net/lyndon_li/article/details/126715976