V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
skinny
V2EX  ›  Linux

debian 系统下,有没有简单的办法检测指定网卡配置是 dhcp/static/manual?

  •  
  •   skinny · Oct 24, 2021 · 3566 views
    This topic created in 1653 days ago, the information mentioned may be changed or developed.

    我想到的是通过查找网卡配置文件 /etc/network/interfaces 的内容来判定,但是网卡配置可能写到了 /etc/network/interfaces.d 下的某个文件,而且配置文件内容的一行要是被拆成了奇形怪状的好几行怎么办?虽然多写几句 bash script 也能搞定,但是想问问有没有别的办法。

    那个 ifquery 命令我试过,没有用,按 help 输出和 manpage 操作,要么输出为空,要么根本不能正常解析它自己的选项,连示例都不能运行。

    9 replies    2021-10-24 16:14:23 +08:00
    Ayahuasec
        1
    Ayahuasec  
       Oct 24, 2021
    dhcp 和 static/manual 好像可以通过 ip addr 里每个网卡的 ip 的那一行看有没有 dynamic 来确定
    不过我也不知道怎么把 manual 和 static 区别开来
    Remember
        2
    Remember  
       Oct 24, 2021
    ps -auxf , check if isc-dhcp process exist.
    skinny
        3
    skinny  
    OP
       Oct 24, 2021   ❤️ 1
    @Ayahuasec 有的 VPS 环境即便是 dhcp 也没有 dynamic……
    skinny
        4
    skinny  
    OP
       Oct 24, 2021
    @Remember 嗯,查 dhcp 客户端进程信息也是一个检查是不是 dhcp 的办法
    zyq2280539
        5
    zyq2280539  
       Oct 24, 2021
    debian 下不知道,我知道 ubuntu 下做这些很容易
    ruidoBlanco
        6
    ruidoBlanco  
       Oct 24, 2021
    一句话的事儿。

    awk '/iface eth0/' /etc/network/{interfaces,interfaces.d/*}
    Arnie97
        7
    Arnie97  
       Oct 24, 2021   ❤️ 1
    这个问题的前提是系统管理员一定用 ifupdown 体系设置的网络么…

    作为只用 systemd networkd 并把 /etc/network 整个删了的 Debian 用户,我建议用一楼说的判定逻辑:

    $ ip a s eth0 dynamic
    liuxu
        8
    liuxu  
       Oct 24, 2021
    $ journalctl -u NetworkManager --no-tail |grep dhclient
    liuxu
        9
    liuxu  
       Oct 24, 2021
    @liuxu 不过有的 vps 没有用 NetworkManager.service
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1323 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 16:37 · PVG 00:37 · LAX 09:37 · JFK 12:37
    ♥ Do have faith in what you're doing.