Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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'm searching for something like:

tcpdump -p PID        # But tcpdump does not know the PID


lsof -i --continuous  # But lsof just runs and exits, no «live logging»

to log which connections an application opens.

In my case, I want to find out to which port git connects when committing. This happens in a fraction of a second, so I cannot use lsof. If there is a lot of traffic, filtering by PID or process name would be useful.

share|improve this question
up vote 5 down vote accepted

You can strace the process.

$ strace -e trace=connect git ...

connect(4, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("<your local DNS resolver>")}, 16) = 0
connect(4, {sa_family=AF_INET, sin_port=htons(<PORT>), sin_addr=inet_addr("<GIT SERVER>")}, 16) = 0
share|improve this answer
This works for wget here and (only as root) ping. But for git the only output is «--- SIGCHLD (Child exited) @ 0 (0) ---» (also without grep), any idea why this might be? – Simon A. Eugster Sep 23 '12 at 9:21
Also, strace COMMAND|grep something does not work since it will only grep on the COMMAND's output, but it works with an additional filter: strace -e trace=network -e connect COMMAND. – Simon A. Eugster Sep 23 '12 at 9:22
If git forks an additional process to do the job, add a -f flag to strace that. Yes, if you don't have the pipe redirection 2>&1 then it will only grep on stdout, which is the output of COMMAND. – Jay Sep 23 '12 at 12:18
That's it! -f did the job. Thanks a lot. – Simon A. Eugster Sep 23 '12 at 14:18

In my case, I want to find out to which port git connects when committing.

Why not:

$ git config --get remote.origin.url

The default port is:

  • git:// - 9418
  • git+ssh:// - 22
  • http:// - 80
  • ...

Otherwise, git will let you know which port it connects to when committing:

$ git config --get remote.origin.url
share|improve this answer
What if the program happens to use something other than documented or what it claims to use? (Unlikely to be true with git, but could happen in other cases.) – mattdm Sep 23 '12 at 13:35

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.