How do I find my internal ip address?












190















I have Ubuntu server 12.04 installed, so I have no GUI. When I do the command ifconfig, I cannot find my internl ip address. It says inet addr: 127.0.0.1 .



Here is the output of ifconfig -a:



eth0   link encap:Ethernet  HWaddr 00:06:4f:4a:66:f0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

eth1 link encap:Ethernet HWaddr 00:16:ec:05:c8:9c
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr 127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:1800 errors:0 dropped:0 overruns:0 frame:0
Tx packets:1800 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:143896 (143.b KB) TX bytes:143896 (143.8 KB)


here are the contents of etc/network/interfaces:



# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp


If someone could edit this for me, the contents of etc/network/interfaces should be on seperate lines.



The output of host askubuntu.com was:



;; connection timed out; no servers could be reached.


I set up owncloud and webmin a few months ago and was using them for a month with no problems. I think the power went off one day 2 months ago and I never turned the server back on until yesterday. I haven't done anything that would have affected the internet setup So i'm not sure why it doesn't work anymore. As far as my network topology goes, I have a pci-e network card for the pc. The ethernet line goes from the network card to a switch, and then to a modem/router from there.










share|improve this question




















  • 1





    @AvatarParto Those are for interfaces facing public access, this question is about internal networks...

    – Bruno Pereira
    Mar 7 '14 at 14:17











  • Out of curiosity, what does /etc/network/interfaces have in it?

    – Powerlord
    Mar 7 '14 at 15:54











  • I know how to use the change directory command, but I do not know how to list the files once there, how would I do this?

    – Cam Jones
    Mar 7 '14 at 16:05











  • ls will list files in a directory. ls -l will give a detailed listing. To list contents of a particular directory, ls -l /etc/network. To change into a directory and list contents cd /etc/network ;ls -l. To read the contents of etc/network/interfaces (this is a file) sudo pico /etc/network/interfaces. (pico is a lightweight text editor - good for reading & basic editing, and less intimidating than vi.)

    – douggro
    Mar 7 '14 at 16:18


















190















I have Ubuntu server 12.04 installed, so I have no GUI. When I do the command ifconfig, I cannot find my internl ip address. It says inet addr: 127.0.0.1 .



Here is the output of ifconfig -a:



eth0   link encap:Ethernet  HWaddr 00:06:4f:4a:66:f0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

eth1 link encap:Ethernet HWaddr 00:16:ec:05:c8:9c
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr 127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:1800 errors:0 dropped:0 overruns:0 frame:0
Tx packets:1800 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:143896 (143.b KB) TX bytes:143896 (143.8 KB)


here are the contents of etc/network/interfaces:



# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp


If someone could edit this for me, the contents of etc/network/interfaces should be on seperate lines.



The output of host askubuntu.com was:



;; connection timed out; no servers could be reached.


I set up owncloud and webmin a few months ago and was using them for a month with no problems. I think the power went off one day 2 months ago and I never turned the server back on until yesterday. I haven't done anything that would have affected the internet setup So i'm not sure why it doesn't work anymore. As far as my network topology goes, I have a pci-e network card for the pc. The ethernet line goes from the network card to a switch, and then to a modem/router from there.










share|improve this question




















  • 1





    @AvatarParto Those are for interfaces facing public access, this question is about internal networks...

    – Bruno Pereira
    Mar 7 '14 at 14:17











  • Out of curiosity, what does /etc/network/interfaces have in it?

    – Powerlord
    Mar 7 '14 at 15:54











  • I know how to use the change directory command, but I do not know how to list the files once there, how would I do this?

    – Cam Jones
    Mar 7 '14 at 16:05











  • ls will list files in a directory. ls -l will give a detailed listing. To list contents of a particular directory, ls -l /etc/network. To change into a directory and list contents cd /etc/network ;ls -l. To read the contents of etc/network/interfaces (this is a file) sudo pico /etc/network/interfaces. (pico is a lightweight text editor - good for reading & basic editing, and less intimidating than vi.)

    – douggro
    Mar 7 '14 at 16:18
















190












190








190


68






I have Ubuntu server 12.04 installed, so I have no GUI. When I do the command ifconfig, I cannot find my internl ip address. It says inet addr: 127.0.0.1 .



Here is the output of ifconfig -a:



eth0   link encap:Ethernet  HWaddr 00:06:4f:4a:66:f0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

eth1 link encap:Ethernet HWaddr 00:16:ec:05:c8:9c
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr 127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:1800 errors:0 dropped:0 overruns:0 frame:0
Tx packets:1800 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:143896 (143.b KB) TX bytes:143896 (143.8 KB)


here are the contents of etc/network/interfaces:



# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp


If someone could edit this for me, the contents of etc/network/interfaces should be on seperate lines.



The output of host askubuntu.com was:



;; connection timed out; no servers could be reached.


I set up owncloud and webmin a few months ago and was using them for a month with no problems. I think the power went off one day 2 months ago and I never turned the server back on until yesterday. I haven't done anything that would have affected the internet setup So i'm not sure why it doesn't work anymore. As far as my network topology goes, I have a pci-e network card for the pc. The ethernet line goes from the network card to a switch, and then to a modem/router from there.










share|improve this question
















I have Ubuntu server 12.04 installed, so I have no GUI. When I do the command ifconfig, I cannot find my internl ip address. It says inet addr: 127.0.0.1 .



Here is the output of ifconfig -a:



eth0   link encap:Ethernet  HWaddr 00:06:4f:4a:66:f0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

eth1 link encap:Ethernet HWaddr 00:16:ec:05:c8:9c
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr 127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:1800 errors:0 dropped:0 overruns:0 frame:0
Tx packets:1800 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:143896 (143.b KB) TX bytes:143896 (143.8 KB)


here are the contents of etc/network/interfaces:



# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp


If someone could edit this for me, the contents of etc/network/interfaces should be on seperate lines.



The output of host askubuntu.com was:



;; connection timed out; no servers could be reached.


I set up owncloud and webmin a few months ago and was using them for a month with no problems. I think the power went off one day 2 months ago and I never turned the server back on until yesterday. I haven't done anything that would have affected the internet setup So i'm not sure why it doesn't work anymore. As far as my network topology goes, I have a pci-e network card for the pc. The ethernet line goes from the network card to a switch, and then to a modem/router from there.







networking






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 6 '18 at 14:40









waltinator

22.4k74169




22.4k74169










asked Mar 7 '14 at 13:20









Cam JonesCam Jones

1,27171625




1,27171625








  • 1





    @AvatarParto Those are for interfaces facing public access, this question is about internal networks...

    – Bruno Pereira
    Mar 7 '14 at 14:17











  • Out of curiosity, what does /etc/network/interfaces have in it?

    – Powerlord
    Mar 7 '14 at 15:54











  • I know how to use the change directory command, but I do not know how to list the files once there, how would I do this?

    – Cam Jones
    Mar 7 '14 at 16:05











  • ls will list files in a directory. ls -l will give a detailed listing. To list contents of a particular directory, ls -l /etc/network. To change into a directory and list contents cd /etc/network ;ls -l. To read the contents of etc/network/interfaces (this is a file) sudo pico /etc/network/interfaces. (pico is a lightweight text editor - good for reading & basic editing, and less intimidating than vi.)

    – douggro
    Mar 7 '14 at 16:18
















  • 1





    @AvatarParto Those are for interfaces facing public access, this question is about internal networks...

    – Bruno Pereira
    Mar 7 '14 at 14:17











  • Out of curiosity, what does /etc/network/interfaces have in it?

    – Powerlord
    Mar 7 '14 at 15:54











  • I know how to use the change directory command, but I do not know how to list the files once there, how would I do this?

    – Cam Jones
    Mar 7 '14 at 16:05











  • ls will list files in a directory. ls -l will give a detailed listing. To list contents of a particular directory, ls -l /etc/network. To change into a directory and list contents cd /etc/network ;ls -l. To read the contents of etc/network/interfaces (this is a file) sudo pico /etc/network/interfaces. (pico is a lightweight text editor - good for reading & basic editing, and less intimidating than vi.)

    – douggro
    Mar 7 '14 at 16:18










1




1





@AvatarParto Those are for interfaces facing public access, this question is about internal networks...

– Bruno Pereira
Mar 7 '14 at 14:17





@AvatarParto Those are for interfaces facing public access, this question is about internal networks...

– Bruno Pereira
Mar 7 '14 at 14:17













Out of curiosity, what does /etc/network/interfaces have in it?

– Powerlord
Mar 7 '14 at 15:54





Out of curiosity, what does /etc/network/interfaces have in it?

– Powerlord
Mar 7 '14 at 15:54













I know how to use the change directory command, but I do not know how to list the files once there, how would I do this?

– Cam Jones
Mar 7 '14 at 16:05





I know how to use the change directory command, but I do not know how to list the files once there, how would I do this?

– Cam Jones
Mar 7 '14 at 16:05













ls will list files in a directory. ls -l will give a detailed listing. To list contents of a particular directory, ls -l /etc/network. To change into a directory and list contents cd /etc/network ;ls -l. To read the contents of etc/network/interfaces (this is a file) sudo pico /etc/network/interfaces. (pico is a lightweight text editor - good for reading & basic editing, and less intimidating than vi.)

– douggro
Mar 7 '14 at 16:18







ls will list files in a directory. ls -l will give a detailed listing. To list contents of a particular directory, ls -l /etc/network. To change into a directory and list contents cd /etc/network ;ls -l. To read the contents of etc/network/interfaces (this is a file) sudo pico /etc/network/interfaces. (pico is a lightweight text editor - good for reading & basic editing, and less intimidating than vi.)

– douggro
Mar 7 '14 at 16:18












8 Answers
8






active

oldest

votes


















192














These commands will tell you all network info



ip add


or



ifconfig -a


If as you say it only gives you 127.0.0.1 then there are two options:




  1. Your network card is not attached or not recognized by the system


  2. Your network DHCP server is not runnning or not connected







share|improve this answer


























  • when I log in it tells me there are a few upgrades or updates, so I assume it has to talk to official ubuntu website to know it has updates, So i think my internet is working.

    – Cam Jones
    Mar 7 '14 at 13:35











  • @Skateguy try to open askubuntu.com and please print all ifconfig -a

    – kamil
    Mar 7 '14 at 13:36













  • I have no GUI, i am about to type it out though.

    – Cam Jones
    Mar 7 '14 at 13:53






  • 1





    How can I answer the questions that your two options pose?

    – Cam Jones
    Mar 7 '14 at 14:58






  • 1





    I would suggest the ip option first, then the (deprecated) ifconfig afterwards.

    – Campa
    Jan 23 at 8:49





















178














This is what I currently recommend:



ip route get 8.8.8.8 | awk '{print $NF; exit}'



The advantage of that command is that you don't have to know which interface you are using (eth0? eth1? or maybe wlan0?), you don't have to filter out localhost addresses, or Docker addresses, or VPN tunnels etc. and you will always get the IP address that is currently used for Internet connections at that very moment (important when e.g. you are connected with both ethernet and wifi or via VPN etc.).



This will test not only that you have a correct IP configured on some interface (like with parsing the output of ifconfig) but also that you have the routing table configured to use it correctly.



I found that idea in this answer
by Collin Anderson.



I use it in the internalip script in my scripts collection on GitHub, which you can install with:



wget https://rawgit.com/rsp/scripts/master/internalip
chmod a+x internalip


and use as:



internalip


or:



internalip TARGET


and you will get your IP address that would be used to connect with the TARGET IP address. The default target is 8.8.8.8 which is the Google's public DNS resolver and a good default for the Internet.



But if you run it with a different IP:



internalip 127.2.3.4


Then you will get:



127.0.0.1


because that is your IP address that would be used to connect with 127.2.3.4 on the loopback interface. It's useful when your target is on a LAN, VPN or other special network, in which case some other IP could be used for connections than the default IP for reaching the Internet.



External IP



To check your external IP address (the one that the servers on the Internet see when you connect to them - which may be different than the internal IP address described here) see this answer.






share|improve this answer





















  • 1





    this is an awesome answer, thanks! saved me so much headache! :D

    – user65165
    Jul 9 '15 at 17:17











  • This is a useful trick, but the OP was asking about an internal IP, so imay not be not safe to assume that it's routable to 8.8.8.8.

    – mc0e
    Nov 27 '15 at 13:52











  • @mc0e Good point. That's why my script takes an optional argument for some other IP - 8.8.8.8 is just the default. In my answer I used 127.2.3.4 as an example. You can use some IP on your intranet or on a VPN as well. The point is that you don't usually have one internal IP address but few different addresses used for different targets. This way you can find the one that is actually used for connections to a given target.

    – rsp
    Nov 27 '15 at 15:50








  • 1





    Just so you know, this gives the external IP on Mac.

    – OZZIE
    Mar 29 '18 at 12:53





















170














hostname -I


This will give you just ip address without any extra information.






share|improve this answer



















  • 12





    That's perfect. So many overly complicated (but not bad) answers.. this one is just dead simple.

    – user1003916
    Jun 16 '16 at 22:22






  • 2





    Perfect answer..:)

    – john400
    Jul 8 '16 at 4:25






  • 2





    According to man page: ` -I, --all-ip-addresses Display all network addresses of the host. This option enumer‐ ates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted.` So this will give you ip address on the network you're connected to , but also IP of your machine if you're using it as ethernet or lxd server. In my case it gives two addresses because I have lxd : 192.168.0.78 and 10.0.3.1

    – Sergiy Kolodyazhnyy
    Sep 4 '16 at 18:10






  • 4





    Yep. In my case it's more badly 10.0.2.15 172.18.0.1 172.17.0.1 172.20.0.1 172.21.0.1 172.22.0.1 172.19.0.1 because I'm running some Docker containers ;)

    – Alex
    Oct 6 '16 at 16:45






  • 3





    Upvote because other solutions don't work e.g. on raw docker ubuntu image

    – noonex
    Feb 5 '17 at 13:21



















18














I think it worth mentioning that running ifconfig along with -a option will display all interfaces wether or not the interface has an IP.



running ifconfig alone, will display only interfaces with IPs assigned.



Here is a nice trick you could use to display only IPs using Perl.



# ifconfig | perl -nle'/dr:(S+)/ && print $1'
192.168.1.100
127.0.0.1


Your network card is recognized by the system, that why its showing up eth0 and eth1



here is a quick way of assigning IP to your interface, use valid IP/Subnet accordingly.



 ifconfig eth0 192.168.1.200/24 up 


then we need to add a default route



route add default gw 192.168.1.1


Best,






share|improve this answer



















  • 1





    I would try this method but you will have to break it down a little more for me to understand it, as in how to find or know a valid IP, subnet and a valid default route.

    – Cam Jones
    Mar 8 '14 at 23:30











  • this is a static IP assignment for your network interface, meaning if you are behind a router with subnet of 192.168.1.0/24 then you can ping an ip ex. 192.168.1.200 and if you get no response, then go a head and use ifconfig interface_name IP_ADDRESS/MASK up Your default gw needs to be added after assigning IP.

    – user1007727
    Mar 12 '14 at 19:17



















8














This command will show all the IP addresses for a single device:



dev=eth0
ip addr show $dev | awk '/inet/ {print $2}' | cut -d/ -f1


It will print one or two lines of output. The first one is the inet/IPv4 address and the other one is inet6/IPv6 if your system is configured to support this.






share|improve this answer































    6














    In case, the ifconfig command didn't display the IP address, there is a very simple and easy way to find out the IP address of the Ubuntu machine through the GUI. Follow the steps below:



    Click the network icon in the notification area and click Connection Information.
    Network icon options



    This brings up a window which has a some information, including the IP address.
    IP address information






    share|improve this answer































      1














      There's lots of good answers here to choose from already, but I thought I'd point out facter which is usually, but not necessarily used with puppet for collecting various facts about the system. The main advantage of facter is that it gives nice clean output which saves you all the manipulation with grep, sed, awk, cut, perl, etc. It isn't going to tell you which interface you're interested in, but if you know that, then the following gives you the IP without other cruft to clean up:



      facter ipaddress_eth0 





      share|improve this answer































        1














        ip command



        Here's a variation on ip addr way.



        ip has -o option which allows putting all information on single line - this is useful for parsing with tools like awk or perl. In combination with -4 option, we will only see IPv4 addresses. Thus, output would be something like this (note - replace wlan7 with the interface you want to check):



        $ ip -4 -o addr show wlan7
        3: wlan7 inet 192.168.0.78/24 brd 192.168.0.255 scope global dynamic wlan7 valid_lft 85654sec preferred_lft 85654sec


        As you can see, the IP address is 4th column/word in the output. The rest , is simple parsing exercise via the tool of your choice. Here, I'm using python:



        ip -4 -o addr show wlan7 | python -c "import sys;print sys.stdin.readlines()[0].split()[3]" 


        Same thing, only with here string <<< and command substitution $()



        python -c "import sys;print sys.stdin.readlines()[0].split()[3]"  <<< $(ip -4 -o addr show wlan7)


        Personally, I have this saved as a nice function in my ~/.bashrc so less typing is done.



        wlan_ip() {
        ip -4 -o addr show wlan7 | python -c "import sys;print sys.stdin.readlines()[0].split()[3]"
        }


        Perl's and Ruby's version are a bit shorter:



        $ ip -4 -o addr show  wlan7 | perl -lane 'print $F[3]'                         
        192.168.0.78/24

        $ ip -4 -o addr show wlan7 | ruby -n -e 'print $_.split()[3]'
        192.168.0.78/24


        Wireshark



        If you're familiar with using network analysis tools, you probably know that to get your ip address, all you need to do is clear the browser cache, start Wireshark capture on the specific interface, and look for http GET packets being transmitted. The destination column will show your ip address






        share|improve this answer






















          protected by Community Mar 31 '16 at 16:29



          Thank you for your interest in this question.
          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



          Would you like to answer one of these unanswered questions instead?














          8 Answers
          8






          active

          oldest

          votes








          8 Answers
          8






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          192














          These commands will tell you all network info



          ip add


          or



          ifconfig -a


          If as you say it only gives you 127.0.0.1 then there are two options:




          1. Your network card is not attached or not recognized by the system


          2. Your network DHCP server is not runnning or not connected







          share|improve this answer


























          • when I log in it tells me there are a few upgrades or updates, so I assume it has to talk to official ubuntu website to know it has updates, So i think my internet is working.

            – Cam Jones
            Mar 7 '14 at 13:35











          • @Skateguy try to open askubuntu.com and please print all ifconfig -a

            – kamil
            Mar 7 '14 at 13:36













          • I have no GUI, i am about to type it out though.

            – Cam Jones
            Mar 7 '14 at 13:53






          • 1





            How can I answer the questions that your two options pose?

            – Cam Jones
            Mar 7 '14 at 14:58






          • 1





            I would suggest the ip option first, then the (deprecated) ifconfig afterwards.

            – Campa
            Jan 23 at 8:49


















          192














          These commands will tell you all network info



          ip add


          or



          ifconfig -a


          If as you say it only gives you 127.0.0.1 then there are two options:




          1. Your network card is not attached or not recognized by the system


          2. Your network DHCP server is not runnning or not connected







          share|improve this answer


























          • when I log in it tells me there are a few upgrades or updates, so I assume it has to talk to official ubuntu website to know it has updates, So i think my internet is working.

            – Cam Jones
            Mar 7 '14 at 13:35











          • @Skateguy try to open askubuntu.com and please print all ifconfig -a

            – kamil
            Mar 7 '14 at 13:36













          • I have no GUI, i am about to type it out though.

            – Cam Jones
            Mar 7 '14 at 13:53






          • 1





            How can I answer the questions that your two options pose?

            – Cam Jones
            Mar 7 '14 at 14:58






          • 1





            I would suggest the ip option first, then the (deprecated) ifconfig afterwards.

            – Campa
            Jan 23 at 8:49
















          192












          192








          192







          These commands will tell you all network info



          ip add


          or



          ifconfig -a


          If as you say it only gives you 127.0.0.1 then there are two options:




          1. Your network card is not attached or not recognized by the system


          2. Your network DHCP server is not runnning or not connected







          share|improve this answer















          These commands will tell you all network info



          ip add


          or



          ifconfig -a


          If as you say it only gives you 127.0.0.1 then there are two options:




          1. Your network card is not attached or not recognized by the system


          2. Your network DHCP server is not runnning or not connected








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 25 at 14:25

























          answered Mar 7 '14 at 13:32









          kamilkamil

          5,23762954




          5,23762954













          • when I log in it tells me there are a few upgrades or updates, so I assume it has to talk to official ubuntu website to know it has updates, So i think my internet is working.

            – Cam Jones
            Mar 7 '14 at 13:35











          • @Skateguy try to open askubuntu.com and please print all ifconfig -a

            – kamil
            Mar 7 '14 at 13:36













          • I have no GUI, i am about to type it out though.

            – Cam Jones
            Mar 7 '14 at 13:53






          • 1





            How can I answer the questions that your two options pose?

            – Cam Jones
            Mar 7 '14 at 14:58






          • 1





            I would suggest the ip option first, then the (deprecated) ifconfig afterwards.

            – Campa
            Jan 23 at 8:49





















          • when I log in it tells me there are a few upgrades or updates, so I assume it has to talk to official ubuntu website to know it has updates, So i think my internet is working.

            – Cam Jones
            Mar 7 '14 at 13:35











          • @Skateguy try to open askubuntu.com and please print all ifconfig -a

            – kamil
            Mar 7 '14 at 13:36













          • I have no GUI, i am about to type it out though.

            – Cam Jones
            Mar 7 '14 at 13:53






          • 1





            How can I answer the questions that your two options pose?

            – Cam Jones
            Mar 7 '14 at 14:58






          • 1





            I would suggest the ip option first, then the (deprecated) ifconfig afterwards.

            – Campa
            Jan 23 at 8:49



















          when I log in it tells me there are a few upgrades or updates, so I assume it has to talk to official ubuntu website to know it has updates, So i think my internet is working.

          – Cam Jones
          Mar 7 '14 at 13:35





          when I log in it tells me there are a few upgrades or updates, so I assume it has to talk to official ubuntu website to know it has updates, So i think my internet is working.

          – Cam Jones
          Mar 7 '14 at 13:35













          @Skateguy try to open askubuntu.com and please print all ifconfig -a

          – kamil
          Mar 7 '14 at 13:36







          @Skateguy try to open askubuntu.com and please print all ifconfig -a

          – kamil
          Mar 7 '14 at 13:36















          I have no GUI, i am about to type it out though.

          – Cam Jones
          Mar 7 '14 at 13:53





          I have no GUI, i am about to type it out though.

          – Cam Jones
          Mar 7 '14 at 13:53




          1




          1





          How can I answer the questions that your two options pose?

          – Cam Jones
          Mar 7 '14 at 14:58





          How can I answer the questions that your two options pose?

          – Cam Jones
          Mar 7 '14 at 14:58




          1




          1





          I would suggest the ip option first, then the (deprecated) ifconfig afterwards.

          – Campa
          Jan 23 at 8:49







          I would suggest the ip option first, then the (deprecated) ifconfig afterwards.

          – Campa
          Jan 23 at 8:49















          178














          This is what I currently recommend:



          ip route get 8.8.8.8 | awk '{print $NF; exit}'



          The advantage of that command is that you don't have to know which interface you are using (eth0? eth1? or maybe wlan0?), you don't have to filter out localhost addresses, or Docker addresses, or VPN tunnels etc. and you will always get the IP address that is currently used for Internet connections at that very moment (important when e.g. you are connected with both ethernet and wifi or via VPN etc.).



          This will test not only that you have a correct IP configured on some interface (like with parsing the output of ifconfig) but also that you have the routing table configured to use it correctly.



          I found that idea in this answer
          by Collin Anderson.



          I use it in the internalip script in my scripts collection on GitHub, which you can install with:



          wget https://rawgit.com/rsp/scripts/master/internalip
          chmod a+x internalip


          and use as:



          internalip


          or:



          internalip TARGET


          and you will get your IP address that would be used to connect with the TARGET IP address. The default target is 8.8.8.8 which is the Google's public DNS resolver and a good default for the Internet.



          But if you run it with a different IP:



          internalip 127.2.3.4


          Then you will get:



          127.0.0.1


          because that is your IP address that would be used to connect with 127.2.3.4 on the loopback interface. It's useful when your target is on a LAN, VPN or other special network, in which case some other IP could be used for connections than the default IP for reaching the Internet.



          External IP



          To check your external IP address (the one that the servers on the Internet see when you connect to them - which may be different than the internal IP address described here) see this answer.






          share|improve this answer





















          • 1





            this is an awesome answer, thanks! saved me so much headache! :D

            – user65165
            Jul 9 '15 at 17:17











          • This is a useful trick, but the OP was asking about an internal IP, so imay not be not safe to assume that it's routable to 8.8.8.8.

            – mc0e
            Nov 27 '15 at 13:52











          • @mc0e Good point. That's why my script takes an optional argument for some other IP - 8.8.8.8 is just the default. In my answer I used 127.2.3.4 as an example. You can use some IP on your intranet or on a VPN as well. The point is that you don't usually have one internal IP address but few different addresses used for different targets. This way you can find the one that is actually used for connections to a given target.

            – rsp
            Nov 27 '15 at 15:50








          • 1





            Just so you know, this gives the external IP on Mac.

            – OZZIE
            Mar 29 '18 at 12:53


















          178














          This is what I currently recommend:



          ip route get 8.8.8.8 | awk '{print $NF; exit}'



          The advantage of that command is that you don't have to know which interface you are using (eth0? eth1? or maybe wlan0?), you don't have to filter out localhost addresses, or Docker addresses, or VPN tunnels etc. and you will always get the IP address that is currently used for Internet connections at that very moment (important when e.g. you are connected with both ethernet and wifi or via VPN etc.).



          This will test not only that you have a correct IP configured on some interface (like with parsing the output of ifconfig) but also that you have the routing table configured to use it correctly.



          I found that idea in this answer
          by Collin Anderson.



          I use it in the internalip script in my scripts collection on GitHub, which you can install with:



          wget https://rawgit.com/rsp/scripts/master/internalip
          chmod a+x internalip


          and use as:



          internalip


          or:



          internalip TARGET


          and you will get your IP address that would be used to connect with the TARGET IP address. The default target is 8.8.8.8 which is the Google's public DNS resolver and a good default for the Internet.



          But if you run it with a different IP:



          internalip 127.2.3.4


          Then you will get:



          127.0.0.1


          because that is your IP address that would be used to connect with 127.2.3.4 on the loopback interface. It's useful when your target is on a LAN, VPN or other special network, in which case some other IP could be used for connections than the default IP for reaching the Internet.



          External IP



          To check your external IP address (the one that the servers on the Internet see when you connect to them - which may be different than the internal IP address described here) see this answer.






          share|improve this answer





















          • 1





            this is an awesome answer, thanks! saved me so much headache! :D

            – user65165
            Jul 9 '15 at 17:17











          • This is a useful trick, but the OP was asking about an internal IP, so imay not be not safe to assume that it's routable to 8.8.8.8.

            – mc0e
            Nov 27 '15 at 13:52











          • @mc0e Good point. That's why my script takes an optional argument for some other IP - 8.8.8.8 is just the default. In my answer I used 127.2.3.4 as an example. You can use some IP on your intranet or on a VPN as well. The point is that you don't usually have one internal IP address but few different addresses used for different targets. This way you can find the one that is actually used for connections to a given target.

            – rsp
            Nov 27 '15 at 15:50








          • 1





            Just so you know, this gives the external IP on Mac.

            – OZZIE
            Mar 29 '18 at 12:53
















          178












          178








          178







          This is what I currently recommend:



          ip route get 8.8.8.8 | awk '{print $NF; exit}'



          The advantage of that command is that you don't have to know which interface you are using (eth0? eth1? or maybe wlan0?), you don't have to filter out localhost addresses, or Docker addresses, or VPN tunnels etc. and you will always get the IP address that is currently used for Internet connections at that very moment (important when e.g. you are connected with both ethernet and wifi or via VPN etc.).



          This will test not only that you have a correct IP configured on some interface (like with parsing the output of ifconfig) but also that you have the routing table configured to use it correctly.



          I found that idea in this answer
          by Collin Anderson.



          I use it in the internalip script in my scripts collection on GitHub, which you can install with:



          wget https://rawgit.com/rsp/scripts/master/internalip
          chmod a+x internalip


          and use as:



          internalip


          or:



          internalip TARGET


          and you will get your IP address that would be used to connect with the TARGET IP address. The default target is 8.8.8.8 which is the Google's public DNS resolver and a good default for the Internet.



          But if you run it with a different IP:



          internalip 127.2.3.4


          Then you will get:



          127.0.0.1


          because that is your IP address that would be used to connect with 127.2.3.4 on the loopback interface. It's useful when your target is on a LAN, VPN or other special network, in which case some other IP could be used for connections than the default IP for reaching the Internet.



          External IP



          To check your external IP address (the one that the servers on the Internet see when you connect to them - which may be different than the internal IP address described here) see this answer.






          share|improve this answer















          This is what I currently recommend:



          ip route get 8.8.8.8 | awk '{print $NF; exit}'



          The advantage of that command is that you don't have to know which interface you are using (eth0? eth1? or maybe wlan0?), you don't have to filter out localhost addresses, or Docker addresses, or VPN tunnels etc. and you will always get the IP address that is currently used for Internet connections at that very moment (important when e.g. you are connected with both ethernet and wifi or via VPN etc.).



          This will test not only that you have a correct IP configured on some interface (like with parsing the output of ifconfig) but also that you have the routing table configured to use it correctly.



          I found that idea in this answer
          by Collin Anderson.



          I use it in the internalip script in my scripts collection on GitHub, which you can install with:



          wget https://rawgit.com/rsp/scripts/master/internalip
          chmod a+x internalip


          and use as:



          internalip


          or:



          internalip TARGET


          and you will get your IP address that would be used to connect with the TARGET IP address. The default target is 8.8.8.8 which is the Google's public DNS resolver and a good default for the Internet.



          But if you run it with a different IP:



          internalip 127.2.3.4


          Then you will get:



          127.0.0.1


          because that is your IP address that would be used to connect with 127.2.3.4 on the loopback interface. It's useful when your target is on a LAN, VPN or other special network, in which case some other IP could be used for connections than the default IP for reaching the Internet.



          External IP



          To check your external IP address (the one that the servers on the Internet see when you connect to them - which may be different than the internal IP address described here) see this answer.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 27 '16 at 16:13

























          answered Apr 3 '15 at 2:49









          rsprsp

          2,11011110




          2,11011110








          • 1





            this is an awesome answer, thanks! saved me so much headache! :D

            – user65165
            Jul 9 '15 at 17:17











          • This is a useful trick, but the OP was asking about an internal IP, so imay not be not safe to assume that it's routable to 8.8.8.8.

            – mc0e
            Nov 27 '15 at 13:52











          • @mc0e Good point. That's why my script takes an optional argument for some other IP - 8.8.8.8 is just the default. In my answer I used 127.2.3.4 as an example. You can use some IP on your intranet or on a VPN as well. The point is that you don't usually have one internal IP address but few different addresses used for different targets. This way you can find the one that is actually used for connections to a given target.

            – rsp
            Nov 27 '15 at 15:50








          • 1





            Just so you know, this gives the external IP on Mac.

            – OZZIE
            Mar 29 '18 at 12:53
















          • 1





            this is an awesome answer, thanks! saved me so much headache! :D

            – user65165
            Jul 9 '15 at 17:17











          • This is a useful trick, but the OP was asking about an internal IP, so imay not be not safe to assume that it's routable to 8.8.8.8.

            – mc0e
            Nov 27 '15 at 13:52











          • @mc0e Good point. That's why my script takes an optional argument for some other IP - 8.8.8.8 is just the default. In my answer I used 127.2.3.4 as an example. You can use some IP on your intranet or on a VPN as well. The point is that you don't usually have one internal IP address but few different addresses used for different targets. This way you can find the one that is actually used for connections to a given target.

            – rsp
            Nov 27 '15 at 15:50








          • 1





            Just so you know, this gives the external IP on Mac.

            – OZZIE
            Mar 29 '18 at 12:53










          1




          1





          this is an awesome answer, thanks! saved me so much headache! :D

          – user65165
          Jul 9 '15 at 17:17





          this is an awesome answer, thanks! saved me so much headache! :D

          – user65165
          Jul 9 '15 at 17:17













          This is a useful trick, but the OP was asking about an internal IP, so imay not be not safe to assume that it's routable to 8.8.8.8.

          – mc0e
          Nov 27 '15 at 13:52





          This is a useful trick, but the OP was asking about an internal IP, so imay not be not safe to assume that it's routable to 8.8.8.8.

          – mc0e
          Nov 27 '15 at 13:52













          @mc0e Good point. That's why my script takes an optional argument for some other IP - 8.8.8.8 is just the default. In my answer I used 127.2.3.4 as an example. You can use some IP on your intranet or on a VPN as well. The point is that you don't usually have one internal IP address but few different addresses used for different targets. This way you can find the one that is actually used for connections to a given target.

          – rsp
          Nov 27 '15 at 15:50







          @mc0e Good point. That's why my script takes an optional argument for some other IP - 8.8.8.8 is just the default. In my answer I used 127.2.3.4 as an example. You can use some IP on your intranet or on a VPN as well. The point is that you don't usually have one internal IP address but few different addresses used for different targets. This way you can find the one that is actually used for connections to a given target.

          – rsp
          Nov 27 '15 at 15:50






          1




          1





          Just so you know, this gives the external IP on Mac.

          – OZZIE
          Mar 29 '18 at 12:53







          Just so you know, this gives the external IP on Mac.

          – OZZIE
          Mar 29 '18 at 12:53













          170














          hostname -I


          This will give you just ip address without any extra information.






          share|improve this answer



















          • 12





            That's perfect. So many overly complicated (but not bad) answers.. this one is just dead simple.

            – user1003916
            Jun 16 '16 at 22:22






          • 2





            Perfect answer..:)

            – john400
            Jul 8 '16 at 4:25






          • 2





            According to man page: ` -I, --all-ip-addresses Display all network addresses of the host. This option enumer‐ ates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted.` So this will give you ip address on the network you're connected to , but also IP of your machine if you're using it as ethernet or lxd server. In my case it gives two addresses because I have lxd : 192.168.0.78 and 10.0.3.1

            – Sergiy Kolodyazhnyy
            Sep 4 '16 at 18:10






          • 4





            Yep. In my case it's more badly 10.0.2.15 172.18.0.1 172.17.0.1 172.20.0.1 172.21.0.1 172.22.0.1 172.19.0.1 because I'm running some Docker containers ;)

            – Alex
            Oct 6 '16 at 16:45






          • 3





            Upvote because other solutions don't work e.g. on raw docker ubuntu image

            – noonex
            Feb 5 '17 at 13:21
















          170














          hostname -I


          This will give you just ip address without any extra information.






          share|improve this answer



















          • 12





            That's perfect. So many overly complicated (but not bad) answers.. this one is just dead simple.

            – user1003916
            Jun 16 '16 at 22:22






          • 2





            Perfect answer..:)

            – john400
            Jul 8 '16 at 4:25






          • 2





            According to man page: ` -I, --all-ip-addresses Display all network addresses of the host. This option enumer‐ ates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted.` So this will give you ip address on the network you're connected to , but also IP of your machine if you're using it as ethernet or lxd server. In my case it gives two addresses because I have lxd : 192.168.0.78 and 10.0.3.1

            – Sergiy Kolodyazhnyy
            Sep 4 '16 at 18:10






          • 4





            Yep. In my case it's more badly 10.0.2.15 172.18.0.1 172.17.0.1 172.20.0.1 172.21.0.1 172.22.0.1 172.19.0.1 because I'm running some Docker containers ;)

            – Alex
            Oct 6 '16 at 16:45






          • 3





            Upvote because other solutions don't work e.g. on raw docker ubuntu image

            – noonex
            Feb 5 '17 at 13:21














          170












          170








          170







          hostname -I


          This will give you just ip address without any extra information.






          share|improve this answer













          hostname -I


          This will give you just ip address without any extra information.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 25 '15 at 6:29









          Sarath SomanaSarath Somana

          1,801152




          1,801152








          • 12





            That's perfect. So many overly complicated (but not bad) answers.. this one is just dead simple.

            – user1003916
            Jun 16 '16 at 22:22






          • 2





            Perfect answer..:)

            – john400
            Jul 8 '16 at 4:25






          • 2





            According to man page: ` -I, --all-ip-addresses Display all network addresses of the host. This option enumer‐ ates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted.` So this will give you ip address on the network you're connected to , but also IP of your machine if you're using it as ethernet or lxd server. In my case it gives two addresses because I have lxd : 192.168.0.78 and 10.0.3.1

            – Sergiy Kolodyazhnyy
            Sep 4 '16 at 18:10






          • 4





            Yep. In my case it's more badly 10.0.2.15 172.18.0.1 172.17.0.1 172.20.0.1 172.21.0.1 172.22.0.1 172.19.0.1 because I'm running some Docker containers ;)

            – Alex
            Oct 6 '16 at 16:45






          • 3





            Upvote because other solutions don't work e.g. on raw docker ubuntu image

            – noonex
            Feb 5 '17 at 13:21














          • 12





            That's perfect. So many overly complicated (but not bad) answers.. this one is just dead simple.

            – user1003916
            Jun 16 '16 at 22:22






          • 2





            Perfect answer..:)

            – john400
            Jul 8 '16 at 4:25






          • 2





            According to man page: ` -I, --all-ip-addresses Display all network addresses of the host. This option enumer‐ ates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted.` So this will give you ip address on the network you're connected to , but also IP of your machine if you're using it as ethernet or lxd server. In my case it gives two addresses because I have lxd : 192.168.0.78 and 10.0.3.1

            – Sergiy Kolodyazhnyy
            Sep 4 '16 at 18:10






          • 4





            Yep. In my case it's more badly 10.0.2.15 172.18.0.1 172.17.0.1 172.20.0.1 172.21.0.1 172.22.0.1 172.19.0.1 because I'm running some Docker containers ;)

            – Alex
            Oct 6 '16 at 16:45






          • 3





            Upvote because other solutions don't work e.g. on raw docker ubuntu image

            – noonex
            Feb 5 '17 at 13:21








          12




          12





          That's perfect. So many overly complicated (but not bad) answers.. this one is just dead simple.

          – user1003916
          Jun 16 '16 at 22:22





          That's perfect. So many overly complicated (but not bad) answers.. this one is just dead simple.

          – user1003916
          Jun 16 '16 at 22:22




          2




          2





          Perfect answer..:)

          – john400
          Jul 8 '16 at 4:25





          Perfect answer..:)

          – john400
          Jul 8 '16 at 4:25




          2




          2





          According to man page: ` -I, --all-ip-addresses Display all network addresses of the host. This option enumer‐ ates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted.` So this will give you ip address on the network you're connected to , but also IP of your machine if you're using it as ethernet or lxd server. In my case it gives two addresses because I have lxd : 192.168.0.78 and 10.0.3.1

          – Sergiy Kolodyazhnyy
          Sep 4 '16 at 18:10





          According to man page: ` -I, --all-ip-addresses Display all network addresses of the host. This option enumer‐ ates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted.` So this will give you ip address on the network you're connected to , but also IP of your machine if you're using it as ethernet or lxd server. In my case it gives two addresses because I have lxd : 192.168.0.78 and 10.0.3.1

          – Sergiy Kolodyazhnyy
          Sep 4 '16 at 18:10




          4




          4





          Yep. In my case it's more badly 10.0.2.15 172.18.0.1 172.17.0.1 172.20.0.1 172.21.0.1 172.22.0.1 172.19.0.1 because I'm running some Docker containers ;)

          – Alex
          Oct 6 '16 at 16:45





          Yep. In my case it's more badly 10.0.2.15 172.18.0.1 172.17.0.1 172.20.0.1 172.21.0.1 172.22.0.1 172.19.0.1 because I'm running some Docker containers ;)

          – Alex
          Oct 6 '16 at 16:45




          3




          3





          Upvote because other solutions don't work e.g. on raw docker ubuntu image

          – noonex
          Feb 5 '17 at 13:21





          Upvote because other solutions don't work e.g. on raw docker ubuntu image

          – noonex
          Feb 5 '17 at 13:21











          18














          I think it worth mentioning that running ifconfig along with -a option will display all interfaces wether or not the interface has an IP.



          running ifconfig alone, will display only interfaces with IPs assigned.



          Here is a nice trick you could use to display only IPs using Perl.



          # ifconfig | perl -nle'/dr:(S+)/ && print $1'
          192.168.1.100
          127.0.0.1


          Your network card is recognized by the system, that why its showing up eth0 and eth1



          here is a quick way of assigning IP to your interface, use valid IP/Subnet accordingly.



           ifconfig eth0 192.168.1.200/24 up 


          then we need to add a default route



          route add default gw 192.168.1.1


          Best,






          share|improve this answer



















          • 1





            I would try this method but you will have to break it down a little more for me to understand it, as in how to find or know a valid IP, subnet and a valid default route.

            – Cam Jones
            Mar 8 '14 at 23:30











          • this is a static IP assignment for your network interface, meaning if you are behind a router with subnet of 192.168.1.0/24 then you can ping an ip ex. 192.168.1.200 and if you get no response, then go a head and use ifconfig interface_name IP_ADDRESS/MASK up Your default gw needs to be added after assigning IP.

            – user1007727
            Mar 12 '14 at 19:17
















          18














          I think it worth mentioning that running ifconfig along with -a option will display all interfaces wether or not the interface has an IP.



          running ifconfig alone, will display only interfaces with IPs assigned.



          Here is a nice trick you could use to display only IPs using Perl.



          # ifconfig | perl -nle'/dr:(S+)/ && print $1'
          192.168.1.100
          127.0.0.1


          Your network card is recognized by the system, that why its showing up eth0 and eth1



          here is a quick way of assigning IP to your interface, use valid IP/Subnet accordingly.



           ifconfig eth0 192.168.1.200/24 up 


          then we need to add a default route



          route add default gw 192.168.1.1


          Best,






          share|improve this answer



















          • 1





            I would try this method but you will have to break it down a little more for me to understand it, as in how to find or know a valid IP, subnet and a valid default route.

            – Cam Jones
            Mar 8 '14 at 23:30











          • this is a static IP assignment for your network interface, meaning if you are behind a router with subnet of 192.168.1.0/24 then you can ping an ip ex. 192.168.1.200 and if you get no response, then go a head and use ifconfig interface_name IP_ADDRESS/MASK up Your default gw needs to be added after assigning IP.

            – user1007727
            Mar 12 '14 at 19:17














          18












          18








          18







          I think it worth mentioning that running ifconfig along with -a option will display all interfaces wether or not the interface has an IP.



          running ifconfig alone, will display only interfaces with IPs assigned.



          Here is a nice trick you could use to display only IPs using Perl.



          # ifconfig | perl -nle'/dr:(S+)/ && print $1'
          192.168.1.100
          127.0.0.1


          Your network card is recognized by the system, that why its showing up eth0 and eth1



          here is a quick way of assigning IP to your interface, use valid IP/Subnet accordingly.



           ifconfig eth0 192.168.1.200/24 up 


          then we need to add a default route



          route add default gw 192.168.1.1


          Best,






          share|improve this answer













          I think it worth mentioning that running ifconfig along with -a option will display all interfaces wether or not the interface has an IP.



          running ifconfig alone, will display only interfaces with IPs assigned.



          Here is a nice trick you could use to display only IPs using Perl.



          # ifconfig | perl -nle'/dr:(S+)/ && print $1'
          192.168.1.100
          127.0.0.1


          Your network card is recognized by the system, that why its showing up eth0 and eth1



          here is a quick way of assigning IP to your interface, use valid IP/Subnet accordingly.



           ifconfig eth0 192.168.1.200/24 up 


          then we need to add a default route



          route add default gw 192.168.1.1


          Best,







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 '14 at 21:17









          user1007727user1007727

          30115




          30115








          • 1





            I would try this method but you will have to break it down a little more for me to understand it, as in how to find or know a valid IP, subnet and a valid default route.

            – Cam Jones
            Mar 8 '14 at 23:30











          • this is a static IP assignment for your network interface, meaning if you are behind a router with subnet of 192.168.1.0/24 then you can ping an ip ex. 192.168.1.200 and if you get no response, then go a head and use ifconfig interface_name IP_ADDRESS/MASK up Your default gw needs to be added after assigning IP.

            – user1007727
            Mar 12 '14 at 19:17














          • 1





            I would try this method but you will have to break it down a little more for me to understand it, as in how to find or know a valid IP, subnet and a valid default route.

            – Cam Jones
            Mar 8 '14 at 23:30











          • this is a static IP assignment for your network interface, meaning if you are behind a router with subnet of 192.168.1.0/24 then you can ping an ip ex. 192.168.1.200 and if you get no response, then go a head and use ifconfig interface_name IP_ADDRESS/MASK up Your default gw needs to be added after assigning IP.

            – user1007727
            Mar 12 '14 at 19:17








          1




          1





          I would try this method but you will have to break it down a little more for me to understand it, as in how to find or know a valid IP, subnet and a valid default route.

          – Cam Jones
          Mar 8 '14 at 23:30





          I would try this method but you will have to break it down a little more for me to understand it, as in how to find or know a valid IP, subnet and a valid default route.

          – Cam Jones
          Mar 8 '14 at 23:30













          this is a static IP assignment for your network interface, meaning if you are behind a router with subnet of 192.168.1.0/24 then you can ping an ip ex. 192.168.1.200 and if you get no response, then go a head and use ifconfig interface_name IP_ADDRESS/MASK up Your default gw needs to be added after assigning IP.

          – user1007727
          Mar 12 '14 at 19:17





          this is a static IP assignment for your network interface, meaning if you are behind a router with subnet of 192.168.1.0/24 then you can ping an ip ex. 192.168.1.200 and if you get no response, then go a head and use ifconfig interface_name IP_ADDRESS/MASK up Your default gw needs to be added after assigning IP.

          – user1007727
          Mar 12 '14 at 19:17











          8














          This command will show all the IP addresses for a single device:



          dev=eth0
          ip addr show $dev | awk '/inet/ {print $2}' | cut -d/ -f1


          It will print one or two lines of output. The first one is the inet/IPv4 address and the other one is inet6/IPv6 if your system is configured to support this.






          share|improve this answer




























            8














            This command will show all the IP addresses for a single device:



            dev=eth0
            ip addr show $dev | awk '/inet/ {print $2}' | cut -d/ -f1


            It will print one or two lines of output. The first one is the inet/IPv4 address and the other one is inet6/IPv6 if your system is configured to support this.






            share|improve this answer


























              8












              8








              8







              This command will show all the IP addresses for a single device:



              dev=eth0
              ip addr show $dev | awk '/inet/ {print $2}' | cut -d/ -f1


              It will print one or two lines of output. The first one is the inet/IPv4 address and the other one is inet6/IPv6 if your system is configured to support this.






              share|improve this answer













              This command will show all the IP addresses for a single device:



              dev=eth0
              ip addr show $dev | awk '/inet/ {print $2}' | cut -d/ -f1


              It will print one or two lines of output. The first one is the inet/IPv4 address and the other one is inet6/IPv6 if your system is configured to support this.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Oct 24 '14 at 14:14









              Aaron DigullaAaron Digulla

              5693721




              5693721























                  6














                  In case, the ifconfig command didn't display the IP address, there is a very simple and easy way to find out the IP address of the Ubuntu machine through the GUI. Follow the steps below:



                  Click the network icon in the notification area and click Connection Information.
                  Network icon options



                  This brings up a window which has a some information, including the IP address.
                  IP address information






                  share|improve this answer




























                    6














                    In case, the ifconfig command didn't display the IP address, there is a very simple and easy way to find out the IP address of the Ubuntu machine through the GUI. Follow the steps below:



                    Click the network icon in the notification area and click Connection Information.
                    Network icon options



                    This brings up a window which has a some information, including the IP address.
                    IP address information






                    share|improve this answer


























                      6












                      6








                      6







                      In case, the ifconfig command didn't display the IP address, there is a very simple and easy way to find out the IP address of the Ubuntu machine through the GUI. Follow the steps below:



                      Click the network icon in the notification area and click Connection Information.
                      Network icon options



                      This brings up a window which has a some information, including the IP address.
                      IP address information






                      share|improve this answer













                      In case, the ifconfig command didn't display the IP address, there is a very simple and easy way to find out the IP address of the Ubuntu machine through the GUI. Follow the steps below:



                      Click the network icon in the notification area and click Connection Information.
                      Network icon options



                      This brings up a window which has a some information, including the IP address.
                      IP address information







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Sep 24 '15 at 13:09









                      IbungoIbungo

                      23226




                      23226























                          1














                          There's lots of good answers here to choose from already, but I thought I'd point out facter which is usually, but not necessarily used with puppet for collecting various facts about the system. The main advantage of facter is that it gives nice clean output which saves you all the manipulation with grep, sed, awk, cut, perl, etc. It isn't going to tell you which interface you're interested in, but if you know that, then the following gives you the IP without other cruft to clean up:



                          facter ipaddress_eth0 





                          share|improve this answer




























                            1














                            There's lots of good answers here to choose from already, but I thought I'd point out facter which is usually, but not necessarily used with puppet for collecting various facts about the system. The main advantage of facter is that it gives nice clean output which saves you all the manipulation with grep, sed, awk, cut, perl, etc. It isn't going to tell you which interface you're interested in, but if you know that, then the following gives you the IP without other cruft to clean up:



                            facter ipaddress_eth0 





                            share|improve this answer


























                              1












                              1








                              1







                              There's lots of good answers here to choose from already, but I thought I'd point out facter which is usually, but not necessarily used with puppet for collecting various facts about the system. The main advantage of facter is that it gives nice clean output which saves you all the manipulation with grep, sed, awk, cut, perl, etc. It isn't going to tell you which interface you're interested in, but if you know that, then the following gives you the IP without other cruft to clean up:



                              facter ipaddress_eth0 





                              share|improve this answer













                              There's lots of good answers here to choose from already, but I thought I'd point out facter which is usually, but not necessarily used with puppet for collecting various facts about the system. The main advantage of facter is that it gives nice clean output which saves you all the manipulation with grep, sed, awk, cut, perl, etc. It isn't going to tell you which interface you're interested in, but if you know that, then the following gives you the IP without other cruft to clean up:



                              facter ipaddress_eth0 






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 28 '15 at 15:11









                              mc0emc0e

                              274211




                              274211























                                  1














                                  ip command



                                  Here's a variation on ip addr way.



                                  ip has -o option which allows putting all information on single line - this is useful for parsing with tools like awk or perl. In combination with -4 option, we will only see IPv4 addresses. Thus, output would be something like this (note - replace wlan7 with the interface you want to check):



                                  $ ip -4 -o addr show wlan7
                                  3: wlan7 inet 192.168.0.78/24 brd 192.168.0.255 scope global dynamic wlan7 valid_lft 85654sec preferred_lft 85654sec


                                  As you can see, the IP address is 4th column/word in the output. The rest , is simple parsing exercise via the tool of your choice. Here, I'm using python:



                                  ip -4 -o addr show wlan7 | python -c "import sys;print sys.stdin.readlines()[0].split()[3]" 


                                  Same thing, only with here string <<< and command substitution $()



                                  python -c "import sys;print sys.stdin.readlines()[0].split()[3]"  <<< $(ip -4 -o addr show wlan7)


                                  Personally, I have this saved as a nice function in my ~/.bashrc so less typing is done.



                                  wlan_ip() {
                                  ip -4 -o addr show wlan7 | python -c "import sys;print sys.stdin.readlines()[0].split()[3]"
                                  }


                                  Perl's and Ruby's version are a bit shorter:



                                  $ ip -4 -o addr show  wlan7 | perl -lane 'print $F[3]'                         
                                  192.168.0.78/24

                                  $ ip -4 -o addr show wlan7 | ruby -n -e 'print $_.split()[3]'
                                  192.168.0.78/24


                                  Wireshark



                                  If you're familiar with using network analysis tools, you probably know that to get your ip address, all you need to do is clear the browser cache, start Wireshark capture on the specific interface, and look for http GET packets being transmitted. The destination column will show your ip address






                                  share|improve this answer




























                                    1














                                    ip command



                                    Here's a variation on ip addr way.



                                    ip has -o option which allows putting all information on single line - this is useful for parsing with tools like awk or perl. In combination with -4 option, we will only see IPv4 addresses. Thus, output would be something like this (note - replace wlan7 with the interface you want to check):



                                    $ ip -4 -o addr show wlan7
                                    3: wlan7 inet 192.168.0.78/24 brd 192.168.0.255 scope global dynamic wlan7 valid_lft 85654sec preferred_lft 85654sec


                                    As you can see, the IP address is 4th column/word in the output. The rest , is simple parsing exercise via the tool of your choice. Here, I'm using python:



                                    ip -4 -o addr show wlan7 | python -c "import sys;print sys.stdin.readlines()[0].split()[3]" 


                                    Same thing, only with here string <<< and command substitution $()



                                    python -c "import sys;print sys.stdin.readlines()[0].split()[3]"  <<< $(ip -4 -o addr show wlan7)


                                    Personally, I have this saved as a nice function in my ~/.bashrc so less typing is done.



                                    wlan_ip() {
                                    ip -4 -o addr show wlan7 | python -c "import sys;print sys.stdin.readlines()[0].split()[3]"
                                    }


                                    Perl's and Ruby's version are a bit shorter:



                                    $ ip -4 -o addr show  wlan7 | perl -lane 'print $F[3]'                         
                                    192.168.0.78/24

                                    $ ip -4 -o addr show wlan7 | ruby -n -e 'print $_.split()[3]'
                                    192.168.0.78/24


                                    Wireshark



                                    If you're familiar with using network analysis tools, you probably know that to get your ip address, all you need to do is clear the browser cache, start Wireshark capture on the specific interface, and look for http GET packets being transmitted. The destination column will show your ip address






                                    share|improve this answer


























                                      1












                                      1








                                      1







                                      ip command



                                      Here's a variation on ip addr way.



                                      ip has -o option which allows putting all information on single line - this is useful for parsing with tools like awk or perl. In combination with -4 option, we will only see IPv4 addresses. Thus, output would be something like this (note - replace wlan7 with the interface you want to check):



                                      $ ip -4 -o addr show wlan7
                                      3: wlan7 inet 192.168.0.78/24 brd 192.168.0.255 scope global dynamic wlan7 valid_lft 85654sec preferred_lft 85654sec


                                      As you can see, the IP address is 4th column/word in the output. The rest , is simple parsing exercise via the tool of your choice. Here, I'm using python:



                                      ip -4 -o addr show wlan7 | python -c "import sys;print sys.stdin.readlines()[0].split()[3]" 


                                      Same thing, only with here string <<< and command substitution $()



                                      python -c "import sys;print sys.stdin.readlines()[0].split()[3]"  <<< $(ip -4 -o addr show wlan7)


                                      Personally, I have this saved as a nice function in my ~/.bashrc so less typing is done.



                                      wlan_ip() {
                                      ip -4 -o addr show wlan7 | python -c "import sys;print sys.stdin.readlines()[0].split()[3]"
                                      }


                                      Perl's and Ruby's version are a bit shorter:



                                      $ ip -4 -o addr show  wlan7 | perl -lane 'print $F[3]'                         
                                      192.168.0.78/24

                                      $ ip -4 -o addr show wlan7 | ruby -n -e 'print $_.split()[3]'
                                      192.168.0.78/24


                                      Wireshark



                                      If you're familiar with using network analysis tools, you probably know that to get your ip address, all you need to do is clear the browser cache, start Wireshark capture on the specific interface, and look for http GET packets being transmitted. The destination column will show your ip address






                                      share|improve this answer













                                      ip command



                                      Here's a variation on ip addr way.



                                      ip has -o option which allows putting all information on single line - this is useful for parsing with tools like awk or perl. In combination with -4 option, we will only see IPv4 addresses. Thus, output would be something like this (note - replace wlan7 with the interface you want to check):



                                      $ ip -4 -o addr show wlan7
                                      3: wlan7 inet 192.168.0.78/24 brd 192.168.0.255 scope global dynamic wlan7 valid_lft 85654sec preferred_lft 85654sec


                                      As you can see, the IP address is 4th column/word in the output. The rest , is simple parsing exercise via the tool of your choice. Here, I'm using python:



                                      ip -4 -o addr show wlan7 | python -c "import sys;print sys.stdin.readlines()[0].split()[3]" 


                                      Same thing, only with here string <<< and command substitution $()



                                      python -c "import sys;print sys.stdin.readlines()[0].split()[3]"  <<< $(ip -4 -o addr show wlan7)


                                      Personally, I have this saved as a nice function in my ~/.bashrc so less typing is done.



                                      wlan_ip() {
                                      ip -4 -o addr show wlan7 | python -c "import sys;print sys.stdin.readlines()[0].split()[3]"
                                      }


                                      Perl's and Ruby's version are a bit shorter:



                                      $ ip -4 -o addr show  wlan7 | perl -lane 'print $F[3]'                         
                                      192.168.0.78/24

                                      $ ip -4 -o addr show wlan7 | ruby -n -e 'print $_.split()[3]'
                                      192.168.0.78/24


                                      Wireshark



                                      If you're familiar with using network analysis tools, you probably know that to get your ip address, all you need to do is clear the browser cache, start Wireshark capture on the specific interface, and look for http GET packets being transmitted. The destination column will show your ip address







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Sep 4 '16 at 18:32









                                      Sergiy KolodyazhnyySergiy Kolodyazhnyy

                                      72k9148314




                                      72k9148314

















                                          protected by Community Mar 31 '16 at 16:29



                                          Thank you for your interest in this question.
                                          Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                          Would you like to answer one of these unanswered questions instead?



                                          Popular posts from this blog

                                          How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                                          is 'sed' thread safe

                                          How to make a Squid Proxy server?