谷姐:我们都是谷歌迷
We are all Google fans

Linux上怎样知道一个网卡的ip是静态的还是DHCP?-zxxx

Rate this post

通过什么命令可以查询?

热议
2楼 周星辰 2022-7-20 22:31:40

直接看网卡配置

3楼 zxxx 2022-7-20 22:32:43

直接看网卡配置

想通过脚本实现,不同系统的网卡配置还不一样吧?

4楼 spr1ng 2022-7-20 22:34:41

nmclinmtui

5楼 周星辰 2022-7-20 22:37:01

想通过脚本实现,不同系统的网卡配置还不一样吧?

是不一样,但一般小鸡都是静态啊

6楼 zxxx 2022-7-20 22:37:52

nmclinmtui

这个可以做到,但是有的机器上面没有这个程序,又不方便安装的话没法用

修改配置

    nano /etc/NetworkManager/NetworkManager.conf

    [main]plugins=ifupdown,keyfile

    [ifupdown]managed=true # false

重启

    systemctl restart NetworkManager

DHCP

    root@debian:~# nmcli c
    NAME UUID TYPE DEVICE
    Wired connection 125e9b32c-6a5a-3d84-a3bd-5447cc368601ethernetenp1s0
    root@debian:~# nmcli c show 25e9b32c-6a5a-3d84-a3bd-5447cc368601 | grep ipv4.method
    ipv4.method: auto

静态

    root@debian:~# nmcli c
    NAME UUID TYPE DEVICE
    eth0 8c0715ef-48ed-400d-9220-7e68c99c6a96etherneteth0
    Ifupdown (eth0)681b428f-beaf-8932-dce4-687ed5bae28eethernet--
    Ifupdown (eth1)7b635ed6-2640-7ad8-675d-744db12dd9faethernet--
    root@debian:~# nmcli c show 8c0715ef-48ed-400d-9220-7e68c99c6a96 | grep ipv4.method
    ipv4.method: manual

grep -IR "DHCPOFFER" /var/log/*

    grep -IR "DHCPOFFER" /var/log/*
    /var/log/daemon.logsd-160051 dhclient[353]: DHCPOFFER of 1.2.3.71 from 1.2.3.1
    /var/log/daemon.logsd-160051 sh[328]: DHCPOFFER of 1.2.3.71 from 1.2.3.1
    /var/log/daemon.logsd-160051 dhclient[425]: DHCPOFFER of 1.2.3.71 from 1.2.3.1
    /var/log/daemon.logsd-160051 dhclient[364]: DHCPOFFER of 1.2.3.71 from 1.2.3.1
    /var/log/daemon.logsd-160051 sh[332]: DHCPOFFER of 1.2.3.71 from 1.2.3.1

9楼 崽崽 昨天15:11

cd /etc/network/

vi 网卡名 看是不是dhcp

10楼 zxxx 昨天19:17

cd /etc/network/

vi 网卡名 看是不是dhcp

可能有的系统没有这个文件吧?

12楼 meta 昨天20:10

看启动日志

13楼 sdqu 昨天20:17

如果一定要脚本的话,
1.获得本机ip
2. 在/etc下面grep这个ip
方法笨点,不过肯定好用

15楼 Lish 昨天20:47

ip addr 看看网卡信息有没有 IP 信息不就知道了!

    # ifconfig
    enp2s1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>mtu 1500
    inet 192.168.1.28netmask 255.255.255.0broadcast 192.168.1.255
    ether 00:0c:29:46:9f:7etxqueuelen 1000(Ethernet)

    enp2s4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>mtu 1500
    inet 192.168.1.30netmask 255.255.255.0broadcast 192.168.1.255
    ether 00:0c:29:46:9f:88txqueuelen 1000(Ethernet)

    ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>mtu 1500
    inet6 240e:33d:32a:ca30:20c:29ff:fe46:9f7eprefixlen 64scopeid 0x0<global>
    inet6 fe80::20c:29ff:fe46:9f7eprefixlen 64scopeid 0x20<link>
    ether 00:0c:29:46:9f:7etxqueuelen 1000(Ethernet)
    RX packets 477893bytes 390537819 (372.4 MiB)
    RX errors 0dropped 0overruns 0frame 0
    TX packets 185552bytes 24391768 (23.2 MiB)
    TX errors 0dropped 0 overruns 0carrier 0collisions 0

    ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>mtu 1500
    inet6 240e:33d:32a:ca30:20c:29ff:fe46:9f88prefixlen 64scopeid 0x0<global>
    inet6 fe80::20c:29ff:fe46:9f88prefixlen 64scopeid 0x20<link>
    ether 00:0c:29:46:9f:88txqueuelen 1000(Ethernet)
    RX packets 65754bytes 9041989 (8.6 MiB)
    RX errors 0dropped 0overruns 0frame 0
    TX packets 4653bytes 400726 (391.3 KiB)
    TX errors 0dropped 0 overruns 0carrier 0collisions 0

    lo: flags=73<UP,LOOPBACK,RUNNING>mtu 65536
    inet 127.0.0.1netmask 255.0.0.0
    inet6 ::1prefixlen 128scopeid 0x10<host>
    looptxqueuelen 1000(Local Loopback)
    RX packets 20bytes 2690 (2.6 KiB)
    RX errors 0dropped 0overruns 0frame 0
    TX packets 20bytes 2690 (2.6 KiB)
    TX errors 0dropped 0 overruns 0carrier 0collisions 0

17楼 Lish 昨天20:52

scope global dynamic

不是写着动态的吗?应该就是 DHCP了

你可以看下网卡配置文件

18楼 Do. 昨天20:53

cat /etc/network/interfaces

这个也是动态IP的,没有显示为 scope global dynamic

    # cat /etc/network/interfaces
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).

    source /etc/network/interfaces.d/*

    # The loopback network interface
    auto lo
    iface lo inet loopback

    # The primary network interface
    allow-hotplug enp1s0
    iface enp1s0 inet dhcp

    scope global dynamic enp0s25 动态IP地址
    scope global enp0s25 静态IP地址

    valid_lft ??????sec preferred_lft ??????sec 动态IP地址
    valid_lft forever preferred_lft forever 静态IP地址

动态IP地址

    $ ip addr
    2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 40:8d:5c:4f:12:03 brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    inet 10.0.0.100/24 brd 10.0.0.255 scope global dynamic noprefixroute eth0
    valid_lft 28899sec preferred_lft 28899sec

静态IP地址

    $ ip addr
    4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether bc:5f:f4:79:66:fe brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.220/24 brd 10.0.0.255 scope global bond0
    valid_lft forever preferred_lft forever

22楼 Residual 2分钟前

cat /etc/network/interfaces

正解

申明:本文内容由网友收集分享,仅供学习参考使用。如文中内容侵犯到您的利益,请在文章下方留言,本站会第一时间进行处理。

未经谷姐允许不得转载:谷姐靓号网 » Linux上怎样知道一个网卡的ip是静态的还是DHCP?-zxxx
分享到: 生成海报

热门文章

评论 抢沙发

评论前必须登录!

立即登录   注册

买Google Voice认准【谷姐靓号网】

Google Voice靓号列表Google Voice自助购买
切换注册

登录

点击按钮进行验证

忘记密码 ?

切换登录

注册

我们将发送一封验证邮件至你的邮箱, 请正确填写以完成账号注册和激活

点击按钮进行验证