LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-04-2022, 04:51 AM   #1
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 369
Blog Entries: 1

Rep: Reputation: 49
Red face What connects to


Hi there!

I'd like to know if it's possible to have something that listens to all network traffic and would give me, for any particular connection, what process is writing / reading to/from it?

1. tcpdump listens to everything, continuously, and prints the packets, but not the process ids bound to them.

2. ss, netstat and lsof print the process id or command name, but they don't listen to all packets. They have a continuous mode, but it seems like they're really just recurrent snapshots. It's not capturing traffic in between.

What are my other options?

My ultimate goal is to have a bash function/script that would give me the process IDs or application names connecting to a remote IP. I already have the necessary bash code that lists all connections to the outside world with tcpdump.

Code:
root@messagerie-principale[10.10.10.19] ~ # net.connexions.to.outside
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes
10:38:33.345155 10.10.10.19.56487     - 158.69.65.151.443:     CA  Quebec           OVH Hosting, Inc.
10:38:34.104469 10.10.10.19.56488     - 158.69.65.151.443:     CA  Quebec           OVH Hosting, Inc.
I need a companion that would print further info about a particular remote IP (what process connects to it). For the example above, I'm curious to know what connects to 158.69.65.151?

Thanks for your input.
 
Old 07-04-2022, 05:00 AM   #2
lvm_
Member
 
Registered: Jul 2020
Posts: 970

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
netstat -p
 
Old 07-04-2022, 05:01 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,996

Rep: Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338
netstat -p will list all the living connections and will tell you what processes are using them. Monitoring all the incoming/outgoing traffic may require a lot of resources, if you want to connect them to the running apps/services/daemons/whatever in real time.
 
Old 07-04-2022, 09:07 AM   #4
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 369

Original Poster
Blog Entries: 1

Rep: Reputation: 49
it seems that netstat is listing what it sees at the moment you invoke it (snapshot). I need something that works continuously, and netstat -c is only making snapshots at every s seconds.
 
Old 07-04-2022, 11:16 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,996

Rep: Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338
Quote:
Originally Posted by ychaouche View Post
it seems that netstat is listing what it sees at the moment you invoke it (snapshot). I need something that works continuously, and netstat -c is only making snapshots at every s seconds.
See previous post. How much data can you (and your storage) handle? What do you mean by continuously? Do you want to know the state of your network in every microsecond?
Again, look for [network] monitoring software like nagios.
 
Old 07-04-2022, 11:34 AM   #6
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 369

Original Poster
Blog Entries: 1

Rep: Reputation: 49
Quote:
Originally Posted by pan64 View Post
What do you mean by continuously?
Same as tcpdump.
 
Old 07-04-2022, 08:15 PM   #7
!!!
Member
 
Registered: Jan 2017
Location: Fremont, CA, USA
Distribution: Trying any&ALL on old/minimal
Posts: 997

Rep: Reputation: 382Reputation: 382Reputation: 382Reputation: 382
Wireshark Maybe
 
Old 07-06-2022, 02:02 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,365

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
iftop https://www.tecmint.com/iftop-linux-...nitoring-tool/ ?
 
Old 07-06-2022, 05:31 AM   #9
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
etherape?
 
Old 07-06-2022, 12:34 PM   #10
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 369

Original Poster
Blog Entries: 1

Rep: Reputation: 49
iftop, wireshark, etherape (cool app btw) don't display process pids.
 
Old 07-06-2022, 12:46 PM   #11
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 369

Original Poster
Blog Entries: 1

Rep: Reputation: 49
osquery seems pretty cool



Source : https://youtu.be/v9bK8_pZNwo?t=660

Props to Abdou Soudaki (Linkedin profile)

Last edited by ychaouche; 07-06-2022 at 12:49 PM.
 
  


Reply

Tags
netstat, network, tcpdump



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Modem connects then ZILCH tsundram Linux - Software 4 03-09-2002 07:17 PM
dialup ISP connects but can't navigate med Linux - Newbie 0 03-08-2002 07:51 AM
wvdial connects but "connecting to ..." window sticks palanu7 Linux - Networking 1 02-04-2002 10:09 PM
Smoothwall connects, but... DiBosco Linux - Networking 1 01-06-2002 06:09 PM
How do I config Sendmail to accept connects /only/ from localhost marvin Linux - Security 4 05-09-2001 07:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration