How to find static IP of the Linux server using command line
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
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.
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
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.
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.
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;
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.