0

How to find the internal IP and external IP of a linux server by connecting to it using Putty? Secondly, what is the IP address given by the echo $SSH_CLIENT command, is it internal or external?

My last question is - Is Back netip and external ip same?

0

2 Answers 2

4

Once you have connected to the server, these commands will get you the information you want (I will assume that this is a simple setup where the server has one network interface and IP configured) :

  1. Get the server's internal IP:

    ip addr show | perl -ne '/inet\s*([\d\.]+).*global/ && do {print "$1\n"}'
    

    The ip addr show command returns quite a lot of information (run it by itself once to see), I pass its output to a Perl one-liner that looks for an IP address (a stretch of digits and dots: [\d\.]+) on a line that contains the words inet and global and prints the IP found.

  2. Get the server's external IP:

    wget -qO - http://cfajohnson.com/ipaddr.cgi
    

The SSH_CLIENT variable contains the following information:

echo $SSH_CLIENT
123.456.78.90 36436 22
------------- ----- --
      |         |   |-----> The server's TCP port
      |         |---------> The client's (your local pc) TCP port
      |-------------------> The client's IP address 

No idea what you mean by Back netip.

1

On Linux, at a command prompt, you can find the internal IP address by typing /sbin/ifconfig (typically look for the device eth0 - the address associated with that is the internal IP address). As a side note, 127.0.0.1 is always a local address of that PC on a correctly configured IPV4 network.

Assuming you are talking about a typical home network, where the router is performing NAT, you can't tell the systems external IP address directly, you will need to get this reflected off the wider internet.

lynx http://www.whatismyip.com
will do that for you.

I am unfamiliar with the term "Back netip" - you may want to provide more context, as these are not terms typically used when talking in Linux and Networks.

It appears that $SSH_CLIENT is the "IP address, source port and destination port" that a box you have SSH'd into associates with the connection, ie the computer that connected too it.

You must log in to answer this question.

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