0

I have a workstation connected to several internal networks, with a different static IP address on each of them. Through one (?) of these networks, I can connect to a server over ssh. How can I tell which of my workstation's IP addresses is used to connect to the server? There's no NAT between the two computers as far as I can tell.

Dan
  • 113
  • 5
  • 2
    Run netstat and look for the foreign address of the server. When you find it look at the local address to determine which local address is connecting to the server. – joeqwerty Dec 09 '15 at 17:33

4 Answers4

5

On a Linux machine you can find the source IP that will be used for a connection with ip route get $destination_ip

This is the primary IP of the interface that is directly connected with the next hop.

Mircea Vutcovici
  • 16,706
  • 4
  • 52
  • 80
1

Via ssh?

server$ echo $SSH_CLIENT
1234:5678:90a:bc::805f:c436 58642 22
server$ 
thrig
  • 1,626
  • 9
  • 9
0

You can use traceroute and see from which IP it goes. Or after ssh'ing to the server check:

who am i

the last field is your IP or fqdn if it has a reverse DNS entry.

Another option is, after ssh'ing to your server, do a :

tcpdump -nnpi any icmp

And from another terminal from your workstation ping that host. You'll see in the tcpdump shell icmp packets from your workstation's IP

Now that i think about it, you dont even need access to the server, you can launch tcpdump on your host checking for packets for a choosen unused port, let's say 121345, on one root shell in your workstation:

tcpdump -nnpi any port 12345 

Then from a normal terminal window on your workstation:

telnet server 12345

or:

nc server 12345

On the tcpdump shell you'll see the IP you're using to connect to the server.

Fredi
  • 2,227
  • 9
  • 13
  • I already know my fqdn; is there a way to get `who` to return my IP address? – Dan Dec 09 '15 at 18:06
  • from who's manual page it seems not. But you can just resolve what who says (assuming your DNS is correct) whith host YOUR_FQDN. It will resolve in one IP. Alternatively you can grep for your username on /var/log/secure (in redhat at least). I updated my answer with yet another way to get your IP – Fredi Dec 09 '15 at 18:18
0

If you're on Windows, use tracert <destination IP> from your source computer to find the route it's traversing to the destination.