Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outgoing IP per domain #245

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

outgoing IP per domain #245

wants to merge 14 commits into from

Conversation

runout-at
Copy link
Contributor

@runout-at runout-at commented Oct 12, 2017

this is still missing the part for the webUI.
But i want to discuss if this is going in the right direction.

#30

outgoing ip addresses separated by ';'
for outgoing ip addresses
because this is for outgoing mail we have to lookup the senders IP.
I think this should be taken from the AUTH of the user who logged in to send this message.
last fix was in the wrong line
@runout-at runout-at changed the title outgoing IP outgoing IP per domain Oct 12, 2017
@Udera
Copy link
Collaborator

Udera commented Oct 14, 2017

You are planning that you can put a list of IPs? Or how do you manage ipv4 and ipv6?

@runout-at
Copy link
Contributor Author

The easiest solution would be to have just one additional field in the 'domains' table and put a semicolon separated list of IPs there. This way we can have mix of IPv4 and IPv6 in this field and can use it 'as is' in the transport like interface = <; OUTGOING_IP_ADDRESSES

Maybe the WebUI could be more complex if we like to check/sanitize the values on input or split ddresses in separate fields - but to me, one field would be enough. I wouldn't do checks on every mail in exim.
One could monitor the validity of the addresses with a cron job.

bash script for checking if vexim outgoing ips exists in systems network config
checks the out-IPs from the vexim domains table if they are configured on any systems network interface
bugfix for message text
config now even works with ansible out of the box
check if an ip address has valid syntax using ipv6calc
@runout-at
Copy link
Contributor Author

This is on my production servers for 2 weeks without issues, IPv4/v6 dual stack.

The only part missing here is the transports.
For now i add following to the original Debian transport files but i'm not sure what is the best way to integrate this in vexim:

.ifdef OUTGOING_IP_ADDRESSES
  interface = <; OUTGOING_IP_ADDRESSES
.endif

added to following files:
/etc/exim4/conf.d/transport/30_exim4-config_remote_smtp
/etc/exim4/conf.d/transport/30_exim4-config_remote_smtp_smarthost

@Udera Udera added this to the Version 2.4 milestone Apr 2, 2018
@Udera
Copy link
Collaborator

Udera commented Apr 2, 2018

Let's wait for the 2.4 milestone when the new webinterface is planned. Though it seems very far away.

@runout-at
Copy link
Contributor Author

i think that we can have the actual changes earlier and do the webUI later.

Having different IPs per domain is a good feature. Besides from IPv6 it makes it easier getting mails through spam filters at gmail and others - eg if some domains on a server are sending bulk mails, newsletters,... it's better other mail is going out over a different IP.

@runout-at
Copy link
Contributor Author

I asked the debian packagers to integrate the code for the transports in their package:
http://lists.alioth.debian.org/pipermail/pkg-exim4-users/2018-April/thread.html#2385

@runout-at
Copy link
Contributor Author

A rework of this PR makes sense since Debian has integrated this in the default configs now.

I did use the variable OUTGOING_IP_ADDRESSES. Debian uses REMOTE_SMTP_INTERFACE. That's the only difference.

We only really need the changes in the DB and a config setting to read the IP from the database like:

  • /etc/exim4/conf.d/main/00_vexim_listmacrosdefs
VEXIM_OUTIP = SELECT DISTINCT out_ip FROM domains \
                           WHERE domain = '${quote_mysql:$sender_address_domain}' \
                               AND out_ip <> TRIM('')
OUTGOING_IP_DEFAULT = 2001:db8:: ; 10.0.0.1
REMOTE_SMTP_INTERFACE = ${lookup mysql{VEXIM_OUTIP}{ <; $value }{ <; OUTGOING_IP_DEFAULT }}

@Udera
Copy link
Collaborator

Udera commented Jan 13, 2024

How does the smtp transport know which ip to use (or is this already hidden somewhere)? You just add all of the ip addresses:

The first interface of the correct type (IPv4 or IPv6) is used for the outgoing connection.

https://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_smtp_transport.html

@runout-at
Copy link
Contributor Author

runout-at commented Jan 13, 2024

In Debian split config its in transport/30_exim4-config_remote_smtp

.ifdef REMOTE_SMTP_INTERFACE
  interface = REMOTE_SMTP_INTERFACE
.endif

My code from above #245 (comment) does set the variable REMOTE_SMTP_INTERFACE from the DB-query or a default value.

@runout-at
Copy link
Contributor Author

After reading your comment again, I'm not sure I did understand your question right. Maybe my answer was not sufficient.

If multiple IPs are given in REMOTE_SMTP_INTERFACE, Exim will try each until it finds one that is sufficient. Eg if the connection is IPv4 and the first addresses given are IPv6 it will skip it. At least it works like that on my production sever for several years now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants