Dynamic Zones

Tom Eastep

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover, and with no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.

2016/02/16


Overview

There is sometimes a need to be able to define a zone whose members are unknown at compile-time. For example, you may wish to require authentication of internal users before allowing them access to the internet. When a user is authenticated, the user's IP address is added to the zone of users permitted web access.

Shorewall provides basic support for defining such zones. This support is based on ipset. Most current distributions have ipset, but you may need to install the xtables-addons.

Installing xtables-addons

If your distribution does not have an xtables-addons package, the xtables-addons are fairly easy to install. You do not need to recompile your kernel.

Debian™ users can find xtables-addons-common and xtables-addons-source packages in testing. The kernel modules can be built and installed with the help of module-assistant. As of this writing, these packages are in the admin group rather than in the network group!!??

For other users, the basic steps are as follows:

  1. Install gcc and make

  2. Install the headers for the kernel you are running. In some distributions, such as Debian™ and Ubuntu™, the packet is called kernel-headers. For other distrubutions, such as OpenSuSE, you must install the kernel-source package.

  3. download the iptables source tarball

  4. untar the source

  5. cd to the iptables source directory

  6. run 'make'

  7. as root, run 'make install'

  8. Your new iptables binary will now be installed in /usr/local/sbin. Modify shorewall.conf to specify IPTABLES=/usr/local/sbin/iptables

  9. Download the latest xtables-addons source tarball

  10. Untar the xtables-addons source

  11. cd to the xtables-addons source directory

  12. run './configure'

  13. run 'make'

  14. As root, cd to the xtables-addons directory and run 'make install'.

  15. Restart shorewall

  16. 'shorewall show capabilities' should now indicate Ipset Match: Available

You will have to repeat steps 10-13 each time that you receive a kernel upgrade from your distribution vendor. You can install xtables-addons before booting to the new kernel as follows (new-kernel-version is the version of the newly-installed kernel - example 2.6.28.11-generic. Look in the /lib/modules directory to get the full version name)

  1. cd to the xtables-addons source directory

  2. run 'make clean'

  3. run './configure --with-kbuild=/lib/modules/new-kernel-version/build --with-ksource=/lib/modules/new-kernel-version/source'

  4. run 'make'

  5. As root, cd to the xtables-addons source directory and run 'make install'.

  6. As root, run 'depmod -a new-kernel-version'

Dynamic Zones -- Shorewall 4.5.9 and Later

Prior to Shorewall 4.5.9, when multiple records for a zone appear in /etc/shorewall/hosts, Shorewall would create a separate ipset for each interface. This meant that an add or delete command was required for each of the interface, when the address involved was reachable via multiple interfaces.

Beginning with Shoreawll 4.5.9, it is possible to have a single ipset shared among all interfaces. This also simplifies management of dynamic zone contents for dynamic zones associated with only a single interface.

The earlier implementation described below is still available in these later releases.

Defining a Dynamic Zone

A dynamic zone is defined by specifying the dynamic_shared option in the zones file and using the dynamic keyword in the hosts list.

/etc/shorewall/zones:

#NAME        TYPE             OPTIONS
net          ipv4
rsyncok:loc  ipv4             dynamic_shared

/etc/shorewall/interfaces:

#ZONE       INTERFACE      BROADCAST        OPTIONS
loc         eth0           -                …
loc         eth1           -                …

/etc/shorewall/hosts:

#ZONE       HOSTS          OPTIONS
rsyncok     eth0:dynamic
rsyncok     eth1:dynamic

When the dynamic_shared option is specified, a single ipset is created; the ipset has the same name as the zone.

Adding a Host to a Dynamic Zone.

Adding a host to a dynamic zone is accomplished by adding the host's IP address to the appropriate ipset. Shorewall provldes a command for doing that:

shorewall add zone address ...

Example:

shorewall add rsyncok 70.90.191.124

Deleting a Host from a Dynamic Zone

Deleting a host from a dynamic zone is accomplished by removing the host's IP address from the appropriate ipset. Shorewall provldes a command for doing that:

shorewall delete zone address ...

Example:

shorewall delete rsyncok 70.19.191.124

The command can only be used when the ipset involved is of type iphash. For other ipset types, the ipset command must be used directly.

Listing the Contents of a Dynamic Zone

The shorewall show command may be used to list the current contents of a dynamic zone.

shorewall show dynamic zone

Example:

shorewall show dynamic rsyncok
rsyncok:
   70.90.191.122
   70.90.191.124

Dynamic Zones -- Shorewall 5.4.8 and Earlier.

The method described in this section is still supported in the later releases.

Defining a Dynamic Zone

A dynamic zone is defined by using the keyword dynamic in the zones host list.

Example:

/etc/shorewall/zones:

#NAME        TYPE             OPTIONS
loc          ipv4
webok:loc    ipv4

/etc/shorewall/interfaces:

#ZONE       INTERFACE      BROADCAST        OPTIONS
loc         eth0           -                …

/etc/shorewall/hosts:

#ZONE       HOSTS          OPTIONS
webok       eth0:dynamic

Once the above definition is added, Shorewall will automatically create an ipset named webok_eth0 the next time that Shorewall is started or restarted. Shorewall will create an ipset of type iphash. If you want to use a different type of ipset, such as macipmap, then you will want to manually create that ipset yourself before the next Shorewall start/restart.

The dynamic zone capability was added to Shorewall6 in Shorewall 4.4.21.

Adding a Host to a Dynamic Zone

Adding a host to a dynamic zone is accomplished by adding the host's IP address to the appropriate ipset. Shorewall provldes a command for doing that:

shorewall add interface:address ... zone

Example:

shorewall add eth0:192.168.3.4 webok

The command can only be used when the ipset involved is of type iphash. For other ipset types, the ipset command must be used directly.

Deleting a Host from a Dynamic Zone

Deleting a host from a dynamic zone is accomplished by removing the host's IP address from the appropriate ipset. Shorewall provldes a command for doing that:

shorewall delete interface:address ... zone

Example:

shorewall delete eth0:192.168.3.4 webok

The command can only be used when the ipset involved is of type iphash. For other ipset types, the ipse t command must be used directly.

Listing the Contents of a Dynamic Zone

The shorewall show command may be used to list the current contents of a dynamic zone.

shorewall show dynamic zone

Example:

shorewall show dynamic webok
eth0:
   192.168.3.4
   192.168.3.9

Dynamic Zone Contents and Shorewall stop/start/restart

When SAVE_IPSETS=Yes in shorewall.conf, the contents of a dynamic zone survive shorewall stop/shorewall start and shorewall restart. During shorewall stop, the contents of the ipsets are saved in the file ${VARDIR}/ipsets.save (usually /var/lib/shorewall/ipsets.save). During shorewall start, the contents of that file are restored to the sets. During both shorewall start and shorewall restart, any new ipsets required as a result of a configuration change are added.

Documentation


Frequently Used Articles

- FAQs - IPv4 Manpages - IPv6 Manpages - Configuration File Basics - Beginner Documentation - Troubleshooting

Shorewall 4.0/4.2 Documentation


Current HOWTOs and Other Articles

- 6to4 and 6in4 Tunnels - Accounting - Actions - Aliased (virtual) Interfaces (e.g., eth0:0) - Anatomy of Shorewall - Anti-Spoofing Measures - AUDIT Target support - Bandwidth Control - Blacklisting/Whitelisting - Bridge/Firewall - Building Shorewall from GIT - Commands - Compiled Programs - Configuration File Basics - DHCP - DNAT - Dynamic Zones - ECN Disabling by host or subnet - Events - Extension Scripts - Fallback/Uninstall - FAQs - Features - Fool's Firewall - Forwarding Traffic on the Same Interface - FTP and Shorewall - Helpers/Helper Modules - Installation/Upgrade - IPP2P - IPSEC - Ipsets - IPv6 Support - ISO 3661 Country Codes - Kazaa Filtering - Kernel Configuration - KVM (Kernel-mode Virtual Machine) - Limiting Connection Rates - Linux Containers (LXC) - Linux-vserver - Logging - Macros - MAC Verification - Manpages (IPv4) (IPv6) - Manual Chains - Masquerading - Multiple Internet Connections from a Single Firewall - Multiple Zones Through One Interface - My Shorewall Configuration - Netfilter Overview - Network Mapping - No firewalling of traffic between bridge port - One-to-one NAT - Operating Shorewall - OpenVPN - OpenVZ - Packet Marking - Packet Processing in a Shorewall-based Firewall - 'Ping' Management - Port Forwarding - Port Information - Port Knocking (deprecated) - Port Knocking, Auto Blacklisting and Other Uses of the 'Recent Match' - PPTP - Proxy ARP - QuickStart Guides - Release Model - Requirements - Routing and Shorewall - Routing on One Interface - Samba - Shorewall Events - Shorewall Init - Shorewall Lite - Shorewall on a Laptop - Shorewall Perl - Shorewall Setup Guide - SMB - SNAT - Split DNS the Easy Way - Squid with Shorewall - Starting/stopping the Firewall - Static (one-to-one) NAT - Support - Tips and Hints - Traffic Shaping/QOS - Simple - Traffic Shaping/QOS - Complex - Transparent Proxy - UPnP - Upgrade Issues - Upgrading to Shorewall 4.4 (Upgrading Debian Lenny to Squeeze) - VPN - VPN Passthrough - White List Creation - Xen - Shorewall in a Bridged Xen DomU - Xen - Shorewall in Routed Xen Dom0

Top of Page