Thursday, June 16, 2022

Using UFW to retrict network access to specific IP's/LAN

'ufw' is a firewall usually preinstalled on ubuntu systems but disabled by default.

You will need root access to configure the firewall.

This tutorial assumes that the router and the server are in the same subnet -- here 192.168.1.*. The server on LAN which we want to permit access to is 192.168.1.20

#step 1: make sure ipv6 is enabled too for the firewall

sudo nano /etc/default/ufw

check if "IPV6=yes"

if yes then do no changes

# step 2 (these are defaults but no harm forcing it again)

ufw enable

ufw default deny incoming

ufw default allow outgoing

# step 3 manual rules

ufw allow from 192.168.1.20

ufw allow out to 192.168.1.20

ufw deny out to any

# how it works

-- first manual rule allow incoming traffic from the ip

-- second rule allows outgoing traffic to the server

-- third rule denies any other outgoing connections to any ip on any port.