Dynamic IP setup

<p>When having a dynamic IP address, a dynamic DNS service can be used to circumvent issues that may occur as a result of it. </p> <ol> <li> <p>Register an account with the dynamic DNS service of your choice (e.g. <a href="https://no-ip.com">no-ip.com</a>) and configure its settings.</p> <blockquote> <blockquote> <blockquote> <p>When choosing a different dynamic DNS service, be aware that some "dynamic DNS" services only provide IP forwards, rather than actual DNS lookups!</p> </blockquote> </blockquote> </blockquote> </li> <li> <p>Set up your router to use the dynamic DNS service of your choice.</p> <blockquote> <blockquote> <blockquote> <p>The way to set up your router varies heavily on the hardware used, please consult the applicable documentation of your hardware</p> </blockquote> </blockquote> </blockquote> </li> <li> <p>Install dnsutils on the system that runs Postfix to enable dynamical changes to the postfix configuration file:</p> <pre><code class="language-shell">apt install -y dnsutils</code></pre> </li> <li> <p>Use <code>crontab -e</code> on the system that runs Postfix to schedule an 8-hourly hostname update:</p> <pre><code class="language-diff"> # m h dom mon dow command + 0 */8 * * * /usr/sbin/postconf -e "myhostname=$(dig +short -x $(dig +short &lt;DDNS NAME&gt;)| sed "s/\.$//")" &amp;&amp; systemctl reload postfix</code></pre> <blockquote> <blockquote> <blockquote> <p>Replace <code>&lt;DDNS NAME&gt;</code> with the name registered at the dynamic DNS service of your choice.</p> </blockquote> </blockquote> </blockquote> </li> <li> <p>Configure your DNS registrar's records to retrieve the IP address from the dynamic DNS service:</p> <pre><code class="language-shell">| Host | Type | Content | |---------|-------|-------------------| | @ | MX | 10 &lt;DDNS NAME&gt;. | | imap | CNAME | &lt;DDNS NAME&gt;. | | smtp | CNAME | &lt;DDNS NAME&gt;. | | webmail | CNAME | &lt;DDNS NAME&gt;. |</code></pre> <blockquote> <blockquote> <blockquote> <p>Replace <code>&lt;DDNS NAME&gt;</code> with the name registered at the dynamic DNS service of your choice. <br/> <strong>NB:</strong> Don't forget the period "." (dot character) after end of the domain name! <br/> </p> </blockquote> </blockquote> </blockquote> </li> <li> <p>Execute the scheduled cronjob manually to update the properly configure the hostname.</p> <pre><code class="language-shell">postconf -e "myhostname=$(dig +short -x $(dig +short &lt;DDNS NAME&gt;)| sed "s/\.$//")" &amp;&amp; systemctl reload postfix</code></pre> </li> <li> <p>Run the SMTP diagnostics tests from <a href="https://mxtoolbox.com/diagnostic.aspx">mxtoolbox.com</a> on <code>smtp.&lt;DOMAIN NAME&gt;</code> to verify the IP and hostname are now correctly set up</p> <blockquote> <blockquote> <blockquote> <p>Keep in mind that changes to your DNS may take some time to persist!</p> </blockquote> </blockquote> </blockquote> </li> </ol>