• Linux
  • FreeBSD
  • Networking
  • Python
  • AWS
  • WebDev
  • About Us
Tech Tips and Tutorials
Menu
  • Linux
  • FreeBSD
  • Networking
  • Python
  • AWS
  • WebDev
  • About Us
Home  /  FreeBSD  /  How to run tcpdump as a process for pcap capture in FreeBSD

How to run tcpdump as a process for pcap capture in FreeBSD

Written by
FreeBSD Leave a Comment

If you are managing FreeBSD or any Linux servers , you might have used the tcpdump a number of times . It’s a very handy tool for Network engineers or System administrators for troubleshooting . Sometimes you need to run it over day/night , capture the file and then analyze it in Wireshark . So let’s have a look at some of the handy commands for this .

Here igb1 is my interface name , you need to replace it with yours , the wireshark capture file needs to have a .pcap extension .

tcpdump -ni igb1 -s0  -w /tmp/testcapture.pcap

You can also add your filters with the command, for eg : if you are filtering for a specific host IP

tcpdump -ni igb1 -s0 host 192.168.150.17  -w /tmp/testcapture.pcap

Some of the older FreeBSD versions gives a sytntax error on tcpdump with the above cammand . In that case , you can use the command below. You can also filter with host ip , port number etc after igb1

tcpdump -w /testcapture.pcap -s0 -ni igb1 

Now, to run it as background as a process

nohup  tcpdump -w /root/testcapture.pcap -s0 -ni igb1 port 80 &

This is very important , the tcpdump writes to the file in a chunk of 16kb .So if you check the size of the write file after starting it as a process , you will see only 0 .So you need to run it for some good time . And while stopping tcpdump , you need to gracefully stop the process or it will cause poroblems with your write file .

ps ax | grep tcpdump 

Find the process id from the above command and then use only kill -15. Do not use kill -9 , it won’t stop the process gracefully and cause issues

kill -15 tcpdumpPID

You cannot directly cat , tail or clog a tcpdump capture file from the command line , you need to use the -r flag for that . To use the file in Wireshark , download the file locally and open in Wireshark .

tcpdump -r /testcapture.pcap

Share On
Share on Facebook
Share on Twitter
Share on Google+
Share on Whatsapp

 Previous Article How to grep IP addresses from log files in Linux
Next Article   How to increase the root volume in a Linux ec2 instance

Related Posts

  • How to increase the disk size in FreeBSD

  • How to list and mount an external USB disk in FreeBSD

  • How to install and connect OpenVPN client in FreeBSD

Leave a Reply

Cancel reply

  • Popular Posts
  • Recent Posts
  • Linux Shell Scripts for System Administrators
  • Cacti 1.1.38 ERROR Opening .rrd No Such file or directory
  • Apache configuration for Cacti
  • How to create RAM disk in Ubuntu 18.04
  • Linux Shell Scripts for System Administrators
  • SOCKS PROXY
  • How to install XAMPP and access phpMyAdmin in MAC OS
  • How to increase the root volume in a Linux ec2 instance

Linux

  • Linux Shell Scripts for System Administrators
  • SOCKS PROXY
  • How to grep IP addresses from log files in Linux
  • How to empty or delete a large file in Linux

Categories

  • AWS (5)
  • FreeBSD (12)
  • Linux (29)
  • Networking (3)
  • Python (5)
  • Uncategorized (4)
  • WebDev (1)
  • Connect on Facebook
  • Connect on YouTube
© Copyright 2020.TechieNix. All Rights Reserved.
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Cookie settingsACCEPT
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Non-necessary

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.