`
webcenterol
  • 浏览: 951070 次
文章分类
社区版块
存档分类
最新评论

IP Address Management-----ifconfig + ip address

 
阅读更多

AppendixC.IP Address Management

A machine which can access Internet resources has an IP address, whether that IP address is a public address or a private address hidden behind an SNAT router [44]. With the increasingly common use of linux machines as servers, desktops, and embedded devices and with changing network topologies and re-addressing, the need to be able to determine the current IP address of a machine and modify that address has consequently become a common need.

I assume in this chapter that the reader has some familiarity with CIDR addressing and netmasks. If any of these concepts are unfamiliar, or the reader would like to brush up, I suggest a visit to some of the links which can be found in SectionI.1.3, “General IP Networking Resources”.

We'll begin our tour of the utilities for observing, changing, removing, and adding IP addresses to network devices with ifconfig, the traditional utility for IP management. We will also examine the newer and more flexible ip address, a key part of the iproute2 package.



[44] I'm sure somebody will be glad to nitpick here and tell me that s/he has a machine connected to the Internet which uses SNA, DecNET, IPX, or NetBEUI to connect to another host which actually does speak IP, thus proving that not every host which has access to the Internet is actually directly speaking IP. Another example is doubtless, wireless devices, such as telephones. Here, I'll concern myself with the majority case.

C.1.ifconfig

The venerable ifconfig is available on almost every unix I have encountered. In addition to reporting the IP addressing and usage statistics of an optionally specified interface, ifconfig can modify an interface's MTU and other flags and interface characteristics, bring up an interface and bring down an interface. This tool is the primary tool for manipulation of IP addressing on many linux distributions.

C.1.1.Displaying interface information with ifconfig

In its simplest use, ifconfig merely reports the IP interface and relevant statistics. For Ethernet devices, the hardware address, IP address, broadcast, netmask, IP interface states, and some other additional information is presented. For other interfaces, different information may be presented to the user, but the basic summary of IP addressing information will always be available. Be sure to read SectionC.1.4, “Reading ifconfig output” also.

ExampleC.1.Viewing interface information with ifconfig

[root@tristan]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:80:C8:F8:4A:51
          inet addr:192.168.99.35  Bcast:192.168.99.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:190312 errors:0 dropped:0 overruns:0 frame:0
          TX packets:86955 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:30701229 (29.2 Mb)  TX bytes:7878951 (7.5 Mb)
          Interrupt:9 Base address:0x5000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:306 errors:0 dropped:0 overruns:0 frame:0
          TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:29504 (28.8 Kb)  TX bytes:29504 (28.8 Kb)
          

It is fairly common to specify the name of an interface as an argument to ifconfig, which will restrict the output to the named interface. This is the only way to retrieve information from ifconfig about link layer devices which are available, but not in an UP state. See also SectionB.3, “ip link and SectionC.2, “ip address.

There are many other options available to the ifconfig command to control addressing and interface state. Contrary to the behaviour of most other standard unix command line utilities which operate on arguments and options, ifconfig operates on a grammar after the specified interface. Subsequent examples will demonstrate how this differs from conventional modern unix tools.

C.1.2.Bringing down an interface with ifconfig

Let's look at some simple operations you can perform with ifconfig. Occasionally, you will need to bring down a network interface. For an introduction to this and its side effects, see Example1.6, “Bringing down a network interface with ifconfig and the list of side effects.

ExampleC.2.Bringing down an interface with ifconfig

[root@tristan]# ifconfig eth0 down
[root@tristan]# ifconfig
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:306 errors:0 dropped:0 overruns:0 frame:0
          TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:29504 (28.8 Kb)  TX bytes:29504 (28.8 Kb)
          

Naturally, when we view the active interfaces after downing the first Ethernet interface, we see that eth0 is no longer present. This is exactly what we had intended. Now to bring up the interface, we'll need the IP address and netmask information.

C.1.3.Bringing up an interface with ifconfig

Bringing up an interface is slightly more complex than bringing an interface down because you need to have the IP addressing information handy in order to bring the interface back. For an introduction to the side effects of bringing up an IP address on an interface, see Example1.7, “Bringing up an Ethernet interface with ifconfig and the list of side effects.

ExampleC.3.Bringing up an interface with ifconfig

[root@tristan]# ifconfig eth0 192.168.99.35 netmask 255.255.255.0 up
[root@tristan]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:80:C8:F8:4A:51
          inet addr:192.168.99.35  Bcast:192.168.99.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:190312 errors:0 dropped:0 overruns:0 frame:0
          TX packets:86955 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:30701229 (29.2 Mb)  TX bytes:7878951 (7.5 Mb)
          Interrupt:9 Base address:0x5000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:306 errors:0 dropped:0 overruns:0 frame:0
          TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:29504 (28.8 Kb)  TX bytes:29504 (28.8 Kb)
          

C.1.4.Reading ifconfig output

The above operations are the simple operations one can perform with ifconfig. Let's examine the output a bit more closely now, with an eye toward the other flags and settings we can manually twiddle.

The first line of each interface definition represents data which cannot be altered with ifconfig. If we consider only Ethernet interfaces, the link encapsulation will always say "Ethernet", and the hardware address cannot be altered with ifconfig [45]. Below this, one line summarizes the IP information associated with this logical interface.

The third line indicates the current states of the interface, maximum transmission unit, and the metric for this interface. Possible state options are itemized in the table below. The maximimum transmission unit is routinely set to 1500 bytes for Ethernet and promptly forgotten. MTU suddenly becomes important when IP packets are forwarded across a link layer which requires a smaller MTU. Thus ifconfig provides a method to set the MTU on an interface. For more on MTU, see Section4.10.1, “MTU, MSS, and ICMP”. The remaining lines of output are taken from the Ethernet driver. See further discussion of these statistics below.

C.1.5.Changing MTU with ifconfig

It is a rare occasion on which the MTU needs to be changed, but when it needs to be changed, nothing else will suffice. Here's an example of setting the MTU on an interface to 1412 bytes.

ExampleC.4.Changing MTU with ifconfig

[root@tristan]# ifconfig eth0 mtu 1412
[root@tristan]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:80:C8:F8:4A:51
          inet addr:192.168.99.35  Bcast:192.168.99.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1412  Metric:1
          RX packets:190312 errors:0 dropped:0 overruns:0 frame:0
          TX packets:86955 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:30701229 (29.2 Mb)  TX bytes:7878951 (7.5 Mb)
          Interrupt:9 Base address:0x5000
          

C.1.6.Changing device flags with ifconfig

Every device on a system has flags which indicate the state the device may be in. These flags can be altered by the ifconfig utility.

TableC.1.Interface Flags

Flag Description
UP device is functioning
BROADCAST device can send traffic to all hosts on the link
RUNNING ???
MULTICAST device can perform and receive multicast packets
ALLMULTI device receives all multicast packets on the link
PROMISC device receives all traffic on the link

I cannot confidently recommend believing the flags as reported by ifconfig output. Attestations from others and experimentation has proven to me that these flags (particularly the PROMISC flag) do not accurately represent the state of the device as reported in log files (by the kernel) and by the ip link show utility.

This does not mean, however, that the flags cannot be set with the ifconfig utility. Manipulation of the flags on an interface operates according to a peculiar grammar. To set the PROMISC flag, one issues a command with the promisc option from the grammar. If one wishes to remove the PROMISC flag from an interface, the -promisc option is required.

ExampleC.5.Setting interface flags with ifconfig

[root@tristan]# ifconfig eth0 promisc
[root@tristan]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:80:C8:F8:4A:51
          inet addr:192.168.99.35  Bcast:192.168.99.255  Mask:255.255.255.0
          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1412  Metric:1
          RX packets:190312 errors:0 dropped:0 overruns:0 frame:0
          TX packets:86955 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:30701229 (29.2 Mb)  TX bytes:7878951 (7.5 Mb)
          Interrupt:9 Base address:0x5000
[root@tristan]# ifconfig eth0 -promisc
[root@tristan]# ifconfig eth0 -arp
[root@tristan]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:80:C8:F8:4A:51
          inet addr:192.168.99.35  Bcast:192.168.99.255  Mask:255.255.255.0
          UP BROADCAST RUNNING NOARP MULTICAST  MTU:1412  Metric:1
          RX packets:190312 errors:0 dropped:0 overruns:0 frame:0
          TX packets:86955 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:30701229 (29.2 Mb)  TX bytes:7878951 (7.5 Mb)
          Interrupt:9 Base address:0x5000
[root@tristan]# ifconfig eth0 arp
          

C.1.7.General remarks about ifconfig

Since linux 2.0 the kernel has supported multiple IP addresses hosted on the same device. By suffixing the real interface name with a colon and a non-negative integer, you can bring up additional IP adresses on the same device. Example alias names are eth0:0 eth0:7. See Section9.4, “Multiple IPs on an Interface” for further details.

As you can see, ifconfig is both a powerful and idiosyncratic tool for controlling network interfaces and devices.



[45] If you need to change the hardware address of an Ethernet interface, you have a strange need, but you can accomplish this using the ip link set address command.

C.2.ip address

Part of the iproute2 suite, ip address can list the IP addresses affiliated with interfaces, add IPs, delete IPs, and remove all IPs on a given device.

C.2.1.Displaying interface information with ip address show

The first thing you'll want to do is list the IPs on your machine. The ip address tool will display IP (and terse encapsulation information) when invoked with the show verb. To specify that you wish to see the IP information for only one interface, you can add dev <device-name>

ExampleC.6.Displaying IP information with ip address

[root@tristan]# ip address show
1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
    link/ether 00:80:c8:f8:4a:51 brd ff:ff:ff:ff:ff:ff
    inet 192.168.99.35/24 brd 192.168.99.255 scope global eth0
[root@tristan]# ip address show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
    link/ether 00:80:c8:f8:4a:51 brd ff:ff:ff:ff:ff:ff
    inet 192.168.99.35/24 brd 192.168.99.255 scope global eth0
[root@wan-gw]# ip address show wan0
8: wan0: <POINTOPOINT,NOARP,UP> mtu 1500 qdisc pfifo_fast qlen 100
    link/ppp 01:f4 peer 00:00
    inet 205.254.209.73 peer 205.254.209.74/32 scope global wan0
[root@real-example]# ip address show ppp0
5: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP> mtu 1492 qdisc htb qlen 3
    link/ppp 
    inet 67.38.163.197 peer 67.38.163.254/32 scope global ppp0
          

You should notice some similarity between the output of ip address and ifconfig. Each device is given an sequential number as an identifying number. This is merely a convenience, and should not be used to refer to devices. The second field in an entry is the interface name (which usually corresponds to the device name). Next, we see the familiar device flags and maximum transmission unit size.

The final fields in the first line of output for each device entry refer to the traffic control queueing discipline (qdisc) and the Ethernet buffer transmit queue length (qlen). For more on understanding and using traffic control under linux, see the LARTC documentation.

The second line of output describes the link layer characteristics of the device. For Ethernet devices, this will always say "link/ether" followed by the hardware address of the device and the media broadcast address. For more detail on the link layer characteristics of a device see SectionB.3, “ip link.

Subsequent lines of output describe the IP addresses available on each interface. In a typical installation only one address is used on each interface, although an arbitrary number of addresses can also be used on each interface.

Each line contains the IP address and netmask in CIDR notation, an optional broadcast address, scope information and a label. Let's examine the scope and label first and then discuss IP addressing and broadcast calculation. The possible values for scope are outlined in the following table.

TableC.2.IP Scope under ip address

Scope Description
global valid everywhere
site valid only within this site (IPv6)
link valid only on this device
host valid only inside this host (machine)

Scope is normally determined by the ip utility without explicit use on the command line. For example, an IP address in the 127.0.0.0/8 range falls in the range of localhost IPs, so should not be routed out any device. This explains the presence of the host scope for addresses bound to interface lo. Usually, addresses on other interfaces are public interfaces, which means that their scope will be global. We will revisit scope again when we discuss routing with ip route, and there we will also encounter the link scope.

Now, let's examine IP addressing with the ip address utility by adding and removing IP addresses from active interfaces.

C.2.2.Using ip address add to configure IP address information

If you need to host an additional IP address on tristan, here's how you would accomplish this task.

ExampleC.7.Adding IP addresses to an interface with ip address

[root@tristan]# ip address add 192.168.99.37/24 brd + dev eth0
[root@tristan]# ip address show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
    link/ether 00:80:c8:f8:4a:51 brd ff:ff:ff:ff:ff:ff
    inet 192.168.99.35/24 brd 192.168.99.255 scope global eth0
    inet 192.168.99.37/24 brd 192.168.99.255 scope global secondary eth0
          

There are a few items of note. You can use ip address add even if the link layer on the device is down. This means that you can readdress an interface without bringing it up. When you add an address within the same CIDR network as another address on the same interface, the second address becomes a secondary address, meaning that if the first address is removed, the second address will also be purged from the interface.

In order to support compatibility with ifconfig the ip address command allows the user to specify a label on every hosted address on a given device. After adding an address to an interface as we did in ExampleC.7, “Adding IP addresses to an interface with ip address, ifconfig will not report that the new IP 192.168.99.37 is hosted on the same device as the primary IP 192.168.99.35. In order to prevent this sort of confusion or apparently contradictory output, you should get in the habit of using the label option to identify each IP hosted on a device. Let's take a look at how to remove the 192.168.99.37 IP from eth0 and add it back so that ifconfig will report the presence of another IP on the eth0 device.

C.2.3.Using ip address del to remove IP addresses from an interface

There is a difference between IPs considered as primary addresses on an interface and secondary addresses. If in the output, an address is listed as a secondary address, removing the primary address will also remove the secondary address.

A workaround is to set the netmask on the second address added to the interface to /32. Unfortunately, this subterfuge will prevent the kernel from entering the correct corresponding network and broadcast routes.

ExampleC.8.Removing IP addresses from interfaces with ip address

[root@tristan]# ip address del 192.168.99.37/24 brd + dev eth0
[root@tristan]# ip address add 192.168.99.37/24 brd + dev eth0 label eth0:0
[root@tristan]# ip address show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
    link/ether 00:80:c8:f8:4a:51 brd ff:ff:ff:ff:ff:ff
    inet 192.168.99.35/24 brd 192.168.99.255 scope global eth0
    inet 192.168.99.37/24 brd 192.168.99.255 scope global secondary eth0:0
[root@tristan]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:80:C8:F8:4A:51
          inet addr:192.168.99.35  Bcast:192.168.99.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:190312 errors:0 dropped:0 overruns:0 frame:0
          TX packets:86955 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:30701229 (29.2 Mb)  TX bytes:7878951 (7.5 Mb)
          Interrupt:9 Base address:0x5000 

eth0:0    Link encap:Ethernet  HWaddr 00:80:C8:F8:4A:51  
          inet addr:10.10.20.10  Bcast:10.10.20.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:9 Base address:0x1000

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:306 errors:0 dropped:0 overruns:0 frame:0
          TX packets:306 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:29504 (28.8 Kb)  TX bytes:29504 (28.8 Kb)
          

Taking the minor precaution of using labels on IP addresses added to an interface will prevent confusion if there are multiple administrators of a machine, some of whom use ifconfig.

C.2.4.Removing all IP address information from an interface with ip address flush

Finally, let's look at the use of ip address flush. If an interface has already had IP addresses assigned to it, and all of the addresses need to be removed (along with their routes), there is one handy command to accomplish all of these tasks. ip address flush takes an interface name as an argument. Let's look at the output of ip address show just before and just after removing all IPs.

ExampleC.9.Removing all IPs on an interface with ip address flush

[root@tristan]# ip address show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
    link/ether 00:80:c8:f8:4a:51 brd ff:ff:ff:ff:ff:ff
    inet 192.168.99.35/24 brd 192.168.99.255 scope global eth0
    inet 192.168.99.37/24 brd 192.168.99.255 scope global secondary eth0:0
[root@tristan]# ip address flush
Flush requires arguments.
[root@tristan]# ip address flush dev eth0
[root@tristan]# ip address show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
    link/ether 00:80:c8:f8:4a:51 brd ff:ff:ff:ff:ff:ff
          

C.2.5.Conclusion

As you can see, the ip address utility provides a wealth of information and a great deal of control over the IPs associated with each device. For more detailed information about the iproute2 package and included tools, see SectionI.1.6, “iproute2 documentation”.

分享到:
评论

相关推荐

    计算机软件-商业源码-272 取得计算机的IP.zip

    - **编程语言API**:如Python的`socket`库,Java的`InetAddress`类,C#的`IPAddress`类等,提供API调用来获取当前设备的IP。 - **网络API**:如WMI(Windows Management Instrumentation)在Windows系统中,或通过...

    跨平台 获取本机IP/MAC地址,检测是否内网IP,字符串IP转换成Number地址

    例如,在Python中,可以使用`ipaddress`库,将IP地址转换为IPv4Network对象,然后检查其是否为私有网络。 4. **字符串IP转Number地址**: 字符串形式的IP地址(如“192.168.1.1”)可以转换为整数形式,便于计算和...

    solaris自启动设置IP地址

    确保 `/etc/Network/Management` 目录下的 `ifconfig.eth0` 文件存在,如果不存在,可以创建一个空白文件。这将告诉系统在启动时加载这个接口。 3. **更新网络启动脚本**: 修改 `/etc/netstart` 脚本,确保它...

    获取主机用户名和IP

    在Linux/Unix中,使用`ifconfig`(或`ip addr show`)命令。如果要获取远程主机的IP,可以使用`ping`命令,它会返回目标主机的IP。 - 编程方式:在Python中,可以使用`socket.gethostbyname(socket.gethostname())`...

    读取本机IP和Mac地址

    IP地址(Internet Protocol Address)是互联网上的唯一标识符,而MAC地址(Media Access Control Address)则是局域网(LAN)中硬件设备的物理地址。本文将深入探讨如何在程序中读取本机的IP地址和MAC地址,以及这两...

    简单可视化获取局域网IP和MAC

    一种常见的方式是通过命令行工具,例如在Windows系统中使用`ipconfig /all`命令可以查看本地计算机的IP和MAC信息,而在Linux或Unix系统中,可以使用`ifconfig`或`ip addr show`命令。然而,对于需要获取网络中所有...

    it认证答案整理

    - **计算telnet流量**:使用`tcpdump tcp port 23 host IP_address and IP_address -c`命令来监控特定IP地址的telnet流量。 - **访问网站服务器路径**:无线用户访问网站服务器需依次通过AP、交换机B、防火墙、...

    Linux和WindowsC语言获取(CPU序列号、硬盘序列号、网卡信息、IP地址、MAC地址、网卡是否插入网线)硬件信息源码

    在Linux中,可以使用`ifconfig`命令或`ip addr show`命令获取IP地址,MAC地址则在`/sys/class/net/ethX/address`路径中,其中`ethX`是网卡接口名。网络连接状态可以通过`ethtool`命令或`/sys/class/...

    新手入门 Linux菜鸟必学的60个命令-转载Linux必学命令

    - `ip addr add &lt;IP address&gt;/&lt;subnet mask&gt; dev &lt;interface&gt;`: 配置 IP 地址 - **示例:** 启用 eth0 接口并设置 IP 地址为 `192.168.1.100/24`: ```bash ifconfig eth0 up ifconfig eth0 ip addr add 192.168.1...

    IDC运维工程师面试题及其答案 .pdf

    - ARP(Address Resolution Protocol)用于根据IP地址查找对应的物理(MAC)地址。 - DNS(Domain Name System)负责将域名解析为IP地址,便于用户访问网站。 18. **网线线序**: - EIA/TIA 568A和568B标准规定...

    2021年IDC运维工程师面试题及其答案.docx

    - `ipconfig /all`(Windows)和`ip addr show`或`ifconfig -a`(Linux)用于查看MAC地址。 6. **RAID技术**: - RAID(Redundant Array of Independent Disks)用于提高数据冗余和性能,常见的RAID级别包括RAID ...

    获得 Linux window 的硬盘ID 和mac , ip 等信息(已测试)

    硬盘ID可以通过`win32api`库,但Java中我们可以使用`WMI`(Windows Management Instrumentation)来实现。以下是一个使用`jwmi`库的例子: ```java import net.java.dev.jna.platform.win32.Wmi; import ...

    获取windows or unix系统下服务器MAC地址及服务器IP地址

    1. 使用WMI(Windows Management Instrumentation):通过Java的`javax.management.remote.rmi.RMIServerImpl_Stub`类可以调用WMI接口,查询`Win32_NetworkAdapterConfiguration`类获取MAC地址。 2. 使用JNI(Java ...

    获取本机网卡信息

    IP地址(Internet Protocol Address)是网络上设备的逻辑地址,分为静态IP和动态IP。静态IP由管理员手动分配,而动态IP则通过DHCP(Dynamic Host Configuration Protocol)服务器自动分配。在Windows中,查看IP地址...

    获取以太网卡的MAC地址

    - **Linux/Unix**:使用`ifconfig`或`ip link show`命令,查找对应的以太网卡(如eth0、enp0s3等)的HWaddr或ether字段。 - **MacOS**:使用`networksetup -getmacaddress "Ethernet"`命令,其中"Ethernet"替换为...

    IBM小型机检查手册

    1. 使用`#ping [ipaddress]`命令可以测试与特定IP地址的网络连通性。确保/etc/hosts文件中的所有IP地址都可以被ping通。 #### 七、通过HMC检测硬件 1. **HMC(Hardware Management Console)**:HMC是IBM提供的...

    C语言获取硬件信息(CPU序列号,硬盘序列号,网卡IP、MAC地址、是否插入网线).zip

    在Windows系统中,可以使用Windows Management Instrumentation (WMI) API来访问系统硬件信息,其中包括CPU序列号。在C语言中,这通常通过调用`CreateFileW`、`DeviceIoControl`等函数来实现。而在Linux环境下,CPU...

    Linux基本命令集(带有说明)

    **ifconfig eth0 [IP address] netmask [subnet mask]** 使用`ifconfig`命令可以配置网络接口的IP地址和子网掩码。例如,设置`eth0`接口的IP为`192.168.4.222`,子网掩码为`255.255.255.0`。 **ifconfig eth0 hw ...

    虚拟网卡驱动源代码(原版)

    * Configuration changes (passed on by ifconfig) */ int snull_config(struct net_device *dev, struct ifmap *map) { if (dev-&gt;flags & IFF_UP) /* can't act on a running interface */ return -EBUSY; /*...

    获取计算机MAC标识

    在Linux中,可以使用`ifconfig`命令或者`ip`命令来获取。例如,通过Python的`subprocess`模块执行命令: ```python import subprocess result = subprocess.check_output(['ifconfig', 'eth0']) # 或者 result...

Global site tag (gtag.js) - Google Analytics