-1

ssh

ssh

Hello everyone,

My dedicated server has a few IP addresses assigned to specific accounts. And I can SSH to the account via secondary IP. But once in, the IP is always the primary IP ( i tried with command " curl wtfismyip.com/text" )

I have a few shell script that need to run in different ssh instances, and they should use different IP addresses (different accounts) for outbound.

Does anyone has any suggestions, solutions for this matter ? I would appreciate your help.

Thank you

3
  • You are not SSHing "to" the IP, you are SSHing "via" the IP. You reach the same machine on the other side, which defaults to connecting through its primary IP. What you really want to know is how to use a secondary IP address for a given application. Commented Jan 31, 2018 at 1:25
  • Thank you so much for your response. Any tips to get that ? I tried to google but no luck. Commented Jan 31, 2018 at 1:31
  • serverfault.com/questions/182550/…
    – Sirex
    Commented Jan 31, 2018 at 1:52

1 Answer 1

0

Your server IP that external sites (eg. whatismyip, ...) see is the IP that your server get from your routing table.

$ ip route
default via x.x.x.x dev ethX ...
10.0.0.0/16 dev ethY ...
....

If the site you are trying to connect has its IP in a subnet specified in the routing table, both source IP (yours) and outgoing interface will be taken from this specific route. For example : whatismyip.net 's IP is 10.0.0.1, when you send traffic to it, your server will use the ethY interface and the ethY IP.

Otherwise, if the site does not match any subnet, the default route is used. In the example, the server will send traffic through the ethX interface with the ethX IP as source.

In your context, it seems that your default route is via eth0.

To use another interface/IP :

  1. you can specify for some command, the outgoing interface and then your source IP, eg.

    ping -I ethY whatever.net
    ping -I eth0.Y whatever.net
    curl --interface eth0.Y wtfismyip.com/text
    
  2. or, you can add a new route for MY_REMOTE_IP, that will enforce the use of a given interface or source IP when communicating with it. In the example above, MY_SECOND_IP is the IP of the ethY interface

    $ ip route add MY_REMOTE_IP dev ethY src MY_SECOND_IP
    $ ip route add MY_REMOTE_IP dev eth0.Y src MY_SECOND_IP
    
  3. Otherwise, in some commands, you can enforce the source IP, eg.

    ssh -b MY_SECOND_IP user@MY_REMOTE_IP
    

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .