I have a SMTP server in Hetzner Cloud. Have added floating IPv4 and IPv6 (in case I switch server and the IP's can follow to the new server)

How to set the floating IP's as primary?

When a client sends a mail it is sent to the floating IP (smtp.server.com), but when the SMTP forwards the mail to recipient server the primary IP is used and SPF fails

How to set the floating IP's as the primary IP addresses?

I want to set eth0:1 as the primary outbound IP address for both the IPv4 and IPv6


auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
    dns-nameservers xx.xx.xx.xx xx.xx.xx.xx xx.xx.xx.xx

iface eth0 inet6 static
    address [primary IPv6]
    gateway fe80::1

# Additional IPv4 (floating IP)
auto eth0:1
iface eth0:1 inet static
    address [additional IPv4]
    netmask 32

# Additional IPv6 (floating IP)
auto eth0:1
iface eth0:1 inet6 static
    address [additional IPv6]
    netmask 64
  • 1
    The easier and saner way would be to change the SMP server settings and not try to tweak routing. Even if you insist on tweaking routing, there's not enough information, and using only xx.xx.xx.xx as address won't help. So you must provide more configuration for the smtp server part or the routing part – A.B Nov 22 '20 at 10:57
  • I would prefer setting the interface so all outbound traffic comes from my preferred IP – clarkk Nov 22 '20 at 16:38
  • Have added some more information – clarkk Nov 22 '20 at 16:55
  • 1
    It is very difficult to try to decipher your addressing when it is completely blocked. IANA has set aside three IPv4 ranges (,, and and one IPv6 range (2001:db8::/32) for example addresses. If you use those, it will make more sense. You can subnet them properly to match your various addresses so that we can see what you actually mean. – Ron Maupin Nov 22 '20 at 18:08
  • And also add routing informations. You didn't. Just run for example ip route + ip -6 route. – A.B Nov 22 '20 at 18:15

I found a solution

# ip route replace default via dev eth0 src [additional IPv4]
# ip -6 route replace default via fe80::1 dev eth0 src [additional IPv6]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.