当我跑步时more 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
我使用 wifi。如何知道我的 IP 是静态的还是动态的?运行时ip addr
我得到
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether e0:d5:5e:78:64:ef brd ff:ff:ff:ff:ff:ff
3: wlx00e02d051a2d: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:e0:2d:05:1a:2d brd ff:ff:ff:ff:ff:ff
inet 192.168.43.87/24 brd 192.168.43.255 scope global dynamic noprefixroute wlx00e02d051a2d
valid_lft 2283sec preferred_lft 2283sec
inet6 2401:4900:4c6a:ba87:2348:3cc3:5ff9:337/64 scope global noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::5cde:b91:60ef:2ee1/64 scope link noprefixroute
valid_lft forever preferred_lft forever
我认为 ipv4 是动态的,那么 ipv6 呢?它是静态的吗?
答案1
如果您从终端窗口运行,输出应该会告诉您。输出中ip addr
以 开头的行会告诉您。动态会显示,但静态会为空白。此外,如果是动态的,则包含和的行将显示剩余时间。我在下面放了一些例子。inet
valid_lft
preferred_lft
DHCP 或动态 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
希望这可以帮助!
答案2
您无法通过工作接口本身找出静态与否。dhcp 与否由某些配置脚本配置。在 ubuntu 上,IP 通常可以通过启动脚本或网络管理器守护程序或最新的 netplan 机器配置。
- 通过启动脚本,你可以检出 /etc/interfaces 或 /etc/interfaces.d/*** 文件
- 通过 NetworkManager 守护进程,您可以使用命令 nwcli 来检查配置。
- 通过 netplan 机器,检查 /etc/netplan/* 配置文件。