2

I am trying to port forward from one server to another. I have tried numerous iptables commands but they don't work. Am I doing something wrong?

Here is my setup:

  • VPS1: 1.1.1.1
    • SMTP Port : 25
    • UFW: OFF
    • iptables policy: Accept All
    • Hostname: mailbox.xxxxxx.com
    • OS: Ubuntu 14.04
  • Mail Server: 2.2.2.2
    • SMTP NAT Port: 15324

I have tried these commands:

iptables -t nat -A PREROUTING -p tcp --dport 25 -j DNAT --to-destination 2.2.2.2:15324
iptables -A FORWARD -d 2.2.2.2 -p tcp --dport 15324 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

iptables -t nat -nvL

Chain PREROUTING (policy ACCEPT 459 packets, 17802 bytes) pkts bytes target prot opt in out source destination 19 1088 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:25 to:2.2.2.2:15324

Chain POSTROUTING (policy ACCEPT 2 packets, 120 bytes) pkts bytes target prot opt in out source destination 39 2603 MASQUERADE all -- * eth0 0.0.0.0/0 0.0.0.0/0

After running a telnet to port 25 on the external IP I get this. The packet count changes so it is getting something, but I don't know why it isn't going through PREROUTING

Chain PREROUTING (policy ACCEPT 469 packets, 18178 bytes) pkts bytes target prot opt in out source destination 19 1088 DNAT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:25 to:2.2.2.2:15324

Chain POSTROUTING (policy ACCEPT 3 packets, 180 bytes) pkts bytes target prot opt in out source destination 42 2812 MASQUERADE all -- * eth0 0.0.0.0/0 0.0.0.0/0


Trying to telnet shows me this.

telnet 2.2.2.2 15324 Trying 2.2.2.2... Connected to 2.2.2.2. Escape character is '^]'. 220 mailbox.xxxxxx.com ESMTP Hi, I'm a Mail-in-a-Box (Ubuntu/Postfix; see https://mailinabox.email/)

telnet mailbox.xxxxxx.com 25 Trying 1.1.1.1... telnet: Unable to connect to remote host: Connection refused

  • Bad downvote IMO. This is a good post. – Citizen Jun 10 '16 at 20:36
  • It's one of those unfortunate cases where the asker tried to post what they thought was relavent information but the actual problem had absolutely nothing to do with the information the asker thought was relevant, so the question is of limited utility for future visistors :/ – Peter Green May 10 '18 at 21:01
7

Damn it. I fixed it like a min after posting this. Solution:

echo 1 > /proc/sys/net/ipv4/ip_forward

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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