How to Use ifconfig for Network Interface Management: A Detailed Guide

Enter ifconfig in the command line to view the network interfaces of this machine.

$ ifconfig enp4s0: flags=4099  mtu 1500        ether c8:5b:76:f6:44:d2  txqueuelen 1000  (Ethernet)        RX packets 0  bytes 0 (0.0 B)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 0  bytes 0 (0.0 B)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73  mtu 65536        inet 127.0.0.1  netmask 255.0.0.0        inet6 ::1  prefixlen 128  scopeid 0x10        loop  txqueuelen 1000  (Local Loopback)        RX packets 391  bytes 61933 (60.4 KiB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 391  bytes 61933 (60.4 KiB)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0virbr0: flags=4163  mtu 1500        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255        ether 52:54:00:a7:e6:9c  txqueuelen 1000  (Ethernet)        RX packets 31  bytes 3291 (3.2 KiB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 18  bytes 2571 (2.5 KiB)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0vnet0: flags=4163  mtu 1500        inet6 fe80::fc54:ff:fe15:2983  prefixlen 64  scopeid 0x20        ether fe:54:00:15:29:83  txqueuelen 1000  (Ethernet)        RX packets 31  bytes 3725 (3.6 KiB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 39  bytes 4941 (4.8 KiB)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0wlp5s0: flags=4163  mtu 1500        inet 10.1.1.64  netmask 255.255.255.0  broadcast 10.1.1.255        inet6 fe80::40df:807c:eb38:8b78  prefixlen 64  scopeid 0x20        ether a8:6b:ad:54:d5:3d  txqueuelen 1000  (Ethernet)        RX packets 10965  bytes 11639278 (11.1 MiB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 3369  bytes 513997 (501.9 KiB)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0,broadcast,running,multicast>,broadcast,running,multicast>,broadcast,running,multicast>,loopback,running>,broadcast,multicast>

Jetbrains suite for a year at 46, stable after-sales guarantee

Run a Java code segment to send UDP data to the internal network IP 192.168.122.217

package UDPtest;import java.io.IOException;import java.net.*;public class UDPTestClient {        private static final int PORT = 8800;    private static final String HOSTNAME = "192.168.122.217";    public static void main(String[] args){            try (DatagramSocket ds = new DatagramSocket(8801)){                /**             * Here is where data is sent to the server             */            // Define address information here            InetAddress id = InetAddress.getByName(HOSTNAME);            // Data to be sent            byte[] buffer = "This is the data sent from the client".getBytes();            // Pack data into UDP packet            DatagramPacket dp = new DatagramPacket(buffer, buffer.length,id,PORT);            // Send data packet            ds.send(dp);            /**             * Here is where data is received from the server             */            byte[] data2 = new byte[1024];            DatagramPacket packet2 = new DatagramPacket(data2,data2.length);            ds.receive(packet2);            String info = new String(data2,0,packet2.getLength());            System.out.println("I am the client, received data from the server, info = " + info);        } catch (IOException e) {                e.printStackTrace();        }    }}

Find the running network adapter among all listed adapters, i.e., the adapter with the flags=4163,broadcast,running,multicast> containing the RUNNING field. Here, lo is the local loopback interface, while vnet0 is the adapter we want to find.

Go back to Wireshark, double-click vnet0, and start listening. Execute the UDPTestClient class to find the data packet sent.

The Source 10.1.1.64->Destination 192.168.122.217 is the sent data packet. Double-click to view detailed data packet information.

In the first directory, you see the wireless interface

Interface id: 0 (vnet0)  Interface name: vnet0

The second directory, Ethernet port

Ethernet II, Src: HonHaiPr_54:d5:3d (a8:6b:ad:54:d5:3d), Dst: Tp-LinkT_06:67:7d (74:05:a5:06:67:7d)  Destination: Tp-LinkT_06:67:7d (74:05:a5:06:67:7d)      Address: Tp-LinkT_06:67:7d (74:05:a5:06:67:7d)      .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)      .... ...0 .... .... .... .... = IG bit: Individual address (unicast)  Source: HonHaiPr_54:d5:3d (a8:6b:ad:54:d5:3d)      Address: HonHaiPr_54:d5:3d (a8:6b:ad:54:d5:3d)      .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)      .... ...0 .... .... .... .... = IG bit: Individual address (unicast)  Type: IPv4 (0x0800)

Src represents the source device, and Dst refers to the destination device. Here, data is sent from the HonHaiPr_54:d5:3d MAC address to the Tp-LinkT_06:67:7d router’s MAC address.

The third directory Internet Protocol Version 4, Src: 10.1.1.64, Dst: 192.168.122.217 under the directory Destination GeoIP: CN

[Destination GeoIP: CN]  [Destination GeoIP Country: China]  [Source or Destination GeoIP Country: China]  [Destination GeoIP ISO Two Letter Country Code: CN]  [Source or Destination GeoIP ISO Two Letter Country Code: CN]  [Destination GeoIP Latitude: 34.7725]  [Source or Destination GeoIP Latitude: 34.7725]  [Destination GeoIP Longitude: 113.7266]  [Source or Destination GeoIP Longitude: 113.7266]

GeoIP is used to lookup geographic location based on IP.

Find the UDP header directory User Datagram Protocol, Src Port: 8801, Dst Port: 8800

User Datagram Protocol, Src Port: 8801, Dst Port: 8800  Source Port: 8801  Destination Port: 8800  Length: 41  Checksum: 0x16bc incorrect, should be 0x7c26 (maybe caused by "UDP checksum offload"?)      [Expert Info (Error/Checksum): Bad checksum [should be 0x7c26]]          [Bad checksum [should be 0x7c26]]          [Severity level: Error]          [Group: Checksum]      [Calculated Checksum: 0x7c26]  [Checksum Status: Bad]  [Stream index: 0]

Sequentially observe UDP header as defined by RFC 768, including Source Port, Destination Port, Length, and Checksum information. A checksum error is visible as the received packet’s checksum does not match the calculated checksum. This occurs because certain routers participate in checksum calculation, while upper-layer protocol stacks are unaware, leading to differing checksum values.

Checksum calculation can be performed by network network drivers, protocol drivers, or even hardware. Higher layer checksums are typically executed by the protocol and the completed packet is handed over to the hardware. More modern network hardware can execute some advanced features like IP checksum calculations, known as checksum offloading. Network drivers do not compute checksums but leave checksum fields empty or fill with invalid information for hardware calculation.

Note: This article is original by Xiao yip. Without permission, it cannot be reproduced on any platform. For reprinting, contact the author.

Welcome to join the Linux group chat: 734638086, to share work experiences.

Follow the WeChat official account: Tech Bootcamp (WeChat ID: TechBootcamp) for more information ~

Scan the WeChat QR code to discover more exciting content.

Copyright Statement: The content of this article is voluntarily contributed by Internet users, and the views expressed herein are those of the authors only. This site only provides information storage space services, does not own the content, and assumes no related legal responsibility. If this site contains infringing/illegal content, please send an email to report it, and once verified, the content will be deleted immediately.

Publisher: Full Stack Developer Stack Chief, please indicate the source for reprinting: https://javaforall.cn/222757.html Original link: https://javaforall.cn