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 ⬝⬝⬝
The Source and the Shortcut – Origin Servers vs CDN Edge Servers
Engineers call it the origin. For a small site serving a few local visitors, the origin is all…
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 ⬝⬝⬝
WhatsApp Business Platform and WhatsApp Coexistence – One Number Two Doors
Coexistence is Meta's answer to that dilemma. It is also one of the most misunderstood terms in business…
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 ⬝⬝⬝
Which Codec Actually Wins in 2026? Not the One With the Best Compression
This article is about video codecs only, and it tries to answer a better question: winning at what?
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.

Share
Share on Email Copy to Clipboard
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 ⬝⬝⬝
Origin-Servers-vs-CDN-Edge-Servers

The Source and the Shortcut – Origin Servers vs CDN Edge Servers

whatsapp-business-api-vs-whatsapp-for-business

WhatsApp Business Platform and WhatsApp Coexistence – One Number Two Doors

Which-Codec-Actually-Wins-in-2026

Which Codec Actually Wins in 2026? Not the One With the Best Compression

The-Prime-Meridian,-the-Antimeridian,-and-Greenwich-Mean-Time

Where the World Begins – The Prime Meridian, the Antimeridian, and Greenwich Mean Time

ussd-anatomy

USSD Codes Structure – How to Read Codes Like *123# and 1231#

managing-screen-time-at-the-table

The Impact of Screen Time on the Quality of Life of the World’s Population

cell-towers

2G, 3G, 4G and 5G Towers – Requirements and Differences

full-HD,-4K,-and-8K-resolution

4K, 8K and HDR Streaming – Why Better Pictures Are Hard to Deliver

Keeping-Kids-Safe-Online

A Parent’s Guide to Keeping Kids Safe Online

a-video-player-window-with-a-magnifying-glass

Deepfake Videos – How to Tell What’s Real

Why-Ghana’s-Payment-Providers-Feel-Hostile

Why Ghana’s Payment Providers Feel Hostile, and Where the Ghanaian Developers Are

Why-is-Gmail-Categories-now-Tied-to-Smart-Features-and-Personalization

Why is Gmail Categories now Tied to Smart Features and Personalization

TAILORED VIEWING
Origin-Servers-vs-CDN-Edge-Servers
The Source and the Shortcut – Origin Servers vs CDN Edge Servers
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.