I am trying to step up port forwarding from port 25 to port 2025 on the same AWS EC2 Ubuntu 14.04 instance using iptables. I am using port 2025 to receive income emails using Alfresco.
The first step I took was to open port 25 for INBOUND traffic in the Security Group using the AWS Console. Next I followed the following steps using a new EC2 Ubuntu instance. My understanding is that the first command allows inbound traffic to port 25. The second command then forwards the traffic from port 25 to port 2025 and then the last step saves (but does not persist the settings).
sudo iptables -A INPUT -p tcp --dport 25 -j ACCEPT
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 25 -j REDIRECT --to-port 2025
sudo iptables-save
I've confirmed that Alfresco is listening on port 2025 and the iptable settings using the following commands:
bitnami@ip-172-30-0-000:~$ netstat -an | grep 25
tcp6 0 0 :::2025 :::* LISTEN
bitnami@ip-172-30-0-000:~$ sudo iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 REDIRECT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:25 redir ports 2025
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 5 packets, 431 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 5 packets, 431 bytes)
pkts bytes target prot opt in out source destination
When testing the connection with telnet I would expect something like the following however now the connection simply times out.
Expecting:
Trying 54.85.10.9...
Connected to 54.163.62.000.
Escape character is '^]'.
220 simplycubedholdings.com ESMTP SubEthaSMTP 3.1.6
421 Timeout waiting for data from client.
Actual:
telnet 54.163.62.000 25
Trying 54.163.62.000...
telnet: connect to address 54.163.62.000: Operation timed out
telnet: Unable to connect to remote host
Any help or direction would be greatly appreciated.
Many thanks,
Charles