IP address of server


#1

How can I get the ip address of the server that meteor is running on?


#2

You could do something like:

  var os = Npm.require('os');
  
  var getIp = function() {
    // Get interfaces
    var netInterfaces = os.networkInterfaces();
    // Result
    var result = [];
    for (var id in netInterfaces) {
      var netFace = netInterfaces[id];

      for (var i = 0; i < netFace.length; i++) {
        var ip = netFace[i];
        if (ip.internal === false && ip.family === 'IPv4') {
          result.push(ip);
        }
      }
    }
    return result;
  };

  Meteor.methods({
    'server-ip': function() {
      return getIp();
    }
  });

#3

hostname is also useful:

os.hostname()

#4

Great, thanks raix!!


#5

I’m using docker and os.networkInterfaces() is giving me the wrong ip. Still looking for a way to get the host’s ip.


#6

Is it giving you the ip internal to the container?


#7

^ generally speaking it looks like default route should point to the host