Skip to content

Instantly share code, notes, and snippets.

@lemonlatte
Last active May 20, 2019 09:03
Show Gist options
  • Save lemonlatte/dd84396050e62d4b129bc9ac8e239531 to your computer and use it in GitHub Desktop.
Save lemonlatte/dd84396050e62d4b129bc9ac8e239531 to your computer and use it in GitHub Desktop.
Use iptables to relay a mail server
#!/bin/sh
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -R PREROUTING 1 -p tcp --dport 2587 -j DNAT --to-destination $(host my.mail.server | cut -f4 -d' '):25
if [ $? -ne 0 ]; then
iptables -t nat -A PREROUTING -p tcp --dport 2587 -j DNAT --to-destination $(host my.mail.server | cut -f4 -d' '):25
iptables -t nat -A POSTROUTING -j MASQUERADE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment