LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 12-03-2013, 07:41 AM   #1
unclesamcrazy
Member
 
Registered: May 2013
Posts: 189

Rep: Reputation: 1
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.
 
Old 12-03-2013, 07:53 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,614
Blog Entries: 10

Rep: Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673
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.
 
Old 12-03-2013, 07:59 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,644

Rep: Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501
ifconfig will show the ip of the current (actual) host, nslookup can be used to check another (remote) host.
 
Old 12-03-2013, 08:08 AM   #4
unclesamcrazy
Member
 
Registered: May 2013
Posts: 189

Original Poster
Rep: Reputation: 1
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.
 
Old 12-03-2013, 08:27 AM   #5
andrew01
LQ Newbie
 
Registered: Sep 2013
Posts: 3

Rep: Reputation: Disabled
Try "ip a" or "ifconfig -a" .
 
Old 12-03-2013, 08:34 AM   #6
unclesamcrazy
Member
 
Registered: May 2013
Posts: 189

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by andrew01 View Post
Try "ip a" or "ifconfig -a" .
No, Not working.
 
Old 12-03-2013, 08:42 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,614
Blog Entries: 10

Rep: Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673Reputation: 1673
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.
 
Old 12-03-2013, 08:46 AM   #8
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,644

Rep: Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501Reputation: 2501
use ddns service and you can use a name for your host. http://www.noip.com/
 
Old 12-03-2013, 11:59 AM   #9
bino25
Member
 
Registered: Dec 2010
Posts: 45

Rep: Reputation: 11
What o.s. are you running? If you have RHEL 6, you can do "ip addr show <interface>" where interface is something like eth0.
 
Old 12-03-2013, 02:17 PM   #10
borgy95
Member
 
Registered: Mar 2012
Location: England
Distribution: Debian, Kali, CentOS 7
Posts: 64

Rep: Reputation: Disabled
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.
 
Old 12-03-2013, 02:28 PM   #11
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,393

Rep: Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014
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

Last edited by suicidaleggroll; 12-03-2013 at 02:30 PM.
 
1 members found this post helpful.
Old 12-03-2013, 02:32 PM   #12
Sydney
Member
 
Registered: Mar 2012
Distribution: Scientific Linux
Posts: 147

Rep: Reputation: 36
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.
 
Old 12-03-2013, 02:33 PM   #13
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,393

Rep: Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014
Quote:
Originally Posted by Sydney View Post
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.
 
Old 12-03-2013, 03:05 PM   #14
Sydney
Member
 
Registered: Mar 2012
Distribution: Scientific Linux
Posts: 147

Rep: Reputation: 36
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;
 
Old 12-03-2013, 09:01 PM   #15
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Debian, Mageia, and whatever VMs I happen to be playing with
Posts: 11,794
Blog Entries: 13

Rep: Reputation: 2947Reputation: 2947Reputation: 2947Reputation: 2947Reputation: 2947Reputation: 2947Reputation: 2947Reputation: 2947Reputation: 2947Reputation: 2947Reputation: 2947
Try this:

Code:
curl ifconfig.me
or this:

Code:
curl ifconfig.me/host
I heard about it on smlr.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with find command and rar/unrar command line krakatoa1 *BSD 6 09-11-2012 03:21 PM
Need to find a Command Line Server Book...not GUI!!! ochieman2000 Linux - Server 13 02-08-2012 06:03 AM
ftp to Linux server using One Line command shipon_97 Linux - Newbie 3 08-28-2007 04:46 AM
how to find max memory usage for process in Linux by command line kashameni Linux - Newbie 9 06-01-2007 01:39 AM
Command line looks like static BShocked Mandriva 3 10-25-2005 07:59 AM


All times are GMT -5. The time now is 10:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration