How to add virtual ip with cluster?

H.c.K

Member
Oct 16, 2019
45
3
8
28
Hello,
How can I run any IP address on servers in the entire cluster structure? My goal is this: I can only send mail from one server with random ip addresses in cluster production with 4 servers. I added all the ip addresses to my server with random ip addresses. This time I cannot send mail from my other server with these ip addresses.
Suppose I have an extra 5 ip addresses. I want to be able to send mail from all pmg servers with these 5 ip addresses

My source: https://shami.blog/2016/04/randomize-source-ip-addresses-with-postfix/
 

Stoiko Ivanov

Proxmox Staff Member
Staff member
May 2, 2018
2,986
321
83
Not sure I understand your request completely.
However one IP can normally only be configured on one device (otherwise the router would not know where to send packets for the IP)

You cannot use the 5 same IP-addresses on multiple hosts at the same time (short of things like anycast - but this also does not work with TCP-connections which need to keep a state). You could configure the IPs in a failover config with things like LVS - but this is quite complex and I would not see any benefit (instead of statically configuring one IP on each PMG...)

As for the randomizing source ips - if you want to add those changes to PMG's postfix config you need to use the templateing system:
https://pmg.proxmox.com/pmg-docs/pmg-admin-guide.html#pmgconfig_template_engine

I hope this helps!
 
  • Like
Reactions: H.c.K

H.c.K

Member
Oct 16, 2019
45
3
8
28
Not sure I understand your request completely.
However one IP can normally only be configured on one device (otherwise the router would not know where to send packets for the IP)

You cannot use the 5 same IP-addresses on multiple hosts at the same time (short of things like anycast - but this also does not work with TCP-connections which need to keep a state). You could configure the IPs in a failover config with things like LVS - but this is quite complex and I would not see any benefit (instead of statically configuring one IP on each PMG...)

As for the randomizing source ips - if you want to add those changes to PMG's postfix config you need to use the templateing system:
https://pmg.proxmox.com/pmg-docs/pmg-admin-guide.html#pmgconfig_template_engine

I hope this helps!


Hello Stoiko,
you actually understand what i mean. I use the template system and it works very well.
Main.cf and master.cf are the same on all my servers because it is in the cluster structure.
As an example, the production is as follows:
pmg1.domain.com -> Cluster Master -> Rondom out ips: 1.1.1.1 - 2.2.2.2
master.cf = 1.1.1.1 - 2.2.2.2

pmg2.domain.com -> Cluster Node -> rondom out ips: 3.3.3.3 - 4.4.4.4
master.cf = 1.1.1.1 - 2.2.2.2 (I can't change because the master pulls from the server. If I change it syncs again)
For this reason, I cannot log out from the server of pmg2.domain.com with rondom ip addresses.

If I add 3.3.3.3 - 4.4.4.4 ip addresses to master.cf pmg1.domain.com server, the problem occurs. pmg1.domain.com gives error when it wants to logout because 3.3.3.3 and 4.4.4.4 ip address is not attached.
Because 3.3.3.3 and 4.4.4.4 ip addresses run on the server pmg2.domain.com.
 

Stoiko Ivanov

Proxmox Staff Member
Staff member
May 2, 2018
2,986
321
83
  • Like
Reactions: H.c.K

H.c.K

Member
Oct 16, 2019
45
3
8
28
Ahh - the master.cf.in gets synchronized - right!

see the following thread for how to use the templateing system with IF/ELSIF to change it depending on the nodename:
https://forum.proxmox.com/threads/host-specific-configurations-in-custom-templates.51848/

I hope this helps!
Hi Stoiko,

I examined the subject, but I did not understand how to configure. Can you give an example for the arrangement I will make in main.cf and master.cf?

Would the following example be correct?

Code:
Now pmg1.domain.com main.cf

sender_dependent_default_transport_maps = randmap:{relay1,relay2}
smtp_connection_cache_on_demand=no

after editing:
[%- ELSIF dns.hostname == 'pmg1.domain.com' -%]
sender_dependent_default_transport_maps = randmap:{relay1,relay2}
[%- ELSE %]

[%- ELSIF dns.hostname == 'pmg2.domain.com' -%]
sender_dependent_default_transport_maps = randmap:{relay3,relay4}
[%- ELSE %]
Code:
Now pmg1.domain.com master.cf

relay1     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=1.1.1.1
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay1
relay2     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=2.2.2.2
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay2

after editing:

[%- ELSIF dns.hostname == 'pmg1.domain.com' -%]
relay1     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=1.1.1.1
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay1
relay2     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=2.2.2.2
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay2
[%- ELSE %]

[%- ELSIF dns.hostname == 'pmg2.domain.com' -%]
relay3     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=3.3.3.3
  -o smtp_helo_name=pmg2.domain.com
  -o syslog_name=relay1
relay4     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=4.4.4.4
  -o smtp_helo_name=pmg2.domain.com
  -o syslog_name=relay2
[%- ELSE %]
 
Last edited:

Stoiko Ivanov

Proxmox Staff Member
Staff member
May 2, 2018
2,986
321
83
You need to start the conditional-chain with an IF not with ELSIF (i.e. write IF in the first '[%' bracket)

you can test this by editing the template and running `pmgconfig sync` afterwards (and check the outcome of '/etc/postfix/master.cf'
 
  • Like
Reactions: H.c.K

H.c.K

Member
Oct 16, 2019
45
3
8
28
You need to start the conditional-chain with an IF not with ELSIF (i.e. write IF in the first '[%' bracket)

you can test this by editing the template and running `pmgconfig sync` afterwards (and check the outcome of '/etc/postfix/master.cf'
Hi Stoiko,
Thank you so much. Tonight I will experiment with the following configuration. I will let you know the results.

main.cf
[%- IF dns.hostname == 'pmg1.domain.com' -%]
sender_dependent_default_transport_maps = randmap:{relay1,relay2}
[%- ELSE %]

[%- ELSIF dns.hostname == 'pmg2.domain.com' -%]
sender_dependent_default_transport_maps = randmap:{relay3,relay4}
[%- ELSE %]

master.cf
[%- IF dns.hostname == 'pmg1.domain.com' -%]
relay1 unix - - n - - smtp
-o smtp_bind_address=1.1.1.1
-o smtp_helo_name=pmg1.domain.com
-o syslog_name=relay1
relay2 unix - - n - - smtp
-o smtp_bind_address=2.2.2.2
-o smtp_helo_name=pmg1.domain.com
-o syslog_name=relay2
[%- ELSE %]

[%- ELSIF dns.hostname == 'pmg2.domain.com' -%]
relay3 unix - - n - - smtp
-o smtp_bind_address=3.3.3.3
-o smtp_helo_name=pmg2.domain.com
-o syslog_name=relay1
relay4 unix - - n - - smtp
-o smtp_bind_address=4.4.4.4
-o smtp_helo_name=pmg2.domain.com
-o syslog_name=relay2
[%- ELSE %]
 

Stoiko Ivanov

Proxmox Staff Member
Staff member
May 2, 2018
2,986
321
83
  • Like
Reactions: H.c.K

H.c.K

Member
Oct 16, 2019
45
3
8
28
This will not work - the conditionals are
IF + (optionally ELSEIF ) + ELSE (at the end)

you need to remove the ELSE before the endif - see the template toolkit documentation:
http://www.template-toolkit.org/docs/manual/Directives.html#section_IF_UNLESS_ELSIF_ELSE
Hi Stoiko,

I want to use it for 3 servers. I do not know new with these issues. That's why I'm asking a lot of questions. Thank you.
Is the following configuration correct? I did some research for if and else. I also examined the template page you provided.
pmg1.domain.com -> master
pmg2.domain.com -> node
pmg3.domain.com -> node

Code:
[% IF dns.hostname == 'pmg1.domain.com' %]
relay1     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=1.1.1.1
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay1
relay2     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=2.2.2.2
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay2
 
[% ELSIF dns.hostname == 'pmg2.domain.com' %]
relay3     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=3.3.3.3
  -o smtp_helo_name=pmg2.domain.com
  -o syslog_name=relay3
relay4     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=4.4.4.4
  -o smtp_helo_name=pmg2.domain.com
  -o syslog_name=relay4
 
[% ELSIF dns.hostname == 'pmg3.domain.com' %]
relay5     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=5.5.5.5
  -o smtp_helo_name=pmg3.domain.com
  -o syslog_name=relay5
relay6     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=6.6.6.6
  -o smtp_helo_name=pmg3.domain.com
  -o syslog_name=relay6

[% ELSE %]
(I don't know if I need to write anything here. I think it would be if I wrote the content of pmg1.domain.com.)
 

Stoiko Ivanov

Proxmox Staff Member
Staff member
May 2, 2018
2,986
321
83
I think you should be good with:
Code:
[% IF dns.hostname == 'pmg1.domain.com' %]
relay1     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=1.1.1.1
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay1
relay2     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=2.2.2.2
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=relay2
 
[% ELSIF dns.hostname == 'pmg2.domain.com' %]
relay3     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=3.3.3.3
  -o smtp_helo_name=pmg2.domain.com
  -o syslog_name=relay3
relay4     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=4.4.4.4
  -o smtp_helo_name=pmg2.domain.com
  -o syslog_name=relay4
 
[% ELSIF dns.hostname == 'pmg3.domain.com' %]
relay5     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=5.5.5.5
  -o smtp_helo_name=pmg3.domain.com
  -o syslog_name=relay5
relay6     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=6.6.6.6
  -o smtp_helo_name=pmg3.domain.com
  -o syslog_name=relay6

[% END%]
As said before - try it! - edit the template - run `pmgconfig sync` - check the result in '/etc/postfix/master.cf' (or main.cf respectively).
If it does not work - try changing the template until it fits

I hope this helps!
 
  • Like
Reactions: guletz

papak011

New Member
Feb 27, 2020
2
0
1
50
Hi Stoiko,

I did the same on master and run

Code:
pmgconfig sync --restart 1
but nothing adedd in main.cf and master.cf.

Is any typo in code?

master.cf.in:

Code:
[% IF dns.hostname == 'pmg1.domain.com' %]
smtp1     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=1.1.1.1
  -o smtp_helo_name=pmg1.domain.com
  -o syslog_name=smtp1
smtp2     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=2.2.2.2
  -o smtp_helo_name=relay2.pmg1.domain.com
  -o syslog_name=smtp2
[% ELSIF dns.hostname == 'pmg2.domain.com' %]
smtp3     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=3.3.3.3
  -o smtp_helo_name=pmg2.domain.com
  -o syslog_name=smtp3
smtp4     unix  -       -       n       -       -       smtp
  -o smtp_bind_address=4.4.4.4
  -o smtp_helo_name=relay4.pmg1.domain.com
  -o syslog_name=smtp4
[% END%]
main.cf.in:

Code:
[% IF dns.hostname == 'pmg1.domain.com' %]
sender_dependent_default_transport_maps = randmap:{smtp1,smtp2}
[% ELSIF dns.hostname == 'pmg2.domain.com' %]
sender_dependent_default_transport_maps = randmap:{smtp3,smtp4}
[% END%]
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE and Proxmox Mail Gateway. We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get your own in 60 seconds.

Buy now!