Proxmox VE and Shorewall

| | | | |

Proxmox VE does not come with a firewall by default there are several solutions to this problem but the most flexible and robust is integrating the Shorewall firewall. This document assumes a basic knowledge of the Shorewall program and will not cover all of Shorewall capabilities but will give you a good working model to get you started. For more advanced topics check out the Shorewall documentation.

Shorewall will have 3 zones: 1) the fw zone which is the Proxmox host, 2) the net zone which is the Internet and 3) the dmz zone which is where the virtual machines will reside. The hardware just has one network interface card; vmbr0 is a just a bridge interface.

Note: Want to use Shorewall with stock OpenVZ? Tom Eastep (the Shorewall author) has written an article on the subject that you can find here: Shorewall and OpenVZ.

Network Layout and Shorewall Overview

We will be using proxy arp configuration on the Proxmox host.
A basic Proxmox network configuration looks similar to this:

/etc/network/interfaces
auto eth0

iface eth0 inet static
	address 192.0.2.10
	netmask 255.255.255.0
	gateway 192.0.2.1


auto vmbr0 
iface vmbr0 inet static 
	address  10.1.1.1
	netmask  255.255.255.0 
	bridge_ports none 
	bridge_stp off 
	bridge_fd 0

Proxmox comes by default setup in in a bridged configuration. eth0 is bridged with vmbr0, this will not work for our purposes so we break the bridge and use proxy ARP. Bridging can be made to work but is less flexible. You can define policies with a routed proxy ARP setup; with a bridge you can not. Proxy ARP is a way to expose addresses connected to a private network to the public network. In our case we want to expose our public IP's that are attached to the virtual interface vmbr0. By using private IP space on vmbr0 we also can assign private IP's to our virtual machines if needed.

Installing Shorewall

apt-get install shorewall

Will install all the needed Shorewall components on your Proxmox host node. As of this writing Shorewall 4.0.15 is installed. The configuration files for Shorewall are stored in the /etc/shorewall/ directory. To get started copy an example configuration from the ones installed with the Shorewall package.

cp /usr/share/doc/shorewall-common/default-config/* /etc/shorewall/
cp /usr/share/doc/shorewall-common/examples/two-interfaces/* /etc/shorewall/

This will give you a good base to begin customizing the firewall to meet your needs.

Configuring Shorewall

First thing is to edit the shorewall.conf file. You want to enable IP forwarding. Change it from Keep to On.

IP_FORWARDING=On

Next edit the interfaces file:

net     eth0            detect          tcpflags,routefilter,nosmurfs,logmartians
dmz     venet0          detect          routeback 
dmz     vmbr0           detect          routeback,bridge 

This file just tells Shorewall what interfaces are connected to what zones. This also allows you to make policies based where traffic is traveling to or from. The policy file is where you define what those policies are. In this article the following polices will be defined.

Traffic from the firewall:

  1. To the Internet is permitted
  2. From the Internet is prohibited
  3. To the DMZ is permitted
  4. From the DMZ is prohibited

Traffic from the DMZ:

  1. To the Internet is permitted
  2. To the firewall is prohibited
# From Firewall Policy 
$FW      net     ACCEPT 
$FW      dmz     ACCEPT 

# From DMZ Policy 
dmz     net     ACCEPT 
dmz     $FW     DROP            info    1/sec:2 

# From Net Policy 
net     $FW     DROP            info    1/sec:2 
net     dmz     DROP            info    8/sec:30 

# THE FOLLOWING POLICY MUST BE LAST 
all		all		REJECT		info

Next we need to define rules. Rules are the exceptions to the policies defined above. We are just going to create a very basic set. You can easily expand on these on your own.

#	Accept SSH connections for administration 
# 
SSH/ACCEPT	net		$FW 
SSH/ACCEPT	net		dmz

# Permit access to Proxmox Manager and Console 
ACCEPT          net             $FW     tcp     5900:5999 
HTTPS/ACCEPT    net             $FW 
HTTP/ACCEPT     net             $FW 

# 
#	Allow Ping 
# 
Ping/ACCEPT		dmz		$FW 
Ping/ACCEPT		net		dmz 
Ping/ACCEPT		net		$FW 
ACCEPT		$FW		dmz		icmp 
ACCEPT		$FW		net		icmp 

#
#	VMID: 101
#	Name: test.example.com
#	IP:	192.0.2.11
#
HTTP/ACCEPT		net		dmz:192.0.2.11

This set of rules allows SSH and Ping to work from the net zone. The last part of the file shows a web server running at 192.0.2.11. The syntax is the same for both KVM or an OpenVZ container.

The next file to edit is the proxyarp file. The proxyarp must contain all the IP's of the KVM machines running on the host node. The syntax for the file looks like this:

#ADDRESS	INTERFACE	EXTERNAL	HAVEROUTE	PERSISTENT 
192.0.2.11	vmbr0		eth0		no		yes 
#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE 

The Shorewall documentation explains what this file is and why you need it. To read more about it visit the Shorewall Site

The last file to edit is the masq file. The masq file contains the information for setting up masquerading or SNAT. This allows you to assign private IP's to virtual machines and have them still access the Internet. The syntax of the file looks like this:

#INTERFACE		SOURCE		ADDRESS		PROTO	PORT(S)	IPSEC	MARK 
eth0			10.1.1.0/24 
#LAST LINE -- ADD YOUR ENTRIES ABOVE THIS LINE -- DO NOT REMOVE

The file above says to NAT all address in 10.1.1.0/24 to whatever address eth0 has. In this example a virtual machine with an IP of 10.1.1.2 can be created in Proxmox and access the Internet. You can also add a rule to your rules file to access services running on that host using DNAT. From the Shorewall documentation

The general form of a simple port forwarding rule in /etc/shorewall/rules is:

#ACTION   SOURCE    DEST                                          PROTO      DEST PORT(S)
DNAT      net       loc:[:]  

So to allow a web server running on 10.1.1.2 the rule would look like this:

#ACTION   SOURCE    DEST             PROTO     DEST PORT(S)
Web(DNAT) net       dmz:10.1.1.2

This example uses a Shorewall macro you can learn more about those on the Shorewall website.

Final Notes

Shorewall is a very powerful configuration tool. This document just gives a very basic overview of what can be done with Shorewall and how to integrate it with Proxmox. Two helpful commands when dealing with changing your firewall configuration are shorewall check and shorewall try /etc/shorewall 60. The first command checks the basic syntax of the files and makes sure that you don't have any obvious typos. The second command will run try out the firewall configuration for 60 seconds so that you can test your changes with out accidentally messing something up for more than 60 seconds.

Hopefully this gives a good overview of using Shorewall with Proxmox if you have questions leave me a comment.

Andrew Niemantsverdriet
Linux Systems Administrator
Rocky Mountain College
andrew@rocky.edu

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Adding Veth0

Many months on my Shorewall setup is working very well, im quite happy with it thanks to you.

However i need to install a veth0 interface on a VMachine since this is one of the few places that understand the above configuration i would like to ask the following question, if i issue
vzctl set 101 --netif_add eth0 --save
from the host machine what would the resulting ip address be for the new eth0 interface on the VMachine and how would it be routed out to the internet. many thanks.


Nice article, but how would

Nice article, but how would you add a LAN zone, assuming you need to bridge the LAN zone with an additional eth interface? For example, if you want VMs on LAN, which use broadcasts.


LAN zone

You may want to read this for context: proxmox-ve-with-shorewall-part2.html

You would just add another zone and entry into the interfaces file from there configuration is fairly straight forward.

_
/-\ ndrew


Excellent! It worked great

Excellent! It worked great for me. Thanks.


proxmox firewall config errors

Dear Sir:

i tried following your install instructions but having a few problems with it ... maybe becuz some of these things are assumed we " should know " or whatever but it left me hanging in mid air

you say for example to modify the proxmox file and to " break the bridge but you don't say how exactly how to do it and where does all the other code additions go .... in the shorewall config file, interfaces ???? where i'm confused pls let me asap so i can get this firewall working thks


Error

Im recieving this error any idea what it could be ?

Checking...
Initializing...
Determining Zones...
IPv4 Zones: net loc
Firewall Zone: fw
Validating interfaces file...
ERROR: Invalid zone (dmz) in record "dmz venet0 detect routeback"
Terminated


More infomation is needed

Could you show what is in the zones file (cat /etc/shorewall/zones)? Also please post the output of ifconfig.

_
/-\ ndrew


Same problems (installed proxmox 1.5)

Hello,
I have the same issue. It would be great if you can aid me. Thx in advance.

My zones are defined as you did:

###############################################################################
#ZONE TYPE OPTIONS IN OUT
# OPTIONS OPTIONS
fw firewall
net ipv4
loc ipv4

and my ifconfig reports:

th0 Link encap:Ethernet HWaddr 00:25:90:04:a8:d8
inet addr:178.162.19.156 Bcast:178.162.19.255 Mask:255.255.255.0
inet6 addr: fe80::225:90ff:fe04:a8d8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:306238 errors:0 dropped:0 overruns:0 frame:0
TX packets:99717 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:30358043 (28.9 MiB) TX bytes:51214424 (48.8 MiB)
Memory:fbce0000-fbd00000

eth0:1 Link encap:Ethernet HWaddr 00:25:90:04:a8:d8
inet addr:95.168.18.25 Bcast:95.168.18.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Memory:fbce0000-fbd00000

eth0:2 Link encap:Ethernet HWaddr 00:25:90:04:a8:d8
inet addr:84.16.26.67 Bcast:84.16.26.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Memory:fbce0000-fbd00000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:37973 errors:0 dropped:0 overruns:0 frame:0
TX packets:37973 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13712072 (13.0 MiB) TX bytes:13712072 (13.0 MiB)

venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
UP BROADCAST POINTOPOINT RUNNING NOARP MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

vmbr0 Link encap:Ethernet HWaddr 00:00:00:00:00:00
inet addr:10.254.254.254 Bcast:10.255.255.255 Mask:255.0.0.0
inet6 addr: fe80::200:ff:fe00:0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:468 (468.0 B)

vmtab101i0 Link encap:Ethernet HWaddr ba:27:da:b8:f5:c5
inet6 addr: fe80::b827:daff:feb8:f5c5/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:8077 errors:0 dropped:0 overruns:0 frame:0
TX packets:184299 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:637247 (622.3 KiB) TX bytes:10804445 (10.3 MiB)

vmtab102i0 Link encap:Ethernet HWaddr fa:29:c0:4e:93:86
inet6 addr: fe80::f829:c0ff:fe4e:9386/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:1705 errors:0 dropped:0 overruns:0 frame:0
TX packets:185621 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:180593 (176.3 KiB) TX bytes:10909931 (10.4 MiB)

vmtab103i0 Link encap:Ethernet HWaddr 7a:ae:bd:d4:66:36
inet6 addr: fe80::78ae:bdff:fed4:6636/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:8333 errors:0 dropped:0 overruns:0 frame:0
TX packets:179627 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:350850 (342.6 KiB) TX bytes:10589480 (10.0 MiB)


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.