Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-15-2005, 01:48 PM
|
#1
|
Member
Registered: Dec 2004
Distribution: Slackware
Posts: 104
Rep:
|
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?
|
|
|
11-15-2005, 03:24 PM
|
#2
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
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.
|
|
|
11-15-2005, 03:53 PM
|
#3
|
Member
Registered: May 2005
Location: Greece
Posts: 441
Rep: 
|
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.
|
|
|
All times are GMT -5. The time now is 02:02 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|