I have the following problem. I need to send report emails for one of our customers to his customers. Our customer provided an SMTP endpoint for that and added the IPv4 Address of our server to his whitelist.
However when I started testing the SMTP settings, I got this error: 4.7.26 Service does not accept messages sent over IPv6.
So I tried the following:
ssh -4 127.0.0.1 -N -L1025:smtp.mycustomer.com:25- Ony my test script I changed the host to
127.0.0.1and port to1025
When I executed the test script, I got once again the same error. So clearly
-4 means only use IPv4 to connect to the SSH server, but internally the SSH
server is resolving smtp.mycustomer.com to the IPv6.
I also tried ssh with -o "AddressFamily inet" but that didn't work. The man
page says Specifies which address family to use when connecting, so I presume
that the command line option -4 is shorthand for -o "AddressFamily inet".
When I do the tunnel with IPv4 address instead:
ssh -4 127.0.0.1 -N -L1025:<ipv4 addr>:25
then the script is able to send the email.
I know that by enabling the line
precedence ::ffff:0:0/96 100
in /etc/gai.conf I can force getaddrinfo(3) to resolve to IPv4, but this
would resolve all DNS queries to IPv4. I don't want to do that. Looking at
glibc source code, /etc/gai.conf is hardcoded, I don't see an environment
variable I could use to specify a custom gai.conf file.
How can I tell ssh to resolve the domains with IPv4 when specifying a
LocalForward? Is this even possible? Or is there a way (without having to configure your own DNS server) to force IPv4 for certain domains only?
/etc/hostsxxx.xxx.xxx.xxx smtp.mycustomer.com/etc/hostsunless strictly necessary.host = socket.getaddrinfo(host, port, family=socket.AF_INET)[0][4][0]and passingssl._create_unverified_context()toaiosmtplib. I know, not pretty, but I need to send today the reports, I have time fix connection issues with the customer later.