Here you’ll learn to setup ufw in linux to forbid connections from different ports.
UFW
UFW, or Uncomplicated Firewall, is an interface to iptables that is geared towards simplifying the process of configuring a firewall.
If your distro don’t have ufw, install it:
sudo apt-get install ufw
Then, we have options like:
Enable/Disable firewall:
sudo ufw enable sudo ufw disableShow status and detailed status:
sudo ufw status sudo ufw status verboseShow rules list numbered:
sudo ufw status numberedBlocks/Allows all incoming LAN traffic from internet:
sudo ufw default deny incoming sudo ufw default allow incomingBlocks/Allows all outgoing LAN traffic to internet:
sudo ufw default deny outgoing sudo ufw default allow outgoingBlocks/Allows connections through the port 45 (like ssh):
sudo ufw deny 45 sudo ufw allow 45Blocks/Allows connections from a specific ip:
sudo ufw deny from 52.35.156.45 sudo ufw allow from 52.35.156.45Blocks/Allows connections from a specific ip through a specific port 45:
sudo ufw deny from 52.35.156.45 to any port 45 sudo ufw allow from 52.35.156.45 to any port 45Blocks/Allows connections from a specific subnet (any using a ip in range 192.35.156.1 - 192.35.156.254):
sudo ufw deny from 192.35.156.0/24 sudo ufw allow from 192.35.156.0/24Blocks/Allows connections through the port 45 from a specific subnet (any using a ip in range 192.35.156.1 - 192.35.156.254):
sudo ufw deny from 192.35.156.0/24 to any port 45 sudo ufw allow from 192.35.156.0/24 to any port 45Blocks/Allows connections through the port 53 on TCP/UDP:
sudo ufw deny 53/udp sudo ufw allow 53/udp sudo ufw deny 53/tcp sudo ufw allow 53/tcpBlocks/Allow a port ranges on tcp/udp:
sudo ufw allow 6000:6007/tcp sudo ufw allow 6000:6007/udpBlocks/Allows Connections to a Specific Network Interface (e.g. eth0:
sudo ufw deny in on eth0 to any port 15 sudo ufw allow in on eth0 to any port 15Delete a Rule by number(for example, the 2th rule on the list):
sudo ufw delete 2Delete rule (delete rule http and 2044):
sudo ufw delete allow http sudo ufw delete allow 2044Reset (by default) configuration:
sudo ufw reset
