I have a lot of issues getting the IP address of localhost on the server.

I have this status:

$ sudo service apache2 status
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
   Active: active (running) since Wed 2018-04-18 11:44:37 UTC; 18h ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3087 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 3132 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
    Tasks: 55
   Memory: 6.0M
      CPU: 53.265s
   CGroup: /system.slice/apache2.service
           ├─3157 /usr/sbin/apache2 -k start
           ├─3162 /usr/sbin/apache2 -k start
           └─3163 /usr/sbin/apache2 -k start

Apr 18 11:44:36 instance-3 systemd[1]: Starting LSB: Apache2 web server...
Apr 18 11:44:36 instance-3 apache2[3132]:  * Starting Apache httpd web server apache2
Apr 18 11:44:37 instance-3 apache2[3132]:  *
Apr 18 11:44:37 instance-3 systemd[1]: Started LSB: Apache2 web server.
Apr 19 03:44:22 instance-3 systemd[1]: Started LSB: Apache2 web server.

When I used:

$ curl -4 icanhazip.com

But then:

$ ifconfig
ens4      Link encap:Ethernet  HWaddr 42:01:0a:9a:00:03  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::4001:aff:fe9a:3/64 Scope:Link
          RX packets:4770059 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5014906 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1059058126 (1.0 GB)  TX bytes:1017190807 (1.0 GB)

lo        Link encap:Local Loopback  
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:910501 errors:0 dropped:0 overruns:0 frame:0
          TX packets:910501 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:153346351 (153.3 MB)  TX bytes:153346351 (153.3 MB)

I use /var/www and I get success for HTML using the IP starting with 35 but the apps using localhost do not work on the server.

I am unsure what is the actual localhost IP address.

Hosts -

>cat /etc/hosts localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts metadata.google.internal metadata instance-3.c.inbound-axon-200905.internal instance-3  # Added by Google metadata.google.internal  # Added by Google
  • Whilst I appreciate all feedback, I do not like my words being changed without even asking me. Some of the changes are subjective and according to someone's own preference. Apr 19, 2018 at 8:36
  • Spurious edits can be annoying. Revert them! If you have problems with localhost, your hosts file may be wrong. Post cat /etc/hosts, there should be localhost defined there.
    – ajeh
    Apr 19, 2018 at 15:07
  • I cannot make head nor tail of the question in any incarnation. It seems not to be about looking up the IP address of localhost at all but about some unspecified "apps" that aren't talking to an HTTP server on the machine, somehow.
    – JdeBP
    Apr 19, 2018 at 18:58
  • I added the hosts output. About apps etc. I am using apps via browsers which all reference localhost. As the machine is cloud based I have to enter an IP address in the browser and that was the basis of my query. I saw the ifconfig output differs from icanhazip and that is what confused me (and the fact the browser apps are not working). Apr 20, 2018 at 9:46
  • What interfaces are your Apache server listening to? There are three IP numbers involved here: (localhost, only accessible on the local machine, and your server is not listening to that), (your IP on the local network, not accessible from the public Internet), and (not your machine's IP but probably the IP of a public-facing firewall that passes traffic to your internal machine on
    – Kusalananda
    Apr 20, 2018 at 9:55

2 Answers 2


Local host uses a loop back address of

From your ifconfig it doesn’t look like that IP is being used on that server.

Try SSH to that IP and see where it’s listed. Although if this is because you’re doing some weird routing or load balancing then you should expand your question to include details of this


Try this solution:

ip address show | grep -E "inet " | grep -v "host"
  • ip address show | grep -E "inet " | grep -v "host" inet brd scope global ens4 Apr 19, 2018 at 8:36
  • You saw that the questioner found that IP address in the question, right?
    – JdeBP
    Apr 19, 2018 at 19:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .