Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a program that tries to connect to a server on start-up on a unknown port. I need to find out which port the program accesses to enable a ssh tunnel.

I tried netstat but since the connection fails I don't find any useful information.

share|improve this question
up vote 7 down vote accepted
strace -e trace=connect -f yourprogram

or using a dump file

strace -o yourprogram.strace -e trace=connect -f yourprogram
share|improve this answer
+1 for tracing system calls. – NlightNFotis Feb 28 '14 at 22:40

Just another option: the auditd of Linux support system call logging.

sudo auditctl -a entry,always -F arch=b64 -S connect

Something better compare to strace: you can filter by multiple condition.

For example:

  • Audit/Log all failed connect system call: sudo auditctl -a entry,always -F arch=b64 -F success!=0 -S connect
  • Audit/Log all connect system call by specific uid: sudo auditctl -a entry,always -F arch=b64 -F auid=501 -S connect
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.