LinuxQuestions.org
Help answer threads with 0 replies.
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 11-15-2005, 01:48 PM   #1
jcombs_31
Member
 
Registered: Dec 2004
Distribution: Slackware
Posts: 104

Rep: Reputation: 15
view ports currently in use


I know you can use ps to view running processes, but can you also see which ports are being used by the processes?
 
Old 11-15-2005, 03:24 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
i'm still not as familiar with it as i'd like to be, but lsof is one way forward here. it can give a LOT of info though, so you'll need to whittle down what you are asking for.
 
Old 11-15-2005, 03:53 PM   #3
imitheos
Member
 
Registered: May 2005
Location: Greece
Posts: 441

Rep: Reputation: 141Reputation: 141
Thumbs up

The primary tool for getting this info (the one that exist in all distributions and all versions of them) is netstat
But there are other tools as well.

I will mention what to run in order to see listening ports and ports used by established connections.

a: netstat -lp
-l means listening
-p means pid (of process)
also
-n means numeric (don't show hostnames)
-t means tcp
so if you want to see only tcp ports you run "netstat -tlp"

If you don't use "-l" option then you see already established connections.

b: fuser
fuser can be used to see which process uses a port
the syntax is very simple. you run "fuser port/protocol"
e.g "fuser 25/tcp" will tell you which process uses port 25
It doesn't show you all the processes/ports like netstat

c: lsof
lsof -i

if you just run "lsof -i" you will all the ports (listening and established)
if you want just one port you run "lsof -i TCP:25"

I tried to put only the simplest syntax. You can put a wealth of other options as well (especially for lsof)
If you read the manpage of these tools there are more options

lsof produces the most pretty/readable/understandable output and nowadays exists in all major distributions, but i mention the others
too for the rare case that lsof doesn't exist.
 
  


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
Cannot Open Mail Server Ports 25, 110, and 220. Other Ports will open. Binxter Linux - Newbie 9 11-29-2007 02:03 AM
In addition to "view new posts" about "View last 24 hours" KimVette LQ Suggestions & Feedback 3 10-30-2005 10:22 AM
W2K cannot view samba share but can view NT FiveFlat Linux - Software 3 06-10-2005 02:54 PM
View/close ports SlAiD Linux - Security 4 02-20-2005 07:19 AM
View more than 25 threads on the "view new posts" page lfslinux LQ Suggestions & Feedback 2 02-02-2002 12:07 PM

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

All times are GMT -5. The time now is 02:04 AM.

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