LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-12-2023, 03:08 PM   #1
vinmansbrew
Member
 
Registered: Feb 2016
Posts: 192

Rep: Reputation: Disabled
tcpdump capture between 2 IPs


I seem to be having trouble finding just the right syntax to capture all traffic between 2 IPs.
I've tried a number of commands, but haven't seemed to find the right combo.

I am on RHEL 8.8.
A list of commands I have tried:

tcpdump -s 0 -vv -c 100 -i ens192 -xX src host IP and dst host IP and not stp -w /tmp/capture.pcap

tcpdump -nli ens192 host IP and IP -w /tmp/allcap.pcap

tcpdump -s 0 -vv -c 100 -nli ens192 host IP and IP -w /tmp/allcap.pcap

I've tried separate commands for each IP. However, neither of those limits the capture to just the 2 IPs that I want.

tcpdump -ni ens192 src host IP -w /tmp/capout.pcap

tcpdump -ni ens192 dst host IP -w /tmp/capin.pcap

I'm trying other options, but I thought I'd try you guys.
Thanks
 
Old 12-12-2023, 04:23 PM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,640

Rep: Reputation: 2697Reputation: 2697Reputation: 2697Reputation: 2697Reputation: 2697Reputation: 2697Reputation: 2697Reputation: 2697Reputation: 2697Reputation: 2697Reputation: 2697
If you have space enough, it might be useful to capture the more complete dump and then filter the output to build a database of the traffic only involving BOTH of your two addresses.
 
Old 12-14-2023, 01:45 PM   #3
jayjwa
Member
 
Registered: Jul 2003
Location: NY
Distribution: Slackware, Termux
Posts: 780

Rep: Reputation: 247Reputation: 247Reputation: 247
If I understand correctly, you want only packets with both those IPs? Use and. Maybe something like this:
Code:
tcpdump -i br0 -X -v '(ip host 192.168.20.12) and (ip host 192.168.20.4)'
I only tested it with pings but it seems to work.
 
Old 12-14-2023, 04:55 PM   #4
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,138
Blog Entries: 6

Rep: Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827Reputation: 1827
Quote:
I seem to be having trouble finding just the right syntax to capture all traffic between 2 IPs
A you are wanting to capture packets going to another IP address that is not the machine that you are on? You need to put the ethernet interface into promiscuous mode.

Code:
ip link set eth0 promisc on
Read about the security risk of doing that before you do.
 
Old 12-15-2023, 02:20 PM   #5
vinmansbrew
Member
 
Registered: Feb 2016
Posts: 192

Original Poster
Rep: Reputation: Disabled
I didn't have to worry about any of that.
tcpdump -s 0 -c 100 -vv src host 10.0.0.1 and dst host 10.0.0.2 -w /tmp/capin.pcap
I just changed the IP around and ran the command a 2nd time.
tcpdump -s 0 -c 100 -vv src host 10.0.0.2 and dst host 10.0.0.1 -w /tmp/capout.pcap.

Grabbed what I needed.
 
Old 12-20-2023, 08:24 PM   #6
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,850

Rep: Reputation: 161Reputation: 161
You can use following command to watch bi-direction traffic.
tcpdump -i ens192 -vv host 10.0.0.1 -w /tmp/capin.pcap
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird tcpdump output (No IPs) ptosch Linux - Networking 1 01-17-2014 01:33 PM
I've found tcpdump tagged as 'Installed' in PPM, why I can't find a tcpdump command ? illidan.modeler Puppy 1 09-07-2013 07:50 AM
Getting things straight: Apache, SSL, Multiple External IPs / Internal IPs robin.com.au Linux - Server 21 10-13-2007 11:39 PM
how to define a specific range of IPs and/or multiple IPs in an iptables rule?... TheHellsMaster Linux - Security 9 09-20-2004 10:06 AM
eth0:9 incorrect IPs ,and eth0 not IPs WannaLearnLinux Linux - Networking 10 10-26-2003 08:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:53 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