LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to find static IP of the Linux server using command line (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-static-ip-of-the-linux-server-using-command-line-4175486684/)

unclesamcrazy 12-03-2013 07:41 AM

How to find static IP of the Linux server using command line
 
I am trying to detect static IP of the server using command line.
I have tried command ifconfig but it shows only LAN IP.

Please help.

rtmistler 12-03-2013 07:53 AM

Please reword that question. What's the server? The system you have the command line for? Well, ifconfig is the correct command. If you're asking what the address of another system is, that can be any address which fits within your network hierarchy.

pan64 12-03-2013 07:59 AM

ifconfig will show the ip of the current (actual) host, nslookup can be used to check another (remote) host.

unclesamcrazy 12-03-2013 08:08 AM

No my static IP of the Linux server is same as I found on site
http://whatismyipaddress.com

Here it shows the IP, it is my static IP. I can use this IP to access my server outside LAN
but I want to store it in variable, how can I do it when it does not show it in output of ifconfig.

It is common IP of my LAN. Common means if I open above website from any system of the LAN, it shows this same IP.

andrew01 12-03-2013 08:27 AM

Try "ip a" or "ifconfig -a" .

unclesamcrazy 12-03-2013 08:34 AM

Quote:

Originally Posted by andrew01 (Post 5074607)
Try "ip a" or "ifconfig -a" .

No, Not working.:(

rtmistler 12-03-2013 08:42 AM

Is it always the same IP? I'm doubting that this is guaranteed, unless your IT guarantees it. I'm sure they would prefer to use hostname. I do understand that there is some public IP for your station, but that is from a pool. The truth is, 99.99% of the time, that will be the public IP for your system, until such time that your IT department changes the nature of the network, and then it may totally change to something vastly different.

So talk with that department, if there's no assigned hostname, ask for one, or ask what they recommend. Because using "what's my IP" and using that address so you can access remotely will work, but probably not over the long haul.

pan64 12-03-2013 08:46 AM

use ddns service and you can use a name for your host. http://www.noip.com/

bino25 12-03-2013 11:59 AM

What o.s. are you running? If you have RHEL 6, you can do "ip addr show <interface>" where interface is something like eth0.

borgy95 12-03-2013 02:17 PM

using whatismyip and using ifconfig from the console will very likely give two different results.

they will only be the same if there is no NATing going on between your system and the internet, which is highly unlikely whether in an office,cafe,airport,home or just about anywhere unless you have taken steps for this to be the case.

So, ifconfig is your best bet. If you are not satisfied that dhcp is off, go edit the interfaces file. On debian and variants it will be found at /etc/network/interfaces and edit the file accordingly.

suicidaleggroll 12-03-2013 02:28 PM

It appears that everybody here has missed the OP's question. I'm not sure why, it seemed pretty clear to me.

OP - the only IP the machine knows about is its own IP on the local network. If you want to retrieve the machine/network's public IP, then you'll need to go to the web. You can still do this via the command line in one of many ways

http://www.garron.me/en/go2linux/wha...mand-line.html


Personally, I just stick a tiny php page on my 3rd party web host:
Code:

$ cat ip.php
<?php echo $_SERVER['REMOTE_ADDR']?>

Then from any machine I want, I can just run:
Code:

wget -q -O - http://www.mydomain.com/ip.php

Sydney 12-03-2013 02:32 PM

Whatismyip is going to show your gateway Inet side. So most of the time it will not show the IP of that server, if it does your server is running with a direct connection to the internet and would be the same as ifconfig.

suicidaleggroll 12-03-2013 02:33 PM

Quote:

Originally Posted by Sydney (Post 5074823)
Whatismyip is going to show your gateway Inet side.

That's exactly what the OP is looking for. He clearly does not want the machine's local IP, I don't know why people keep giving him instructions on how to retrieve what he's explicitly said he does not want.

Sydney 12-03-2013 03:05 PM

If you add WWW::Mechanize to your Perl you can use this script to screen scrape whatsmyip and dump the value to a file named myip.txt. This Link shows how to install that module.

Code:

#!/usr/bin/perl
# sydney
    use strict;
        use warnings;
    use WWW::Mechanize;
        use IO::Socket::SSL qw( SSL_VERIFY_NONE );
        open my $fh, '>:encoding(UTF-8)', 'myip.txt';       
        # Object Creation
        my $mech = WWW::Mechanize->new(
        'autocheck' => 1,
                ssl_opts => {
                        verify_hostname => 0,
                        SSL_verify_mode => SSL_VERIFY_NONE,
                }
        );
        my $url="http://www.whatismyip.com/";
        $mech->get( $url );
        my $i = $mech->content(format => 'text');
        $i =~ s/.*Your IP://;
        $i =~ s/Proxy.*//;
        print $fh $i;
        close $fh;


frankbell 12-03-2013 09:01 PM

Try this:

Code:

curl ifconfig.me
or this:

Code:

curl ifconfig.me/host
I heard about it on smlr.


All times are GMT -5. The time now is 12:54 PM.