Skip to contentSkip to conversation

using NetFilter to share the SAME SINGLE IP between a Linux router AND a computer simultaneously

DISCUSSION John Wigley 3 participants 3 messages Jun 20, 2005

lore
Share & tools
lore
#0 lore raw

Hi,

I wonder if some experienced NetFilter users may be able to answer if the following is possible and if so how :-

What I am looking to do is to be able to configure a Linux based router to be able to share a single Public IP address between the linux router and a single computer on the lan acting as the DMZ host.

So basically you have a linux router with two network ports, WAN and LAN. The router takes the single ISP assigned public IP address for it's WAN interface and then uses a non routable subnet for the LAN port. There are a number of machines on the LAN segment and the linux router is performing NAT for them so that they have internet connectivity - so far this is a standard normal setup.

Now what I want to do is to simultaneously assign that SAME PUBLIC IP address onto one of the LAN computers so that it for all intents and purposes is a DMZ host.

Before anyone says that this is mad and that it can't be done, it can be done perfectly well and all WESTELL ADSL / Ethernet routers have this functionality along with some no name Far Eastern origin broadband routers based on a Conexant OEM reference design.

Having thought long and hard about how to do this but not knowing NetFilter at all, I realised that the way this must be done is for the router to perform a standard NAT function with the added functions of tracking all outgoing connections from the DMZ host and entering those into the NAT table as well, so that it doesn't try to do a Port Address Translation on top of an existing outgoing connection from the DMZ host. For incoming connections, if the incoming packet has a reference in the NAT table then it is directed to the originating LAN machine and if not is passed through unmodified to the DMZ host.

I have spent much time googling and reading list postings but cannot find any reference on how to do this under linux, my guess is that Proxy ARP needs to be enabled on the LAN interface and then a 1:1 POST NAT mapping set to remap all the packets for the DMZ host back to the original public IP address but after that I'm stuck.

This is an incredibly useful feature which I've used on the Westell routers for some time, but now want to move to a Linux based router to be able to do QOS, as it allows all the benefits of NAT for sharing a single IP address but also the benefits of a routed connection for NAT unaware applications like IPSEC AH, and some VOIP implementations.

Any advice on setting this up would be much appreciated,

Thanks,

John Wigley

#1 lore raw
Quoted 6 lines · John Wigley

Hi,

Before anyone says that this is mad and that it can't be done, it can be done perfectly well and all WESTELL ADSL / Ethernet routers have this functionality along with some no name Far Eastern origin broadband routers based on a Conexant OEM reference design.

I'd just like to add weight to this call - it's certainly been done in these cheapy routers, usually called 'PPP Half Bridge'. The router terminates the PPP session, and still launches a DHCP server for the LAN, which will only ever give out one lease, the public address allocated by the ISP, and it does some majik to translate between them.

However, there is another option...

This morning for the first time I used a Linksys ADSL2MUE device and was disappointed to find that it did not support port forwarding or DMZ host. Even in the UK with BT's PPP-over-ATM setup, what you can do is configure the modem in 'Bridge only' mode - you do not give the modem your ADSL username and password.

Then you run 'pppoeconf' in Linux (yes, PPPoE !) and give it your ADSL user+pass - it will give you a ppp0 device set with the public IP address so you can easily assign QoS and proper firewalling to it :))

Well worth a look!

Cheers,
Gavin.

#2 lore raw
In reply to John Wigley
Quoted 3 lines · John Wigley

What I am looking to do is to be able to configure a Linux based router to be able to share a single Public IP address between the linux router and a single computer on the lan acting as the DMZ host.

You cannot "share" the IP address. Any given packet can only go to a single destination (load balancing arrangements notwithstanding.) But what you're describing is probably very simple. For example, assuming shell variables properly set as should be self-evident:

iptables -vt nat -A PREROUTING -i $WAN_IF -d $WAN_IP -m state \
--state NEW -j DNAT --to $DMZ_IP

[NB: untested! I am at present not in a position to test this.]

Insofar as sharing, you would place any exception rules before this rule, to allow such packets to be received by the firewall machine itself:

iptables -vt nat -I PREROUTING -i $WAN_IF -d $WAN_IP \
[match extensions as needed] -j ACCEPT

For example to give 22/tcp to the firewall machine's sshd:

iptables -vt nat -I PREROUTING -i $WAN_IF -d $WAN_IP \
-p tcp --dport 22 -j ACCEPT

Similarly you could use preceding DNAT rules to route chosen traffic somewhere other than the DMZ host. Order of rules is important! An ACCEPT rule in nat/PREROUTING means that matching packets are not to be mangled by subsequent rules.

Remember, when these DNAT'ed DMZ packets hit the filter table they have the new destination IP, and they will hit the FORWARD chain, not INPUT.

Read the NAT HOWTO and Packet Filtering HOWTO to begin to understand this.

Signature · 2 lines
    mail to this address is discarded unless "/dev/rob0"
    or "not-spam" is in Subject: header