Here's how to assign multiple IP addresses to the same NIC:
(assuming your eth1 is x.x.x.2, a public IP address)
ifconfig eth1:0 x.x.x.3 netmask 255.255.255.248
ifconfig eth1:1 x.x.x.4 netmask 255.255.255.248
ifconfig eth1:2 x.x.x.5 netmask 255.255.255.248
ifconfig eth1:3 x.x.x.6 netmask 255.255.255.248
I run these commands (and shaping rule commands) in a script in
rc.local. Now your device eth1 will answer for all IP addresses
between x.x.x.2 and x.x.x.6. (Your router is probably on x.x.x.1.)
As for your port forwarding rules, they would look something like this
(/etc/sysconfig/iptables) below. I added some comments, to clarify
what each of these rules do.
Also, the following is assumed:
eth0 is the private side of the firewall
eth1 is the public side of the firewall
x.x.x.2 is the public IP answering for the firewall and used for
general Internet traffic
x.x.x.3 is the public IP answering for the mail server
x.x.x.4 is the public IP answering for the 1st web server
x.x.x.5 is the public IP answering for the 2nd web server
x.x.x.6 is not used
y.y.y.2 is the private IP of the firewall box
y.y.y.3 is the private IP of the mail server
y.y.y.4 is the private IP of the 1st web server
y.y.y.5 is the private IP of the 2nd web server
(/etc/sysconfig/iptables listing)
# Generated by iptables-save v1.3.5 on ...
*filter
:INPUT DROP
:FORWARD ACCEPT
:OUTPUT ACCEPT
# allows related and established traffic from all interfaces
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# blocks connection requests from eth1 only
-A INPUT -i ! eth1 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j
ACCEPT
# allows SSH into the server from the Internet
-A INPUT -d x.x.x.2 -p tcp -m tcp --dport 22 -j ACCEPT
COMMIT
# Completed on ...
# Generated by iptables-save v1.3.5 on ...
*nat
:PREROUTING ACCEPT
:POSTROUTING ACCEPT
:OUTPUT ACCEPT
# Mail server NAT rule
# SMTP, HTTPS (for webmail), and RDP from the public IP x.x.x.3 to
private IP y.y.y.3
-A PREROUTING -d x.x.x.3 -i eth1 -p tcp -m multiport --dports
25,443,3389 -j DNAT --to-destination y.y.y.3
# 1st Web Server NAT rule
# NATs HTTP, HTTPS, and RDP from the public IP x.x.x.4 to private IP
y.y.y.4
-A PREROUTING -d x.x.x.4 -i eth1 -p tcp -m multiport --dports
80,443,3389 -j DNAT --to-destination y.y.y.4
# 2nd Web Server NAT rule
# NATs HTTP, HTTPS, and RDP from the public IP x.x.x.5 to private IP
y.y.y.5
-A PREROUTING -d x.x.x.5 -i eth1 -p tcp -m multiport --dports
80,443,3389 -j DNAT --to-destination y.y.y.5
# Return Traffic rule for the mail server
-A POSTROUTING -s y.y.y.3 -o eth1 -p tcp -m multiport --sports
25,443,3389 -j SNAT --to-source x.x.x.3
# Return Traffic rule for 1st web server
-A POSTROUTING -s y.y.y.4 -o eth1 -p tcp -m multiport --sports
80,443,3389 -j SNAT --to-source x.x.x.4
# Return Traffic rule for 2nd web server
-A POSTROUTING -s y.y.y.5 -o eth1 -p tcp -m multiport --sports
80,443,3389 -j SNAT --to-source x.x.x.5
# Make sure the two rules below are listed last !!!
# Outgoing traffic NAT rule for general Internet users
-A POSTROUTING -o eth1 -j SNAT --to-source x.x.x.2
# Incoming traffic NAT rule for general Internet users
-A POSTROUTING -o eth0 -j SNAT --to-source y.y.y.2
COMMIT
# Completed on ...
Originally, I did all the port accept rules for the servers on the
INPUT chain and then had some simple PREROUTING and POSTROUTING rules
(that didn't include port numbers), but then I rediscovered that the
PREROUTING chain is checked before the INPUT chain, and so all traffic
to the public IP addresses were getting NAT'd straight to the
corresponding servers (not just specific ports), so it was like they
were directly on the Internet. That's when I figured out that I needed
to specify the ports in the PREROUTING chain and then also in the
POSTROUTING chains for consistency. I also could have used the FORWARD
chain instead, but I decided the PREROUTING and POSTROUTING rules would
take less rules to accomplish the same result, so that's how I got this
configuration.
One other interesting tidbit about this setup, is that any traffic from
the servers' public ports (e.g. mail server's ports: 25, 443, 3389)
gets returned using their own IP address (e.g. mail server's: x.x.x.3),
but if someone logs into that server to surf the web or do FTP, that
traffic (from the Internet) looks like it comes from firewall's public
IP of x.x.x.2. Modern Frame Relay routers that I have used work this
way also.
X
|