title: sed: replace ip in hosts file, using hostname as pattern
body: <p>I'm learning about sed but it is very difficult to me understand it.</p>
  
  <p>I have adsl with dynamic ip so and i want to put current ip on hosts file.</p>
  
  <p>This following script just tells me the current wan ip address and no more:</p>
  
  <pre><code>IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
  echo $IP
  </code></pre>
  
  <p>The result:</p>
  
  <pre><code>192.42.7.73
  </code></pre>
  
  <p>So, i have a line on hosts file with the old ip address:</p>
  
  <pre><code>190.42.44.22   peep.strudel.com
  </code></pre>
  
  <p>and i want to update host file like this:</p>
  
  <pre><code>192.42.7.73    peep.strudel.com
  </code></pre>
  
  <p>How can i do it? I think i can use the hostname as pattern...</p>
  
  <p>The reason of doing this is because my server is a client of my router, so it access the internet thru its gateway and not directly. And postfix always is logging me that "connect from unknown [x.x.x.x]" (where x.x.x.x is my wan ip!) and it can't resolve that ip. I think that maybe if i specify this relating with my fqdn host/domain, on hosts file it will works better.</p>
  
  <p>Thanks
  Sergio.</p>