Author Topic: NAT reflection  (Read 3868 times)

Cele

  • Zen Apprentice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
NAT reflection
« on: November 10, 2009, 09:15:51 am »
Hi!

Does the e-box firewall has a NAT reflection feature? And if it does how can I enable it?

sixstone

  • Zentyal Staff
  • Zen Hero
  • *****
  • Posts: 1417
  • Karma: +26/-0
    • View Profile
    • Sixstone's blog
Re: NAT reflection
« Reply #1 on: November 17, 2009, 12:49:27 pm »
Hi Cele,

We don't have such a feature in our current ebox-firewall. Could you explain us a little about this feature?

Cheers,
My secret is my silence...

hordur

  • Zen Apprentice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: NAT reflection
« Reply #2 on: November 25, 2009, 01:02:55 am »
I've also been wanting to do this using ebox.
I believe this is sometimes called NAT loopback. It enables you to access port-forwarded services in your local network from within the network itself using the routers public IP address. Fx. if you're forwarding port 80 to 192.168.0.1 and your router had the public ip 123.123.123.123, you could access the webserver through http://123.123.123.123 both from outside and inside your lan instead of having to use http://192.168.0.1 on the inside.

sixstone

  • Zentyal Staff
  • Zen Hero
  • *****
  • Posts: 1417
  • Karma: +26/-0
    • View Profile
    • Sixstone's blog
Re: NAT reflection
« Reply #3 on: December 01, 2009, 01:18:01 pm »
Thanks for the explanation and I have added it up to our wishlist [1]

Cheers,

[1] http://trac.ebox-platform.com/wiki/Document/Development/Wishlist/Module/Firewall
My secret is my silence...

hordur

  • Zen Apprentice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: NAT reflection
« Reply #4 on: December 03, 2009, 05:14:38 am »
I've managed to do this on my ebox by editing /usr/share/perl5/EBox/Firewall/IptablesRedirectRule.pm

Below is my modified version of the sub. I wasn't sure where I could get the public IP from, so I hardcoded it in. Basically, I added the POSTROUTING rule and I also removed the interface flag from the other lines as that was limiting everything to the external interface. Hopefully this can be useful for someone that can implement this properly.

sub strings
{
    my ($self) = @_;

    my @rules;
    my $state = $self->state();
    my $modulesConf = $self->modulesConf();
    my $iface = $self->interface();
    # Iptables needs to use the real interface
    $iface =~ s/:.*$//;

    foreach my $src (@{$self->{'source'}}) {
        foreach my $origDst (@{$self->{'destination'}}) {
        my ($dst, $toDst, $addr) = @{$self->{'destinationNAT'}};
        foreach my $service (@{$self->{'service'}}) {
            my ($natSvc, $filterSvc) = @{$service};

            my $natRule = "-t nat -A PREROUTING $modulesConf " .
                " $src $natSvc $origDst -j DNAT $toDst";

            my $filterRule = "-A fredirects $state $modulesConf " .
                " $src $filterSvc $dst -j ACCEPT";

            my $postRule = "-t nat -A POSTROUTING " .
                " -s 192.168.0.0/16 $filterSvc $dst -j MASQUERADE";

            push (@rules, $natRule, $filterRule, $postRule);
        }
        }
    }

    return \@rules;
}

mattd

  • Zen Apprentice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: NAT reflection
« Reply #5 on: August 06, 2010, 09:15:21 pm »
Thanks for this hordur.  I've used your solution on my 1.4 install for the last 6 months, but it doesn't seem to be working for me on 1.5.  Any suggestions?  Will we see this feature in 2.0?