LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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-11-2017, 02:14 PM   #1
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Rep: Reputation: Disabled
Unhappy linux - Finding host IP address


hey guys, i'm trying to figure out how to find the host IP address using shell commands.
So far I have:
hostname -i
ip addr show

These both give me different IPs, which one is the correct host ip? and is it internal or external? from what I understand this is the internal IP of the system
 
Old 12-11-2017, 02:39 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
The IP address of your system will be accessible using the ifconfig(8) command.
 
1 members found this post helpful.
Old 12-11-2017, 02:42 PM   #3
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
The IP address of your system will be accessible using the ifconfig(8) command.
ifconfig is saying I will need superuser privileges though, is there a specific option I can add to it?
 
Old 12-11-2017, 02:49 PM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Use:
Code:
$ sudo ifconfig
When asked for a password you enter your user password.
 
Old 12-11-2017, 03:02 PM   #5
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
Use:
Code:
$ sudo ifconfig
When asked for a password you enter your user password.

I'm currently using an SSH connected to a server, I don't have those privileges.
 
Old 12-11-2017, 03:10 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,727

Rep: Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919
Ifconfig shows the same information as ip addr show.

It show all addresses both the lo and your physical ethernet adapter

Hostname -i shows 127.0.0.1 since your hostname is not resolved because your not running an internal DNS server. See hostname man pages for more information.

127.0.0.1 is the local loop back adapter which is internal or virtual.
 
Old 12-11-2017, 03:13 PM   #7
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Ifconfig shows the same information as ip addr show.

It show all addresses both the lo and your physical ethernet adapter

Hostname -i shows 127.0.0.1 since your hostname is not resolved because your not running an internal DNS server. See hostname man pages for more information.

127.0.0.1 is the local loop back adapter which is internal or virtual.
hostname -i doesn't show me 127.0.0.1 it is showing me an address like:
192.168.x.x which i'm assuming is just a local ip?
 
Old 12-11-2017, 03:18 PM   #8
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
ifconfig can be run by a non-root user by using the full path "/sbin/ifconfig" -- a non-root user won't be able to change anything but can list things all the same.
It really is worth reading up on how IP addresses work (no need to remember any calculations and the like though) as it can be helpful to know.
 
1 members found this post helpful.
Old 12-11-2017, 03:19 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,727

Rep: Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919
Ok. I assumed wrong. 192.168.x.x is a private or local address assigned to your network adapter. I assume by your router or other DHCP server.
 
1 members found this post helpful.
Old 12-11-2017, 03:21 PM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,727

Rep: Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919Reputation: 5919
Yes it is a local or private address. I would assume assigned by your router or internal dhcp server

Having problems with my phone...
 
Old 12-11-2017, 03:25 PM   #11
goofygoober
Member
 
Registered: Nov 2017
Posts: 37

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by 273 View Post
ifconfig can be run by a non-root user by using the full path "/sbin/ifconfig" -- a non-root user won't be able to change anything but can list things all the same.
It really is worth reading up on how IP addresses work (no need to remember any calculations and the like though) as it can be helpful to know.
ah, okay! "/sbin/ifconfig" worked for me, showing me the ethernet and loopback info. So looking at this, and based on what michael said it seems that this is showing the host IP which is a local/internal IP, correct?

Also it seems that it is showing the same address as
hostname -i
except it's cleaner since it shows nothing but the IP.
 
Old 12-11-2017, 03:28 PM   #12
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Quote:
Originally Posted by goofygoober View Post
ah, okay! "/sbin/ifconfig" worked for me, showing me the ethernet and loopback info. So looking at this, and based on what michael said it seems that this is showing the host IP which is a local/internal IP, correct?

Also it seems that it is showing the same address as
hostname -i
except it's cleaner since it shows nothing but the IP.
Yes, it shows the loopback IP address and any local addresses also. The 192.xxxxxx address is always going to be a LAN address which is routed to the internet mostly using NAT. Have a look using google about IP addresses and how things like rooting and subnetting work -- as mentioned above not to learn exactly how the numbers work but to give an idea of how things are connected.
 
1 members found this post helpful.
Old 12-12-2017, 05:04 AM   #13
FlinchX
Member
 
Registered: Nov 2017
Distribution: Slackware Linux
Posts: 666

Rep: Reputation: Disabled
Quote:
Originally Posted by goofygoober View Post
ah, okay! "/sbin/ifconfig" worked for me, showing me the ethernet and loopback info.
If you have many network interfaces, use ifconfig -a
 
  


Reply



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
How to get the ip address of host in linux with using of host and nslookup command hussain.s Linux - General 4 10-23-2010 09:12 PM
unable to fix syntax error in finding ip address of a host name JKingW Programming 8 05-03-2010 11:21 PM
Address Space Randomization on 2.6.28-15-generic ubuntu 9.04. Finding base address nullprocess Linux - Kernel 0 09-14-2009 10:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:52 AM.

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
Open Source Consulting | Domain Registration