0

server1 has a private and public ip. server2 has a private and public ip.

generally.. if server1 to ssh to server2 .. server2 would recognize server1 by it's public ip.

but because both servers are with the same firm.. i suppose they have configured it to use "private ip" when ssh ing to each other.

i connected to server1 from server2 then checked to see what my ip is ( server2 ) and i noticed it is not the public ip of server2 but rather the private ip of server2.

i want to disable this feature.. i would like servers to communicate only via their public ip's..

how to midigate this issue ?

  • Often public traffic is metered while private is not. Usually you would want to take advantage of this to reduce costs. – Brian Aug 17 '15 at 12:30
  • ok.. the issue is.. i ssh to server1 from server2 via server1's public ip then after i am in server1.. i check to see what my ip is.. and it is showing me my private ip. ( server2's private ip ) when the truth is.. server2 has a public ip as well.. which is what needs to be shown – ALO MALO Aug 17 '15 at 12:33
  • Please do check from the logs of server1 what IP it records as the source address for the incoming SSH session (it might be /var/log/messages or /var/log/auth or something else, depending on the distro and syslog config). The log entry you should be looking for has something like sshd[xxxx]: Accepted password for username from 123.456.789.123 port nnnn ssh2. If that log also contains the private IP of server2, then it is a matter of some sort of automatic re-routing intra-server traffic to internal network, and you should consult your network admins about it. – zagrimsan Aug 18 '15 at 7:54
1

You should specify the public IP address when connecting to the other server.

If your servers are f.e. configured like this:

Server1: 192.168.0.1 (private), 12.34.56.1 (public)
Server2: 192.168.0.2 (private), 12.34.56.2 (public)

You should connect from server1 to server2 using

ssh 12.34.56.2

This will ensure the connection happens using the public network.

If you want to refer to the server by name (ssh server2) and you want the name to automatically be mapped to the server's public IP address, you should add entries in the hosts files of both servers, telling them their names are to be mapped to their public IPs:

    12.34.56.1 Server1
    12.34.56.2 Server2
0

If you REALLY want to ensure you only communicate via the public interfaces, then have the ssh sever(s) only listen for connections on the public interfaces. Assuming you're using openssh or some variant open your /etc/ssh/sshd_config (that's a common path for it) and add:

ListenAddress <your.public.ip.address>

If you have lines such as this in there:

ListenAddress ::
ListenAddress 0.0.0.0

Comment them out (you may have them already commented out as I believe all interfaces is the default)

Then follow Massimo's advice above for using proper IP address and/or hosts entries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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