1

I was forward my port 25 to 53525 in my server using ufw and iptable configuration.

It is testable port by telnet command, so I did try test it.

Connection is well to my 25 port in localhost, but I can not connect from external computers.

I did check netstat -ntlp result, my 25 port not listed. but port 53525 is listed.

Attach my ufw / iptables configuration. Please help.

File: /etc/ufw/before.rules

*nat
:PREROUTING ACCEPT [0:0]
-A OUTPUT -p tcp --dport 25 -j REDIRECT --to-port 53525
-A OUTPUT -p tcp --dport 143 -j REDIRECT --to-port 54143
-A OUTPUT -p tcp --dport 445 -j REDIRECT --to-port 54445
-A OUTPUT -p tcp --dport 139 -j REDIRECT --to-port 54139
-A OUTPUT -p tcp --dport 173 -j REDIRECT --to-port 54173
-A OUTPUT -p tcp --dport 138 -j REDIRECT --to-port 54138
-A OUTPUT -p tcp --dport 1025 -j REDIRECT --to-port 53525
COMMIT

Command: iptables -t nat -L

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-dgm redir ports 54138
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:173 redir ports 54173
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-ssn redir ports 54139
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:microsoft-ds redir ports 54445
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:imap2 redir ports 54143
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:smtp redir ports 53525
DOCKER     all  --  anywhere             anywhere             ADDRTYPE match dst-type LOCAL
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:imap2 redir ports 54143
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:smtp redir ports 53525
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:microsoft-ds redir ports 54445
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-ssn redir ports 54139
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:173 redir ports 54173
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-dgm redir ports 54138

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-dgm redir ports 54138
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:173 redir ports 54173
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-ssn redir ports 54139
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:microsoft-ds redir ports 54445
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:imap2 redir ports 54143
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:smtp redir ports 53525
DOCKER     all  --  anywhere            !loopback/8           ADDRTYPE match dst-type LOCAL
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:smtp redir ports 53525
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:smtp redir ports 53525
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:imap2 redir ports 54143
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:microsoft-ds redir ports 54445
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-ssn redir ports 54139
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:173 redir ports 54173
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-dgm redir ports 54138
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:smtp redir ports 53525
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:imap2 redir ports 54143
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:microsoft-ds redir ports 54445
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-ssn redir ports 54139
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:173 redir ports 54173
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-dgm redir ports 54138
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:smtp redir ports 53525
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:imap2 redir ports 54143
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:microsoft-ds redir ports 54445
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-ssn redir ports 54139
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:173 redir ports 54173
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-dgm redir ports 54138
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:1025 redir ports 53525
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:smtp redir ports 53525
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:imap2 redir ports 54143
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:microsoft-ds redir ports 54445
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-ssn redir ports 54139
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:173 redir ports 54173
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:netbios-dgm redir ports 54138
REDIRECT   tcp  --  anywhere             anywhere             tcp dpt:1025 redir ports 53525

Command: ufw status

22                         ALLOW       Anywhere
80                         ALLOW       Anywhere
25                         ALLOW       Anywhere
110                        ALLOW       Anywhere
143                        ALLOW       Anywhere
443                        ALLOW       Anywhere
465                        ALLOW       Anywhere
587                        ALLOW       Anywhere
993                        ALLOW       Anywhere
995                        ALLOW       Anywhere
4190                       ALLOW       Anywhere
3389                       ALLOW       Anywhere
8083                       ALLOW       Anywhere
22 (v6)                    ALLOW       Anywhere (v6)
80 (v6)                    ALLOW       Anywhere (v6)
25 (v6)                    ALLOW       Anywhere (v6)
110 (v6)                   ALLOW       Anywhere (v6)
143 (v6)                   ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)
465 (v6)                   ALLOW       Anywhere (v6)
587 (v6)                   ALLOW       Anywhere (v6)
993 (v6)                   ALLOW       Anywhere (v6)
995 (v6)                   ALLOW       Anywhere (v6)
4190 (v6)                  ALLOW       Anywhere (v6)
3389 (v6)                  ALLOW       Anywhere (v6)
8083 (v6)                  ALLOW       Anywhere (v6)

1 Answer 1

0

I found solution.

When prerouting ports in UFW, You have to add destination port to allow rule.

For Example, If you want forward source port 22 to destination port 1922,

you have to run command both 'ufw allow 22' and 'ufw allow port 1922'.

If wasn't open source port or destnation port, prerouting is not working.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .