Linux Demilitarized Zone (DMZ) Ethernet Interface Requirements and Configuration

Q. Can you tell me more about Linux Demilitarized Zone and Ethernet Interface Card Requirements for typical DMZ implementation? How can a rule be set to route traffic to certain machines on a DMZ for HTTP or SMTP?

A. Demilitarized zone, used to secure an internal network from external access. You can use Linux firewall to create DMZ easily. There are many different ways to design a network with a DMZ. The basic method is to use a single Linux firewall with 3 Ethernet cards. The following simple example discusses DMZ setup and forwarding public traffic to internal servers.

Sample Example DMZ Setup

Consider the following DMZ host with 3 NIC:
[a] eth0 with 192.168.1.1 private IP address - Internal LAN ~ Desktop system
[b] eth1 with 202.54.1.1 public IP address - WAN connected to ISP router
[c] eth2 with 192.168.2.1 private IP address - DMZ connected to Mail / Web / DNS and other private servers

Linux Demilitarized Zone (DMZ) Ethernet Single Firewall Design
(Fig 01: A typical Linux based DMZ setup [ Image modified from Wikipedia article] )

Routing traffic between public and DMZ server

To set a rule for routing all incoming SMTP requests to a dedicated Mail server at IP address 192.168.2.2 and port 25, network address translation (NAT) calls a PREROUTING table to forward the packets to the proper destination.

This can be done with appropriate IPTABLES firewall rule to route traffic between LAN to DMZ and public interface to DMZ. For example, all incoming mail traffic from internet (202.54.1.1) can be send to DMZ mail server (192.168.2.2) with the following iptables prerouting rule (assuming default DROP all firewall policy):

### end init firewall .. Start DMZ stuff ####
# forward traffic between DMZ and LAN
iptables -A FORWARD -i eth0 -o eth2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth2 -o eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

# forward traffic between DMZ and WAN servers SMTP, Mail etc
iptables -A FORWARD -i eth2 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i eth1 -o eth2 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

# Route incoming SMTP (port 25 ) traffic to DMZ server 192.168.2.2
iptables -t nat -A PREROUTING -p tcp -i eth1 -d 202.54.1.1 --dport 25 -j DNAT --to-destination 192.168.2.2

# Route incoming HTTP (port 80 ) traffic to DMZ server load balancer IP 192.168.2.3
iptables -t nat -A PREROUTING -p tcp -i eth1 -d 202.54.1.1 --dport 80 -j DNAT --to-destination 192.168.2.3

# Route incoming HTTPS (port 443 ) traffic to DMZ server reverse load balancer IP 192.168.2.4
iptables -t nat -A PREROUTING -p tcp -i eth1 -d 202.54.1.1 --dport 443 -j DNAT --to-destination 192.168.2.4
### End DMZ .. Add other rules ###

Where,

  • -i eth1 : Wan network interface
  • -d 202.54.1.1 : Wan public IP address
  • --dport 25 : SMTP Traffic
  • -j DNAT : DNAT target used set the destination address of the packet with --to-destination
  • --to-destination 192.168.2.2: Mail server ip address (private IP)

Multi port redirection

You can also use multiport iptables module to matches a set of source or destination ports. Up to 15 ports can be specified. For example, route incoming HTTP (port 80 ) and HTTPS ( port 443) traffic to WAN server load balancer IP 192.168.2.3:

iptables -t nat -A PREROUTING -p tcp -i eth1 -d 202.54.1.1 -m multiport --dport 80,443 -j DNAT --to-destination 192.168.2.3

Pitfalls

Above design has few pitfalls:

  1. Single point of failure - The firewall becomes a single point of failure for the network.
  2. Hardware - The firewall Host must be able to handle all of the traffic going to the DMZ as well as the internal network.

Linux / BSD Firewall Distros

If you find above discussion little hard to digest, I suggest getting a Linux / BSD distribution which aims to provide a simple-to-manage firewall appliance based on PC hardware to setup DMZ and gateways:

Further readings:

Updated for accuracy.

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 18 comments… read them below or add one }

1 George 01.02.08 at 4:09 pm

I want to add that there’s a mistake in the iptables rules: iptables -t nat -A PREROUTING -p tcp -i eth2 -d 202.54.1.1 –dport 25 -j DNAT –to-destination 192.168.2.2. The problem is coming from -i eth2, the correct way is -i eth1 because we want packets coming from internet to be redirect to the DMZ.

2 vivek 01.02.08 at 4:21 pm

George,

Thanks for the heads up.

3 Sathish 08.01.08 at 8:35 am

Hi,

I have configured the DMZ mentioned in the above article. Routing concept is working fine, where as if I click on my LAN/Other networks by accessing the web-page [ex :www.xyz.com or http://xyz.com, it showing Apache test page, where as domain related page not working, what may be the problem.

Please help me out.

Thanks,
Sathish

4 vivek 08.01.08 at 9:09 am

You need to configure Apache properly.

5 mirza 08.05.08 at 2:38 am

after George’s correction….
is the script already updated ?

6 vivek 08.05.08 at 5:41 am

mirza,

Yes, it was updated after George’s correction..

7 umesh 10.07.08 at 6:09 pm

Hi,
I have 8 public Ips and want to configure FreeBSD as router and firewall and also want to use all 8 public IPs for my servers so pls can you suggest me how to do this. I am very confused….

Pls help….

8 Gerald Sagoonick 01.19.09 at 8:54 pm

Nice one

9 satya 02.27.09 at 7:32 am

I tried with 2 network card to set as gateway server on Ubuntu 8.10 lts, its not working. Is thr any tips to troubleshoot

10 Vivek Gite 02.27.09 at 7:51 am

DMZ needs 3 network card.

11 Nepguy 02.27.09 at 9:00 am

Hey,
Great Stuff !

But i have a little different case with me and wondering if you could help me.
I want to put a server ( Mail and proxy) in same machine and instead of assigning Private IP in the server in DMZ, I want to assign a public Ip.

So can you please help me out with the iptables and routing in the linux server having 3 Nics.

Thanks in advance.

12 Vivek Gite 02.27.09 at 11:09 am

Rules remains same and replace private IP with public one.

13 Nepguy 03.02.09 at 9:48 am

Doesn’t any NATing thing required here?

14 satya 03.19.09 at 6:32 am

I am having 3 network card with
1..public Ip
2. 192.168.0.0—-servers
3. 192.168.1.0—-Lan
I tried setting as router to allow internet access on lan , it din’t work, can u help me out

15 V.Balaviswanathan 04.29.09 at 2:32 pm

How to use iptables on a Debian or Ubuntu systems? You the ufw utility as a firewall and so how can one use that to forward or deny the ip packets?

Please help me

16 yshri 06.04.09 at 8:34 am

hey, great article. Very informative and helped me a lot. But in my case, i found it risky and don’t want to use 3 interfaces on the same machine. Instead, I want to configure two firewall machines — one sits in front of DMZ and other sits in front of Local LAN. Could you please explore in little in depth the configuration and setup required in this ? If you could give a diagram of it would be of great help to me. Thanks a lot.

17 PG 06.16.09 at 10:32 am

Does this iptables rules share internet to the local LAN users?

I want to implement like this:

INTERNET—————–(pub ip)LINUX ROUTER(pvt ip) ————PROXY/MAIL SVR
|
LAN
how will be the iptable rules change if i want to direct the LAN internet access through the proxy server?

Thanks in advance.

Prakash

What will be the rules if i need to direct

18 PG 06.16.09 at 10:41 am

hey,

in the earlier post, the LAN actually connects to one other NIC of LINUX Router.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , , , , , , , , , , , , , , ,

Previous post: Explain Linux / UNIX dot-files

Next post: Ubuntu Linux NFS Server installation and Configuration