Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I try to telnet from PC 3 To PC 1 and it's redirect to PC 2

PC 1 : 192.168.0.1

PC 2 : 192.168.0.2

PC 3 : 192.168.0.3

i have command like this in PC 1:

  1. iptables -t nat -A PREROUTING -p tcp -d 192.168.0.1 --dport 23 -j DNAT --to-destination 192.168.0.2:23

  2. iptables -t nat -A POSTROUTING -j MASQUARADE

If I just do command number 1, In PC 2 shows(log file) that the telnet is a PC 3(is success) but it's can not telnet(can't telnet) just only send the connection. But when i combined with command number 2, telnet can be done(telnet success) but in file log(in PC 2) shows that ip who telnet is PC 1, but actually that does telnet is PC 3.

How i resolve that?

share|improve this question
add comment

1 Answer

In case when you have first command configured, the connection that comes to PC1 will be redirected to PC2 and PC2 sees the connection as originating from PC3 (since PC1 has only changed destination and not source). Now PC2 responds to connection (SYN) and sends back a SYN,ACK to PC3. but PC3 will drop it (Reason PC3 opened a telnet connection to 192.168.0.1 therefore its expecting response from that IP, but since the connection was redirected source IP would be that of PC2)

In second case since you have Masqueraded the source IP to that of PC1 , PC2 will see PC1 as source of all the connections.

What you need to do is change the source IP address of outgoing packets on PC2 to 192.168.0.1 on PC2.

(Note:Do not use the second command i.e. MASQUERADE on PC1)

Configure this on PC2

iptables -A POSTROUTING -t nat -p tcp --sport 23 -d 192.168.0.3 -j SNAT --to-source 192.168.0.1
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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