linux - 如何知道哪个网络接口用于私有 ip?

我需要为我的 linux(ubuntu) 服务器私有 ip。

所以我检查了 ip add 命令。

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: enp35s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether d0:50:99:dd:49:43 brd ff:ff:ff:ff:ff:ff
    inet xxx.xxx.xxx.xxx/27 brd xxx.xxx.xxx.xxx scope global enp35s0
       valid_lft forever preferred_lft forever
    inet6 xxx::xxx:xxx:xxx:xxx/64 scope link
       valid_lft forever preferred_lft forever
3: enp36s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether d0:50:99:dd:49:44 brd ff:ff:ff:ff:ff:ff
4: br-cf41f234c44d: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:28:48:9c:52 brd ff:ff:ff:ff:ff:ff
    inet 172.23.0.1/16 brd 172.23.255.255 scope global br-cf41f234c44d
       valid_lft forever preferred_lft forever
    inet6 fe80::42:28ff:fe48:9c52/64 scope link
       valid_lft forever preferred_lft forever
5: br-7ad37758b346: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:cd:ca:cb:41 brd ff:ff:ff:ff:ff:ff
    inet 172.22.0.1/16 brd 172.22.255.255 scope global br-7ad37758b346
       valid_lft forever preferred_lft forever
    inet6 fe80::42:cdff:feca:cb41/64 scope link
       valid_lft forever preferred_lft forever
6: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:dd:5b:04:dd brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
7: br-031ff8fec9c6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:f9:58:b0:b8 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 brd 172.18.255.255 scope global br-031ff8fec9c6
       valid_lft forever preferred_lft forever
    inet6 fe80::42:f9ff:fe58:b0b8/64 scope link
       valid_lft forever preferred_lft forever
11: vethd7f8fb1@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-7ad37758b346 state UP group default
    link/ether a2:30:b9:fd:84:0a brd ff:ff:ff:ff:ff:ff link-netnsid 1
    inet6 fe80::a030:b9ff:fefd:840a/64 scope link
       valid_lft forever preferred_lft forever
99: veth9aeb459@if98: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-cf41f234c44d state UP group default
    link/ether 3a:6b:63:02:b9:f6 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::386b:63ff:fe02:b9f6/64 scope link
       valid_lft forever preferred_lft forever
189: vethf22836b@if188: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-7ad37758b346 state UP group default
    link/ether f6:b1:0d:40:18:44 brd ff:ff:ff:ff:ff:ff link-netnsid 2
    inet6 fe80::f4b1:dff:fe40:1844/64 scope link
       valid_lft forever preferred_lft forever

我可以知道 enp35s0 是关于公共 IP 并且

数字 4 到 189 是关于 Docker。

所以我认为第三个接口 enp36s0 用于私有 IP.

但我不能保证。我该如何检查?

回答1

您可以使用 nmcli device status 来检查您的设备、类型、状态和连接。

然后您可以使用(像您一样)ip address,您可以使用 xxx.xxx.xxx.xxx:xxx/27 在inet之前

相似文章