Skip to content

Commit

Permalink
Added FirewallD support to scripts
Browse files Browse the repository at this point in the history
The default action on Fedora and RHEL-based distributions that use
FirewallD is to ban DHCP requests. Instead of telling people to turn off
their firewall, I recommend adding the tap interfaces to the FirewallD
trusted zone.

This commit adds automatic support to the create_net.sh and
cleanup-net.sh scripts that set up the tap interfaces. Due to many
distributions using FirewallD these days, I opted for using the
following command to check if FirewallD is available:

if [ -e $(which --skip-alias firewall-cmd) ]; then
    sudo firewall-cmd --zone=trusted --change-interface=$device
fi

However, we will have to create a better solution for this in the
future.

Signed-off-by: Frey Alfredsson <[email protected]>
  • Loading branch information
freysteinn committed Apr 7, 2024
1 parent 2c934b4 commit 007bb7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tools/labs/qemu/cleanup-net.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

DNSMASQ=/tmp/dnsmasq

for i in lkt-tap0 lkt-tap1 lkt-tap-smbd; do
if ! ip a s dev &> /dev/null $i; then
for device in lkt-tap0 lkt-tap1 lkt-tap-smbd; do
if ! ip a s dev &> /dev/null $device; then
continue
fi
if [ -f $DNSMASQ-$i.pid ]; then
sudo kill `cat $DNSMASQ-$i.pid`
if [ -f $DNSMASQ-$device.pid ]; then
sudo kill $(cat $DNSMASQ-$device.pid)
fi
sudo rm $DNSMASQ-$i.leases
sudo ip tuntap del $i mode tap
sudo rm $DNSMASQ-$device.leases
if [ -e $(which --skip-alias firewall-cmd) ]; then
sudo firewall-cmd --zone=trusted --remove-interface=$device
fi
sudo ip tuntap del $device mode tap
done
4 changes: 4 additions & 0 deletions tools/labs/qemu/create_net.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ sudo /sbin/ip link set dev "$device" down
sudo /sbin/ip address add $subnet.1/24 dev "$device"
sudo /sbin/ip link set dev "$device" up

if [ -e $(which --skip-alias firewall-cmd) ]; then
sudo firewall-cmd --zone=trusted --change-interface=$device
fi

sudo dnsmasq --port=0 --no-resolv --no-hosts --bind-interfaces \
--interface $device -F $subnet.2,$subnet.20 --listen-address $subnet.1 \
-x /tmp/dnsmasq-$device.pid -l /tmp/dnsmasq-$device.leases || true

0 comments on commit 007bb7a

Please sign in to comment.