LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   How to do NAT in Iptables? ..(IP Public to Internal IP) (https://www.linuxquestions.org/questions/linux-networking-3/how-to-do-nat-in-iptables-ip-public-to-internal-ip-797155/)

nimnull22 03-23-2010 10:43 AM

A PREROUTING -d 202.a.b.c1/32 -i eth0 -p tcp -m tcp --dport 25 -j DNAT --to-destination 172.16.1.69:25

This is your first rule.
Answer please,
1. What is 202.a.b.c1?
2. What is 172.16.1.69?

Winanjaya 03-23-2010 10:48 AM

ok.. let me clarify:

-A PREROUTING -d 202.a.b.162/32 -i eth0 -p tcp -m tcp --dport 25 -j DNAT --to-destination 172.16.1.69:25
-A PREROUTING -d 202.a.b.162/32 -i eth0 -p tcp -m tcp --dport 110 -j DNAT --to-destination 172.16.1.69:110

172.16.1.69 is the mail server

nimnull22 03-23-2010 11:01 AM

Quote:

Originally Posted by Winanjaya (Post 3909109)
202.a.b.166/32 is this Linux firewall box?..
are you sure?

202.a.b.162/32 is mail server

This is your post, here you said that: 202.a.b.162/32 is mail server.

Can you please, be more definite.
If your mail server IP is 172.16.1.69, and you can ping 202.a.b.166 from internet, then next rule should do what you want:


A PREROUTING -d 202.a.b.166/32 -i eth0 -p tcp -m tcp --dport 25 -j DNAT --to-destination 172.16.1.69:25

Winanjaya 03-23-2010 11:08 AM

yes, I able to ping 202.a.b.166/32 from internet .. but that's the linux firewall (172.16.1.1)

but you suggest below:
A PREROUTING -d 202.a.b.166/32 -i eth0 -p tcp -m tcp --dport 25 -j DNAT --to-destination 172.16.1.69:25

could you please advise? why I should use 202.a.b.166/32 instead of 202.a.b.162/32

Winanjaya 03-23-2010 11:11 AM

because I have 16 IPs from my ISP:

202.a.b.162 is want to be used for mail
202.a.b.163 is for ... bla bla
202.a.b.166 is for linux firewall on eth0 and eth1 is 172.16.1.1

or do I need to create 16 virtual NICs on linux firewall?

any idea?

nimnull22 03-23-2010 11:13 AM

As I understood, 202.a.b.166 is linux firewall interface reachable from internet. And linux box has only two interfaces - eth0 and eth1.

What is 202.a.b.162?

Winanjaya 03-23-2010 11:18 AM

What is 202.a.b.162?
A: this IP 202.a.b.162 is want to be IP port-forwarding to 172.16.1.69 for SMTP and POP3 service.

or Do I need to create virtual IP of 202.a.b.162 in Linux-Firewall as Eth1:1

nimnull22 03-23-2010 11:27 AM

Linux box can do it.
Packets from internet will come to eth0=202.a.b.166, go through firewall, through router and go to second interface eth1=172.16.1.1, then to mail server=172.16.1.69

You do not need anything else

Winanjaya 03-23-2010 11:39 AM

yes, that also what I thought, Linux-firewall box on 202.a.b.166 receives package from internet, if incoming package destination is to IP 202.a.b.162 and destination port is 25 then it should be forwarded to 172.16.1.69:25 .. but it does not work ..this really make me confusing today :<(

Winanjaya 03-23-2010 11:41 AM

I am suspecting the routing..

Eth0 is on 202.a.b.166
Eth1 is on 172.16.1.1

and the Internet Router is on 202.a.b.161

Do you have suggestion about routing for the above conditions?

nimnull22 03-23-2010 12:02 PM

What makes you confusing is you do not understand that if packets from internet was addressed to 202.a.b.166, they will never go any farther because their destination address is 202.a.b.166. That is why you use iptables router - you manually resend them where you want.
That is happen because only 202.a.b.166 is reachable from internet and remote computer can address its packets only to 202.a.b.166, it does not know about anything else.

Winanjaya 03-23-2010 08:50 PM

Hi,
so the all packets will arrives on eth0 202.a.b.166 and go to eth2=172.16.1.1..
but how to make access-list for

202.a.b.162 should be forwarded to 172.16.1.169 for smtp and pop3?

I am asking you this.. because I put dns record for smtp & pop3 @202.a.b.162

please advise

thanks & regards

nimnull22 03-23-2010 09:36 PM

Quote:

Originally Posted by Winanjaya (Post 3909833)
Hi,
so the all packets will arrives on eth0 202.a.b.166 and go to eth2=172.16.1.1..
but how to make access-list for
202.a.b.162 should be forwarded to 172.16.1.169 for smtp and pop3?
I am asking you this.. because I put dns record for smtp & pop3 @202.a.b.162
please advise
thanks & regards

If you put DNS record to IP=202.a.b.162 for your mail server, it means that mail client will attempt to connect to IP=202.a.b.162 and 202.a.b.162 should be reachable from internet. Is it?
Can you ping 202.a.b.162 from internet?

Winanjaya 03-23-2010 10:08 PM

currently, I am using CISCO PIX, I am unable to ping 202.a.b.162 but I able to port-forwarding..
using Linux.. I am unable to ping 202.a.b.162 and I also unable to port-forwarding

nimnull22 03-23-2010 10:22 PM

DNS record gives an IP address, which is used for connection from internet. If 202.a.b.166 is reachable from internet, you should put it in DNS. And then with Linux you will forward this connection to any internal IP and ports.


All times are GMT -5. The time now is 03:33 AM.