Take the 2-minute tour ×
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.

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

2 Answers 2

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  
+1 for tracing system calls. –  NlightNFotis Feb 28 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

 
discard

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.