Shorewall is a very nice tool for configuring iptables, and you can do many things easily such as port knocking, load balancing for your traffic among two ISP’s, fort forwarding, transparent proxy etc, for more information http://shorewall.net/shorewall_features.htm. There is no documentation yet for VMWare+shorewall, you may want to try the setup below.
Usually big organizations have hardware firewall and other measures, admin’s skip configuring firewall on servers, however we can follow individual firewall/device – a better practice.
Shorewall is available in binary packages (*.rpm, *.deb etc) as well as you can follow installation using source. To use installation using source you just have to run ./install.sh script from the extracted source tarball.
Here I am not going to run into all the setup’s, e.g. sharing traffic between two ISP’s, it would be just re-inventing the wheel, however the information here can give you enough fuel to have your own setup running, some port forwarding and masquerading of traffic as well.
So, what are the minimum files you need to have configured on the server? Files are /etc/shorewall/shorewall.conf (to start the shorewalll automatically at the boot time), and some files under /etc/shorewall directory (interfaces, zones, policy, rules and in case you want to masquerade traffic then masq).
In my setup, I want to forward traffic coming on network interfaces to different virtual machines(can be physical machines as well). I have one ethernet card eth0 (you should have two in case if you want to configure a gateway server), virtual network interface vmnet8 (should be replaced by eth1 in case of using physical server), and one more ISP (sometimes i use mobile phone to use internet).
Entries in configuration files:
/etc/shorewall/interfaces (Define your interfaces)
###############################################################################
#ZONE INTERFACE BROADCAST OPTIONS
net eth0 detect
nokia ppp0
loc vmnet8 172.16.249.255
##############################################################################
File /etc/shorewall/zones
###############################################################################
#ZONE TYPE OPTIONS IN OUT
# OPTIONS OPTIONS
fw firewall
loc ipv4
nokia ipv4
net ipv4
##############################################################################
File /etc/shorewall/policy
###############################################################################
#SOURCE DEST POLICY LOG LIMIT: CONNLIMIT:
# LEVEL BURST MASK
fw all ACCEPT
loc nokia ACCEPT
loc net ACCEPT
loc fw REJECT
net all REJECT
all all REJECT info
###############################################################################
File /etc/shorewall/masq
#############################################################################################
#INTERFACE:DEST SOURCE ADDRESS PROTO PORT(S) IPSEC MARK USER/
# GROUP
eth0 172.16.217.1/24
ppp0 172.16.217.1/24
#############################################################################################
And finally /etc/shorewall/rules file
######################################################################################################################################################################################
#ACTION SOURCE DEST PROTO DEST SOURCE ORIGINAL RATE USER/ MARK CONNLIMIT TIME HEADERS SWITCH
# PORT PORT(S) DEST LIMIT GROUP
#SECTION BLACKLIST
#SECTION ALL
#SECTION ESTABLISHED
#SECTION RELATED
#SECTION NEW
ACCEPT loc net tcp 22,80,53,21,443
ACCEPT loc net udp 53
DNAT net loc:172.16.217.128 tcp 22,80,443
######################################################################################### -
Shorewall version i used is shorewall-4.4.27.tar.bz2, which is the current stable version while writing this post. It was observed that the VM’s getting IP with dhcp had default route set to 172.16.217.2, we have to change the default route of VM’s if DNAT is not working, i had to change default route to 172.16.217.1 on VMs to have port forwarding working.
On debian lenny need to change one more parameter in /etc/default/shorewall file, which is “startup=1″ and in /etc/shorewall/shorewall.conf “STARTUP_ENABLED=Yes”. Make sure that the net.ipv4.ip_forward is set to 1 (net.ipv4.ip_forward=1) in /etc/sysctlc.conf to allow packet forwarding (if you had to change this value then execute sysctl -p /etc/sysctl.conf) otherwise you can use echo 1 >/proc/sys/net/ipv4/ip_forward (for temporary purpose, after a reboot you again to set ip_forward to 1)
It’s time to start the shorewall, issue command “shorewall start” (it’s going to work on most of the linux distributions)
Shorewall is very nicely documented, available on http://www.shorewall.net/
Anuj,