Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have this setup to secure my Email server.
However, the incoming IP displayed was not originated from 182.168.0.4. How can I make it to display the original internet incoming address?
Appreciate any suggestions.
My Setup
internet router <--> FW <---> Email Server
Router 2x.x.x.129
FW WAN - 2x.x.x.130
FW LAN- 192.168.0.4
Email Server - 192.168.0.5
At FW I have ip forwading to Email server
iptables -t nat -A PREROUTING -j DNAT -p tcp -d 2x.x.x.141 --dport 25 --to 192.168.0.5:25
iptables -t nat -A PREROUTING -j DNAT -p tcp -d 2x.x.x.141 --dport 110 --to 192.168.0.5:110
My NAT (for the rest of the local LAN PC)
iptables -t nat -P POSTROUTING DROP
iptables -t nat -A POSTROUTING -j MASQUERADE
not clear for me: what is 2x.x.x.141 address? if you want redirection you should use 2x.x.x.130
are the rules you are using legal (accepted)?
in my opinion it should be:
iptables -t nat -A PREROUTING -d 2x.x.x.130 -p tcp --dport 110 -j DNAT --to-destination=192.168.0.5
iptables -t nat -A PREROUTING -d 2x.x.x.130 -p tcp --dport 25 -j DNAT --to-destination=192.168.0.5
and what abou forwarding?
you should have (for instance) also:
iptables -A FORWARD -m state --state NEW -p tcp --dport 110 -j ACCEPT
iptables -A FORWARD -m state --state NEW -p tcp --dport 25 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
Comments: This is my other IP address in the same IP block. (/28 - 16 IPs)
The bottom line.
It doesn't make any differences to have .141 or .130 as the forwarding address. The result is still the same. The packet going thru have the address of the internal IP 192.168.0.4
The three forwarding rules are not needed, without it, it's still working fine. Again the only problem is internal IPs.
I am not sure anyone understand me. I need to capture the actual internet IPs and not my internal IPs (masq). It's for both security and statistics purpose.
"The packet going thru have the address of the internal IP 192.168.0.4" - which packets ? I assume the packets received by email server. It is obvious. You are doing masquerade on both "firewall ends" (i.e. eth cards).
But in fact you need only one-end masquerade:
iptables -t nat -A POSTROUTING -o ethN -j MASQUERADE
where ethN is the eth connected to the router.
BTW: if you have got the static IPs you should use
iptables -t nat -A POSTROUTING -o ethN -j SNAT --to-source=2x.x.x.130
rather than 'MASQUERADE' construction.
Besides, yeah, you're right. I do not understand you. For instance:
"This is my other IP address in the same IP block. (/28 - 16 IPs)" - but is it firewall external eth address? I can only assume that it is. You have nowhere mentioned it.
"It doesn't make any differences to have .141 or .130 as the forwarding address" - ???? If your firewall eth has .130 IP address there is no way (except case of promiscuous mode or multi-IP mode) to see packet send to .141
Regarding "the three forwarding rules". If you really do not need add any forwarding lines it means that the policy for FORWARD chain is ACCEPT.
I think I finally get it. Sorry for the explanation, my first language is not English.
I will try your method and revert it it works.
It may be because of my two ends MASQ, never know this will caused problem.
As for forwarding, yes you are right, I have the default policy as ACCEPT. Will try to get it work and then will work on the block all and accept selected rules.
Nice to hear that it works, although I still don't understand why you use .141 IP address...
Regarding the ACCEPT policy: usually in firewall's setting the policies at least for INPUT and FORWARD chains are set to DROP. And I don't know the situation it could not to be that.
130 is my firewall, do not want to use that.
Since I have other IP, I choose to use 141, anyway I have 14 usable
My INPUT policy is defaulted to DROP, however, not sure why my POSTROUTING cannot be defaulted to DROP. FORWARD is default to ACCEPT.
My reasoning to use forwarding is to maintain one firewall and harden one machine instead of so many other machines. I only want to open ports 22,25,80,110. The rest if I have forgotten to turn it off, I am still safe. My default firewall rules will block all of them. Otherwise, I will have to maintain and harden 14 machines.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.