How to Query the Network Adapter Name of a Cloud Server?

24-01-2024 02:25:41

When setting up network properties for a cloud server, it is essential to first determine the name of the network adapter currently in use. This is particularly relevant in scenarios such as adding a private network, configuring an IPv6 address, or restoring from a backup, where network property settings are required. For Linux operating systems, using the IP tool is the most convenient method to find out the network adapter name, while the FreeBSD system utilizes ifconfig. The following details the usage of these tools.

Linux System

If remote access to the cloud server is not possible, one can use the console to enter the system and execute the following command to query network adapter information.

# ip addr show

If only a public network is available, and no private network exists, the output will resemble the following.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:00:5e:00:53:10 brd ff:ff:ff:ff:ff:ff

The above result indicates that the network adapter name is enp1s0, with the MAC address being 00:00:5e:00:53:10. The loopback adapter can be disregarded in this context.

Here is another example from a different cloud server, which includes one public network and two private networks.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:00:5e:00:53:20 brd ff:ff:ff:ff:ff:ff
3: enp6s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:00:5e:00:53:fe brd ff:ff:ff:ff:ff:ff
4: enp7s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:00:5e:00:53:ff brd ff:ff:ff:ff:ff:ff

The result shows that the adapter name for the public network is enp1s0, with a MAC address of 00:00:5e:00:53:20; the first private network's adapter name is enp6s0, with a MAC address of 00:00:5e:00:53:fe; and the second private network's adapter name is enp7s0, with a MAC address of 00:00:5e:00:53:ff.

FreeBSD System

On a FreeBSD system, execute the ifconfig command as root.

# ifconfig

The output will be similar to the following.

vtnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
    options=6c07bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,LRO,VLAN_HWTSO,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
    ether 56:00:03:71:b0:2b
    inet 149.28.59.190 netmask 0xfffffe00 broadcast 149.28.59.255
    media: Ethernet 10Gbase-T <full-duplex>
    status: active
    nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
vtnet1: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500
    options=6800bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
    ether 5a:00:03:71:b0:2b
    media: Ethernet 10Gbase-T <full-duplex>
    status: active
    nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
    options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
    inet6 ::1 prefixlen 128
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
    inet 127.0.0.1 netmask 0xff000000
    groups: lo
    nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>

In the example above, the adapter name for the public network is vtnet0, and for the private network, it is vtnet1.