Distributions
› Ubuntu
› Fedora
› CentOS
中文资源站
› 网易开源镜像站
skinny
V2EX  ›  Linux

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

  •  
  •   skinny · Oct 24, 2021 · 3986 views
    This topic created in 1839 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
    Ayahuasec
    Oct 24, 2021
    1
    dhcp 和 static/manual 好像可以通过 ip addr 里每个网卡的 ip 的那一行看有没有 dynamic 来确定
    不过我也不知道怎么把 manual 和 static 区别开来
    Remember
    Remember
    Oct 24, 2021
    2
    ps -auxf , check if isc-dhcp process exist.
    skinny
    skinny
    OP
    Oct 24, 2021❤️1
    3
    @Ayahuasec 有的 VPS 环境即便是 dhcp 也没有 dynamic……
    skinny
    skinny
    OP
    Oct 24, 2021
    4
    @Remember 嗯,查 dhcp 客户端进程信息也是一个检查是不是 dhcp 的办法
    zyq2280539
    zyq2280539
    Oct 24, 2021
    5
    debian 下不知道,我知道 ubuntu 下做这些很容易
    ruidoBlanco
    ruidoBlanco
    Oct 24, 2021
    6
    一句话的事儿。

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

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

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