Skip to content
No results
  • Diy Guides
  • Innovations
  • Connected
  • Security
  • Gaming
  • Science
  • Features
  • Payments
  • Streaming
Login
· Tos · About ·

Technology • Engineering • Computing • History

Login
  • Diy Guides
  • Innovations
  • Connected
  • Security
  • Gaming
  • Science
  • Features
  • Payments
  • Streaming

Technology • Engineering • Computing • History

No results

How to use ngrep – A Network Packet Analyzer for Linux

  • How To
  • 17, Sep, 2018
  • 6 mins
ngrep – A Network Packet Analyzer for Linux

Ngrep (network grep) is a simple yet powerful network packet analyzer. It is a grep-like tool applied to the network layer – it matches traffic passing over a network interface.

It allows you to specify an extended regular or hexadecimal expression to match against data payloads (the actual information or message in transmitted data, but not auto-generated metadata) of packets.

This tool works with various types of protocols, including IPv4/6, TCP, UDP, ICMPv4/6, IGMP as well as Raw on a number of interfaces. It operates in the same fashion as tcpdump packet sniffing tool.

More For Your Read ⬝⬝⬝
When Open Worlds Meet Online Role-Playing – Shared Cities, Streamers and Platform Owners
When open world games meet online role-playing, shared cities, streamers and platform owners reshape play. A detailed look…
Read More

The package ngrep is available to install from the default system repositories in mainstream Linux distributions using package management tool as shown.

$ sudo apt install ngrep
$ sudo yum install ngrep
$ sudo dnf install ngrep

After installing ngrep, you can start analyzing traffic on your Linux network using following examples.

1. The following command will help you match all ping requests on the default working interface. You need to open another terminal and try to ping another remote machine. The -q flag tell ngrep to work quietly, to not output any information other than packet headers and their payloads.

$ sudo ngrep -q '.' 'icmp'
interface: enp0s3 (192.168.0.0/255.255.255.0)
filter: ( icmp ) and ((ip || ip6) || (vlan && (ip || ip6)))
match: .
I 192.168.0.104 -> 192.168.0.103 8:0
]...~oG[....j....................... !"#$%&'()*+,-./01234567
I 192.168.0.103 -> 192.168.0.104 0:0
]...~oG[....j....................... !"#$%&'()*+,-./01234567
I 192.168.0.104 -> 192.168.0.103 8:0
]....oG[............................ !"#$%&'()*+,-./01234567
I 192.168.0.103 -> 192.168.0.104 0:0
]....oG[............................ !"#$%&'()*+,-./01234567

You can press Ctrl + C to terminate it.
2. To match only traffic going to a particular destination site, for instance ‘google.com’, run the following command, then try to access it from a browser.

$ sudo ngrep -q '.' 'host google.com'
interface: enp0s3 (192.168.0.0/255.255.255.0)
filter: ( host google.com ) and ((ip || ip6) || (vlan && (ip || ip6)))
match: .
T 172.217.160.174:443 -> 192.168.0.103:54008 [AP]
..................;.(...RZr..$....s=..l.Q+R.U..4..g.j..I,.l..:{y.a,....C{5>......p..@..EV..
T 172.217.160.174:443 -> 192.168.0.103:54008 [AP]
.............l.......!,0hJ....0.%F..!...l|.........PL..X...t..T.2DC..... ..y...~Y;.$@Yv.Q6

3. If you are surfing the web, then run the following command to monitor which files your browser is requesting:.

More For Your Read ⬝⬝⬝
Subscription Video On Demand Outlook in 2027
What will subscription streaming look like in 2027? This detailed outlook covers subscriber forecasts, rising prices, ad tiers,…
Read More
$ sudo ngrep -q '^GET .* HTTP/1.[01]'
interface: enp0s3 (192.168.0.0/255.255.255.0)
filter: ((ip || ip6) || (vlan && (ip || ip6)))
match: ^GET .* HTTP/1.[01]
T 192.168.0.104:43040 -> 172.217.160.174:80 [AP]
GET / HTTP/1.1..Host: google.com..User-Agent: Links (2.13; Linux 4.17.6-1.el7.elrepo.x86_64 x86_64;
GNU C 4.8.5; text)..Accept: */*..Accept-Language: en,*;q=0.1..Accept-
Encoding: gzip, deflate, bzip2..Accept-Charset: us-ascii,ISO-8859-1,ISO-8859-2,ISO-8859-3,ISO-8859-4,
ISO-8859-5,ISO-8859-6,ISO-8859-7,ISO-8859-8,ISO-8859-9,ISO-8859-10,I
SO-8859-13,ISO-8859-14,ISO-8859-15,ISO-8859-16,windows-1250,windows-1251,windows-1252,windows-1256,
windows-1257,cp437,cp737,cp850,cp852,cp866,x-cp866-u,x-mac,x-mac-ce,x-
kam-cs,koi8-r,koi8-u,koi8-ru,TCVN-5712,VISCII,utf-8..Connection: keep-alive....

4. To see all activity crossing source or destination port 25 (SMTP), run the following command.

$ sudo ngrep port 25

5. To monitor any network-based syslog traffic for the occurrence of the word “error”, use the following command.

$ sudo ngrep -d any 'error' port 514

Importantly, this tool can convert service port names stored in “/etc/services” (on Unix-like systems such as Linux) to port numbers. This command is equivalent to the above command.

$ sudo ngrep -d any 'error' port syslog

6. You can also run ngrep against an HTTP server (port 80), it will match all requests to the destination host as shown.

$ sudo ngrep port 80
interface: eth0 (64.90.164.72/255.255.255.252)
filter: ip and ( port 80 )
####
T 67.169.59.38:42167 -> 64.90.164.74:80 [AP]
GET / HTTP/1.1..User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i
686) Opera 7.21  [en]..Host: www.darkridge.com..Accept: text/html, applicat
ion/xml;q=0.9, application/xhtml+xml;q=0.9, image/png, image/jpeg, image/gi
f, image/x-xbitmap, */*;q=0.1..Accept-Charset: iso-8859-1, utf-8, utf-16, *
;q=0.1..Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0..Cookie: SQ
MSESSID=5272f9ae21c07eca4dfd75f9a3cda22e..Cookie2: $Version=1..Connection:
Keep-Alive, TE..TE: deflate, gzip, chunked, identity, trailers....
##

As you can see in the above output all HTTP headers transmission are displayed in their gory detail. It’s hard to parse though, so let’s watch what happens when you apply -W byline mode.

More For Your Read ⬝⬝⬝
The Anatomy of a Great Prompt – Role, Context, Task and Format
Learn the four parts of a great AI prompt: role, context, task and format. This detailed guide explains…
Read More
$ sudo ngrep -W byline port 80
interface: eth0 (64.90.164.72/255.255.255.252)
filter: ip and ( port 80 )
####
T 67.169.59.38:42177 -> 64.90.164.74:80 [AP]
GET / HTTP/1.1.
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i686) Opera ...
Host: www.darkridge.com.
Accept: text/html, application/xml;q=0.9, application/xhtml+xml;q=0.9 ...
Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1.
Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0.
Cookie: SQMSESSID=5272f9ae21c07eca4dfd75f9a3cda22e.
Cookie2: $Version=1.
Cache-Control: no-cache.
Connection: Keep-Alive, TE.
TE: deflate, gzip, chunked, identity, trailers.

7. To print a timestamp in the form of YYYY/MM/DD HH:MM:SS.UUUUUU every time a packet is matched, use the -t flag.

$ sudo ngrep -t -W byline port 80
interface: enp0s3 (192.168.0.0/255.255.255.0)
filter: ( port 80 ) and ((ip || ip6) || (vlan && (ip || ip6)))
####
T 2018/07/12 16:33:19.348084 192.168.0.104:43048 -> 172.217.160.174:80 [AP]
GET / HTTP/1.1.
Host: google.com.
User-Agent: Links (2.13; Linux 4.17.6-1.el7.elrepo.x86_64 x86_64; GNU C 4.8.5; text).
Accept: */*.
Accept-Language: en,*;q=0.1.
Accept-Encoding: gzip, deflate, bzip2.
Accept-Charset: us-ascii,ISO-8859-1,ISO-8859-2,ISO-8859-3,ISO-8859-4,ISO-8859-5,utf-8.
Connection: keep-alive.

8. To avoid putting the interface being monitored into promiscuous mode (where it intercepts and reads each network packet that arrives in its entirety), add the -p flag.

$ sudo ngrep -p -W byline port 80

9. Another important option is -N which is useful in case you are observing raw or unknown protocols. It tells ngrep to display the sub-protocol number along with single-character identifier.

$ sudo ngrep -N -W byline

For more information, see the ngrep man page.

$ man ngrep

ngrep Github repository: https://github.com/jpr5/ngrep

That’s all! Ngrep (network grep) is a network packet analyzer that understands BPF filter logic in the same fashion tcpdump.

More Information ℹ
  • Krack Attack: What you need to know
  • 2G, 3G, 4G and 5G Towers – Requirements and Differences
  • Understanding Telecom Towers – What They Are and Their Role in Mobile Networks
  • What to look out for in a network switch
  • 11 tips to Secure your Wi-Fi Network from intruders
Topics in Article
# Accellerated Mobile Pages# cache# Data# Display# Form# GitHub# GNU# Google# HTML# HTTP# HTTPS# IPv4# Linux OS# Metadata# Monitor# Mozilla# Network# Opera# Protocols# SMTP# Time
Gabby
Gabby

Inspiring readers to expound the possibilities of the unfolding World

Apple watch vs Samsung Watch
Previous Post Apple Watch Series 4 vs Samsung Galaxy Watch: Who wins the battle of the two flagship watches?
Next Post Copyleft: what is it?
Copyleft
MORE for your read ⬝⬝⬝
When Open Worlds Meet Online Role Playing

When Open Worlds Meet Online Role-Playing – Shared Cities, Streamers and Platform Owners

Video-On-Demand outlook 2027

Subscription Video On Demand Outlook in 2027

Anatomy of a Great Prompt

The Anatomy of a Great Prompt – Role, Context, Task and Format

nvidia

Nvidia and Jensen Huang – The Resignation and the Rehiring Explained

Why keywords matter to every business owner

Why keywords matter to every business owner

Your First Conversation with an AI Assistant

Your First Conversation with an AI Assistant – A Beginner’s Guide

Security Situation of the Last Three Months

The Security Situation of the Last Three Months – From the PHP Hole to the Microsoft Blackout

Contactless Payments

How Contactless Payments Actually Work

transaction rversal

Telecel Cash wrong transfer

Transfer

MoMo Transfer Limits Explained

The Energy Independent Household

Solar + EV + Smart Home: The Energy-Independent Household

Wrong MoMo Transfer

How to Reverse a Wrong MoMo Transfer

TAILORED VIEWING
When Open Worlds Meet Online Role Playing
When Open Worlds Meet Online Role-Playing – Shared Cities, Streamers and Platform Owners
Local Assembly Plants
Local Assembly Plants and the Rise of Africa’s Auto Industry
invalid clicks
What Is Invalid Traffic? A Plain Guide for Publishers
Why is Gmail Categories now Tied to Smart Features and Personalization
Why is Gmail Categories now Tied to Smart Features and Personalization
  • Messaging
  • Programming
  • Operating System
  • Linux OS
  • Android
  • Tutorial
  • Network
  • Web browser
  • Developers
  • Mobile payments
  • Artificial Intelligence
  • Smartphone
  • Cryptocurrency
  • Data Security
  • Collaboration
  • Terms of Service
  • Advertise
  • About

© 2026 | All rights reserved.