<p>I'm in the process of maintaining a Ruby on Rails app and am looking for an easy way to find the hostname or IP address of the box I'm on (since it's a VM and new instances may have different hostnames or IP addresses). Is there a quick and easy way to do this in Ruby on Rails?</p>

<p>Edit: The answer below is correct but the clarification Craig provided is useful (see also provided link in answer):</p>

<blockquote>
  <p>The [below] code does NOT make a
  connection or send any packets (to
  64.233.187.99 which is google). Since UDP is a stateless protocol connect()
  merely makes a system call which
  figures out how to route the packets
  based on the address and what
  interface (and therefore IP address)
  it should bind to. addr() returns an
  array containing the family (AF_INET),
  local port, and local address (which
  is what we want) of the socket.</p>
</blockquote>

try:
Request.remote_ip
remote_ip()
Determine originating IP address. REMOTE_ADDR is the standard but will
  fail if the user is behind a proxy. HTTP_CLIENT_IP and/or
  HTTP_X_FORWARDED_FOR are set by proxies so check for these if
  REMOTE_ADDR is a proxy. HTTP_X_FORWARDED_FOR may be a comma- delimited
  list in the case of multiple chained proxies; the last address which
  is not trusted is the originating IP.
Update:
Oops, sorry I misread the documentation.