Capture network traffic from physical devices in a Linux VM

Abstract: Resolve network troubleshooting in Linux VMs by capturing physical device traffic using tcpdump on the correct virtual interface.

Created: 2026-08-04 by

Use tcpdump inside your Linux VM to capture network traffic from physical devices by attaching to the correct virtual network interface. This process allows you to monitor packets, troubleshoot connectivity issues, and verify security protocols on Hyper-V managed systems without needing access to the host machine's physical hardware.

Identifying the Correct Network Interface

Before capturing any data, you must determine which network interface card (NIC) is handling the traffic. In a Linux environment running on Hyper-V, the virtualized NIC often has a different name than what you might see on bare-metal hardware. The most common naming conventions include eth0, enp0s3, or ens33, depending on the distribution and version of Linux installed. To list all available network interfaces along with their status, run the following command in your terminal:
ip addr show
Look for an interface that has an IP address assigned and is in the UP state. If you are unsure which interface is carrying the external traffic, you can filter by the default route. Run this command to see which interface is used for outbound connections:
ip route show default
The output will typically display something like default via 192.168.1.1 dev eth0. In this example, eth0 is the device you should target. Attaching to the wrong interface, such as lo (loopback), will result in capturing only local system communications rather than traffic between your physical devices and the outside world. For more details on resolving interface-specific issues, see Unable to fix 'Network unreachable' on Ubuntu server running Windows 11 Hyper-V.

Installing tcpdump

While tcpdump is pre-installed on many enterprise Linux distributions, it may be missing on minimal installations or custom builds. You need administrative privileges to install it. Use your distribution's package manager to install the tool. For Debian-based systems like Ubuntu or Kali Linux, use apt:
sudo apt update
sudo apt install tcpdump
For Red Hat-based systems like CentOS, RHEL, or Fedora, use yum or dnf:
sudo yum install tcpdump
Once installed, verify the installation by checking the version:
tcpdump --version
If the command returns a version number, the tool is ready for use. Note that capturing network traffic requires root privileges or membership in the pcap group. Always run commands with sudo to avoid permission denied errors.

Capturing Traffic with tcpdump

The basic syntax for capturing traffic involves specifying the interface and optional filters. To start capturing packets on the identified interface, use the following command:
sudo tcpdump -i eth0
This will begin displaying packet headers in real-time. Each line includes the timestamp, source and destination addresses, protocol, and packet length. To stop the capture, press Ctrl+C. For more targeted analysis, you can apply filters directly within the command. For example, to capture only HTTP traffic (port 80) on eth0:
sudo tcpdump -i eth0 port 80
To capture HTTPS traffic (port 443):
sudo tcpdump -i eth0 port 443
You can also filter by specific IP addresses. To capture traffic from a specific host at 192.168.1.100:
sudo tcpdump -i eth0 host 192.168.1.100
Combining these filters allows for precise troubleshooting. For instance, to capture DNS queries and responses:
sudo tcpdump -i eth0 port 53

Saving Captures to a File

Real-time viewing is useful for quick checks, but saving captures to a file is essential for deep analysis. Use the -w flag to write raw packets to a file. These files have a .pcap extension and can be opened later with tools like Wireshark.
sudo tcpdump -i eth0 -w capture.pcap
This command saves all packets on eth0 to capture.pcap until you stop the process. You can combine this with filters to reduce file size:
sudo tcpdump -i eth0 port 80 -w http_traffic.pcap
When analyzing saved files, ensure you have sufficient disk space, as continuous capture can generate large files quickly. Limiting the duration of the capture using the -c flag (count of packets) or -W flag (file rotation) can help manage storage.

Troubleshooting Common Issues

Sometimes, capturing traffic in a VM does not yield expected results due to Hyper-V configuration. Ensure that the VM's virtual switch is set to an "External" type if you need to see traffic leaving the host machine. An "Internal" or "Private" switch will restrict visibility to only VM-to-VM communication. If you encounter a "permission denied" error despite using sudo, check if the user is in the pcap group:
groups $USER
If the group is missing, add it:
sudo usermod -aG pcap $USER
Log out and log back in for changes to take effect. Additionally, verify that the network adapter is not in promiscuous mode restrictions imposed by certain Hyper-V configurations, though standard tcpdump usage usually bypasses this for inbound traffic. For related networking challenges, check NIC Change VM (Ubuntu Hyper-V) Default Switch - External Switch Lost Internet Connection.

Frequently Asked Questions

Why can't I see traffic from other devices on my network?

You cannot see traffic destined for other devices unless your VM's network adapter is in promiscuous mode or connected to a mirrored port. Standard VM setups only receive packets addressed to the VM's own MAC address. To capture broader traffic, configure port mirroring on your physical switch or adjust Hyper-V virtual switch settings.

How do I read .pcap files generated by tcpdump?

The most common tool for reading .pcap files is Wireshark. Install Wireshark on your Linux VM or transfer the file to a Windows/macOS machine where Wireshark is installed. Open the file via the GUI or use the command line: wireshark capture.pcap.

Is tcpdump safe to run on a production server?

Yes, tcpdump is generally safe as it only reads packets and does not modify them. However, high-volume captures can consume significant CPU and disk I/O resources. Always limit the capture duration or filter aggressively to minimize performance impact on critical services.

What is the difference between tcpdump and tshark?

tcpdump is a command-line tool focused on raw packet capture and simple filtering. tshark is the command-line equivalent of Wireshark, offering deeper protocol dissection and more complex filtering capabilities. Use tshark if you need detailed payload analysis directly from the terminal.

Can I capture traffic on a loopback interface?

Yes, you can capture traffic on the loopback interface (lo) using sudo tcpdump -i lo. This captures traffic sent between processes on the same machine. It is useful for debugging local services but does not show external network traffic.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More