exclude local domain from relaying on per domain relay

Discussion in 'General' started by doekia, Jun 18, 2024.

  1. doekia

    doekia Member

    I have per domain relay (relay_host, relay_user, relay_pass on mail domain page)
    This work perfectly for any outbound domain.
    Unfortunately for security reason my relay service does not allow to relay to the domain that is also the initiator.
    I've tried to exclude local domain (either tampering with de mysql-virtual_transports.cf to return ':' for local mail domain or implementing hash table to not available.

    I presume I'm not addressing the issue at the right place, can someone lead me to the proper setting to achieve that - exclude all local destination domain to use the relay.

    Thanks in advance
     
  2. mangoldwen

    mangoldwen New Member

    When using ISPConfig 3, you will still need to work with Postfix configuration, but ISPConfig provides a web interface to manage many of these settings. Here’s how to achieve your goal of excluding local domains from using the relay host within ISPConfig 3:

    1. **Create Transport Map in ISPConfig:**
    - Log in to your ISPConfig 3 control panel.
    - Navigate to "Email" > "Relay Domains" to manage relay settings.

    2. **Edit Transport Map File:**
    Create or update the `/etc/postfix/transport` file to define the routing rules for local and non-local domains.

    ```
    localdomain.com local:
    .localdomain.com local:
    * relay:[relay.example.com]
    ```

    3. **Postmap the Transport File:**
    Convert the transport file to a Postfix lookup table by running:

    ```
    postmap /etc/postfix/transport
    ```

    4. **Update Postfix Configuration in ISPConfig:**
    - Go to "System" > "Server Config" in the ISPConfig control panel.
    - Select the server you want to configure.
    - Navigate to the "Mail" tab.
    - Ensure the "Transport Maps" entry includes the path to your transport file:

    ```
    hash:/etc/postfix/transport
    ```

    You might need to manually edit `/etc/postfix/main.cf` if the ISPConfig interface doesn't cover this specific setting:

    ```
    transport_maps = hash:/etc/postfix/transport
    ```

    5. **Reload Postfix:**
    Reload Postfix to apply the new configuration:

    ```
    sudo systemctl reload postfix
    ```

    6. **Configure Relay Settings in ISPConfig:**
    - Ensure your relay settings are configured in ISPConfig under "Email" > "Relay Domains" and that your relay host, user, and password are correctly set up.

    7. **Verify mydestination Setting:**
    Ensure that the local domains are correctly set in the `mydestination` parameter. This can often be managed directly through the ISPConfig interface under the "Email" settings for each domain.

    ### Example `/etc/postfix/main.cf` in ISPConfig:

    Ensure your main configuration file contains the necessary parameters for your relay and local handling. ISPConfig may automatically handle most of these settings, but verify as needed:

    ```
    myhostname = mail.localdomain.com
    mydomain = localdomain.com
    mydestination = $myhostname, localhost.$mydomain, localhost, localdomain.com

    relayhost = [relay.example.com]
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    smtp_tls_security_level = may
    smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

    transport_maps = hash:/etc/postfix/transport
    ```

    ### Additional Considerations:

    - **Check for ISPConfig Overrides:** ISPConfig may overwrite configurations during its own updates or synchronization. Always check ISPConfig settings if you notice configurations reverting.
    - **ISPConfig Version:** Ensure you are using a version of ISPConfig that supports these configurations. Consult the ISPConfig documentation for any version-specific instructions.

    By integrating these steps within ISPConfig 3, you can manage Postfix configurations effectively, ensuring local domains do not use the relay while other domains do.
     
    ahrasis likes this.
  3. doekia

    doekia Member

    Thanks for your response, however I tend to think you missed the point here.

    In ISP, we can define relay per hosts. It uses the sender_dependent_relayhost_maps from postfix.
    This works as expected when my mail domain sends mail to any outside mail domain, but it works TOO WELL, even when mail domain are local, they get sent thru the relay.
    This break on of the security in place that prevent mails from local domain to be received from an external connection

    I need to exclude local domain from the relay but unfortunately I haven't be able to have a map/list that can filter on either recipient domain and sender domain.
    The bold part is in fact my request here for help

    Best
     
    ahrasis and mangoldwen like this.
  4. ahrasis

    ahrasis Well-Known Member HowtoForge Supporter

    Try (from Ask Ubuntu):

    Open your postfix configuration file (usually /etc/postfix/main.cf) in a text editor. I like vim.
    Code:
    sudo nano /etc/postfix/main.cf
    Find the line where mydestination is set. It probably looks something like this:
    Code:
    mydestination = $myhostname, localhost.$mydomain, localhost
    Comment that line out by prefixing it with a #.
    Code:
    # mydestination = $myhostname, localhost.$mydomain, localhost
    Add the following line and then save the file.
    Code:
    mydestination =
    Restart postfix
    Code:
    service postfix stop
    service postfix start
    Postfix will no longer try to deliver 'local' email to this server but will use the SMTP server given by the DNS MX record.
     

Share This Page