LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices


Reply
  Search this Thread
Old 05-03-2007, 06:09 AM   #1
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Rep: Reputation: 30
Netstat -ntulp for FreeBSD


Just a quick question. Is there an equivalent command in FreeBSD for the linux command netstat -ntulp
I want to view which TCP and UDP ports are open on my system.
 
Old 05-03-2007, 08:46 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Linux netstat has several flags not on other *Nixes.

You can probably get what you're looking for with the "-t, -u" flags by doing the following:

Code:
netstat -an |egrep "^tcp|^udp"
The -p flag is unique to Linux so far as I know. To associate processes with ports you can use lsof:

Code:
lsof -i
lsof is a great utility that has many other uses. If you were looking for a certain port for example you could just do:

lsof -i : port

OR for a certain server:

lsof -i @server:

Or a certain port to a certain server:

lsof -i @server: port

And those are only some of the things you can do with -i, lsof has many many other uses.
 
Old 05-03-2007, 10:23 AM   #3
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Original Poster
Rep: Reputation: 30
Thanks, this is what I was looking for

netstat -an |egrep "^tcp|^udp"
 
Old 05-03-2007, 12:51 PM   #4
reverse
Member
 
Registered: Apr 2007
Distribution: Gentoo
Posts: 337

Rep: Reputation: 30
A more direct way would be something like:

Code:
netstat -a -f inet -p tcp,udp
(check the FBSD manual page for netstat)
 
Old 05-03-2007, 01:49 PM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
One might assume that with over 2000 posts I either already knew to check man pages OR had at least been admonished to do some in one of those earlier threads.

In point of fact I had checked the man page. The OP didn't give his version of FreeBSD and on the 4.9 system I looked at it didn't have the options he was using.

The fact that I specifically mentioned "-p" would have been a clue that it didn't work the way it does on Linux though I'll admit I missed the fact that it is there and means "protocol" rather than "program" as it does on Linux. My comments about lsof were to address the lack of a "program" option.

On that FBSD 4.9 system running your command gave:
netstat -a -f inet -p tcp,udp
netstat: tcp,udp: unknown or uninstrumented protocol

Running your line with only tcp or only udp after -p gives only one of the two protocols the OP was looking for whereas the the egrep finds both.
 
Old 05-04-2007, 03:44 AM   #6
reverse
Member
 
Registered: Apr 2007
Distribution: Gentoo
Posts: 337

Rep: Reputation: 30
You know what? This is not about you. I tried chipping in, god forbid I offend a Senior Member (WAW) in the process. And I wasn't telling *YOU* to check the manual page.
 
Old 05-04-2007, 08:47 AM   #7
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
My assumption, perhaps, flawed is that before "chipping in" you would have read all the posts in the thread.

Anyway - sorry for the tone of my post - yours just hit me wrong. As indicated in my reply I did have to re-examine one thing I wrote based on what you wrote.
 
Old 05-04-2007, 10:59 AM   #8
reverse
Member
 
Registered: Apr 2007
Distribution: Gentoo
Posts: 337

Rep: Reputation: 30
No problems. I just remember when I was using FBSD I was doing something similar to your solution because I was too lazy to read the `netstat` manual page (I'm not implying *you* are lazy, as your method is "portable" across various releases). I do not currently have access to a BSD system so I had to search for an online FBSD man page repository to refresh my memory about the flags. I wasn't sure how to print *both* tcp and udp, the "-p tcp,udp" mode was an assumption. Surely "-p tcp" works and "-p udp" works but how you'd get both was what I had trouble with. So there were two reasons I was suggesting the OP to check the netstat man page: one, it's always good to read these documents, 2nd: he/she'd be able to "correct" my reply in case it was erroneous.
 
Old 05-04-2007, 04:48 PM   #9
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by SlackDaemon
Just a quick question. Is there an equivalent command in FreeBSD for the linux command netstat -ntulp
I want to view which TCP and UDP ports are open on my system.
Yes. Another easy way to get this information is with sockstat.

if you're only interested in IPv4:
Code:
$ sockstat -4

Last edited by anomie; 05-04-2007 at 04:53 PM.
 
Old 05-04-2007, 10:26 PM   #10
SlackDaemon
Member
 
Registered: Mar 2006
Distribution: RedHat, Slackware, Experimenting with FreeBSD
Posts: 222

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by reverse
2nd: he/she'd be able to "correct" my reply in case it was erroneous.
It's a he

but thanks for all your answers. I appreciate it
 
  


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
netstat Smooth Solaris / OpenSolaris 4 11-17-2006 12:30 AM
netstat -s r_213 Linux - Networking 2 01-27-2005 06:45 AM
route and netstat ray5_83 Programming 1 09-16-2004 01:12 PM
netstat -i r_213 Linux - Networking 4 09-09-2004 06:10 AM
netstat sopiaz57 Linux - Networking 1 10-14-2003 03:39 PM

LinuxQuestions.org > Forums > Other *NIX Forums > *BSD

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