Tutorials

Hands-on guides and configuration examples.

Configuration library · scripts and downloads ↗

Configure Shorewall on Debian 13

Shorewall turns configuration files into Netfilter rules. Zones define networks, policies set defaults, and rules add exceptions.

This guide configures a two-interface IPv4 gateway on Debian 13 “Trixie”. It routes LAN clients to the internet and performs NAT on the WAN.

The example uses a dedicated VM and an isolated LAN. Shorewall handles IPv4 here. If you use IPv6, configure and test its filtering separately with Shorewall6.

  1. Prepare WAN, LAN and a test client

    The names ens18 and ens19 are examples. Identify your interfaces by MAC address and default route before copying the files.

    • WAN ens18. Connect it to the upstream network. This example gets its WAN address and default route from the upstream DHCP server.
    • LAN ens19. Set 192.168.50.1/24 in Debian’s network manager and leave the gateway blank on this interface. Choose a subnet that does not overlap with WAN.
    • Test client. Configure 192.168.50.10/24, gateway 192.168.50.1 and a reachable DNS server such as 1.1.1.1. This example uses static LAN addresses.
    • On Proxmox, connect WAN to the upstream bridge and LAN to a separate bridge without a physical port. Attach the client VM to that second bridge and keep the Proxmox console accessible.
    Terminal
    ip -br addr
    ip route
  2. Install Shorewall and prepare the files

    Use a dedicated test VM. On a host that already applies rules with Docker, nftables or another firewall manager, check how the rule sets interact before applying this configuration.

    Terminal
    sudo apt update && sudo apt install shorewall
    sudo install -d -m 0700 /root/shorewall-lab
    sudo cp -an /etc/shorewall/. /root/shorewall-lab/
    sudoedit /root/shorewall-lab/shorewall.conf

    Set IP_FORWARDING=On in the copied shorewall.conf and check that STARTUP_ENABLED=Yes. Adapt the interface names and addresses below, then use sudoedit to replace the contents of the five files under /root/shorewall-lab.

  3. Declare the zones

    fw represents Debian itself, net is the upstream network, and loc is the LAN.

    /root/shorewall-lab/zones
    # zones
    fw   firewall
    net  ipv4
    loc  ipv4
  4. Assign interfaces to zones

    Format 2 takes a zone, interface and options. The dhcp option permits WAN DHCP traffic. Remove it if the interface uses a static address and the upstream network does not need those exchanges.

    /root/shorewall-lab/interfaces
    # interfaces
    ?FORMAT 2
    net  ens18  dhcp
    loc  ens19
  5. Define the default policies

    The LAN and firewall can initiate connections to WAN. New connections from WAN are dropped, and other flows are rejected by default. Netfilter tracks replies to allowed connections.

    /root/shorewall-lab/policy
    # policy
    loc  net  ACCEPT
    fw   net  ACCEPT
    net  all  DROP
    all  all  REJECT
  6. Allow SSH from an administration client

    This rule allows TCP 22 from 192.168.50.10 only. Adjust the IP and port to match your SSH setup. Remove the rule if you do not use SSH.

    /root/shorewall-lab/rules
    # rules
    ?SECTION NEW
    ACCEPT  loc:192.168.50.10  fw  tcp  22
  7. Configure outbound NAT

    MASQUERADE uses the IPv4 address of ens18 for traffic leaving the LAN. The rule matches 192.168.50.0/24 and the WAN interface.

    /root/shorewall-lab/snat
    # snat
    MASQUERADE  192.168.50.0/24  ens18
  8. Test the configuration for 60 seconds

    Run the syntax check and trial from the local console. Prepare the LAN client tests before starting the timer. Let the trial finish, then inspect firewall status from the console.

    • On the LAN client, test SSH to 192.168.50.1 if sshd is installed. Check DNS and HTTPS with commands such as getent ahostsv4 debian.org and curl -4 -I https://www.debian.org.
    • From an upstream client, check that TCP 22 to the WAN address is blocked if SSH listens on that address. A test from LAN does not verify WAN filtering.
    Terminal
    sudo shorewall check /root/shorewall-lab &&
    sudo shorewall try /root/shorewall-lab 60
  9. Enable Shorewall and troubleshoot

    After a successful trial on the fresh VM, copy the validated files into /etc/shorewall and enable the service. Run these commands from the VM console.

    • If LAN traffic cannot get out, check the client’s default route, the firewall’s WAN route with ip route, and forwarding with sysctl net.ipv4.ip_forward. An IPv4 gateway should report 1.
    • If an IP works but a hostname fails, check the client’s DNS. For startup failures, inspect journalctl -u shorewall -b on the console.
    • For later changes, stage the files, validate them with check and try, then copy them into place and apply them with systemctl reload shorewall.
    Terminal
    sudo cp -a /root/shorewall-lab/. /etc/shorewall/ &&
    sudo shorewall check &&
    sudo systemctl enable --now shorewall
    sudo shorewall status
Official Shorewall two-interface guide ↗