A firewall is like a security guard for your computer. Imagine your computer is a house, and it has lots of doors and windows—that's how it talks to the outside world, like the Internet. The firewall stands at those doors and windows to check everyone and everything trying to come in or go out. If it sees something it doesn't trust, like a stranger, it doesn't let them in (to keep your server safe).

A port in computing is like a specific door in that house where only certain kinds of information can go in or out. Just like a mailbox might be the place where all the mail goes, a specific port on a computer is where certain types of data are sent or received. This helps keep things organized and secure. A port is merely a number, agreed upon (in advance) by both the sender and receiver.

A Linux server will employ dozens (hundreds?) of ports. Some ports must be exposed to the public (like the mailbox). Most can be (and should be) hidden from the public to increase security. This is where the firewall comes in - it blocks public access to server ports - unless you tell it otherwise (using “rules”).

This is a basic explanation and introduction to the GB firewall recommendations when using CAS.

CAS does not automatically configure your firewall.

Incoming TCP ports required by CAS (reference):

7741 is required for the gate service (20230801+),

7742 and [13000 to 13010] is required by the Terminal VPN.

7777 is required for insecure admin access

[12000 through 12050] are also required for CAS Administration access via VPN.

7743 is OPTIONAL - may be used by various extensions (Onfido, etc).

443 is OPTIONAL - may be used by nginx (or other web servers) when implementing a proxy server.

More:

Terminal Security - protect your CAS from Terminal attacks

CAS Admin - secure your Administration page via VPN

Digital Ocean: How To Set Up a Firewall with UFW on Ubuntu 20.04


Two different methods of implementing the Ubuntu firewall are specified here. Please use UFW when possible. A default "clean" Ubuntu LTS server installation - as specified in GB documentation, will automatically permit all access to these ports. If the ports are already blocked, then something unexpected has been installed, and this falls outside the scope of our support.

In the interest of security, you should always employ a firewall on your CAS server.


Option 1 (Easiest): Configure UFW

UFW, or Uncomplicated FireWall, is a simplified firewall management interface. It controls “iptables” without the college degree. UFW is included (by default) with Ubuntu. These instructions will restrict access solely to your terminals and those people with whom you deliberately share access to CAS.

Check to see if UFW is enabled and running:

sudo ufw status

If UFW is enabled and working, it will report the active rules of allowed connections to your server - otherwise you'll see something like this:

If UFW is active, then this procedure will erase that previous configuration and rewrite the rules.


1. Initialize UFW

Reset & deny all incoming connections by default:

sudo ufw reset

Deny all public access to all ports:

sudo ufw default deny incoming

2. SSH

Allow incoming TCP connections on port 22 for SSH connections:

sudo ufw allow ssh

For increased security, you might limit access to a specific IP:


3. BATM/Terminals

Terminals (v.20230801+) employing the VPN normally use only ports 7742, and 13000 through 13010.

Terminal VPN rules:

sudo ufw allow 7742/tcp
sudo ufw allow in on eth0 from any to any proto tcp port 13000:13010
note

First-time connection to CAS

If you are connecting a new BATM, you will need to temporarily expose port 7741:

sudo ufw allow 7741/tcp

After you’ve connected the BATM, remove the UFW exception with:

sudo ufw deny 7741/tcp

First-time connection to CAS

If you are connecting a new BATM, you will need to temporarily expose port 7741:

sudo ufw allow 7741/tcp

After you’ve connected the BATM, remove the UFW exception with:

sudo ufw deny 7741/tcp


4. Administrative Access

Allow administrative access to CAS. Without this access, you cannot login to the CAS GUI.

Secure admin rules:

  1. Configure the firewall integrated admin VPN:

sudo ufw allow in on eth0 from any to any proto tcp port 12000:12050
sudo ufw allow in on tunU+ to any port 7777 proto tcp
note

Alternatives:

Less secure option:

If you have a static IP on your home/office and won’t use the integrated VPN:

sudo ufw allow from ALLOWED_IP to any port 7777

  • Set ALLOWED_IP to your home/office PUBLIC IP.

    • Determine your current public IP with your browser; navigate to this website: My IP

    • In some cases the IP will change frequently, and you’ll have to go in frequently and update it.

If you use nginx as a proxy server, then change the port as follows:

sudo ufw allow from ALLOWED_IP to any port 443

Completely unprotected (strongly discouraged):

This will expose your server to attack (and there’s little reason to even use a firewall in this case):

sudo ufw allow 7777/tcp

Alternatives:

Less secure option:

If you have a static IP on your home/office and won’t use the integrated VPN:

sudo ufw allow from ALLOWED_IP to any port 7777

  • Set ALLOWED_IP to your home/office PUBLIC IP.

    • Determine your current public IP with your browser; navigate to this website: My IP

    • In some cases the IP will change frequently, and you’ll have to go in frequently and update it.

If you use nginx as a proxy server, then change the port as follows:

sudo ufw allow from ALLOWED_IP to any port 443

Completely unprotected (strongly discouraged):

This will expose your server to attack (and there’s little reason to even use a firewall in this case):

sudo ufw allow 7777/tcp


(Optional) Allow incoming TCP connections on port 7743 for extensions:

sudo ufw allow 7743/tcp

Finally, enable/reload UFW to enforce the new rules:

sudo ufw enable
# final step (in the event that UFW was already enabled):
sudo ufw reload

If your system complied with your commands, you should now be protected by UFW.

Option 2: iptables

These are examples using the iptables command. This option is for experts that employ a custom firewall. UFW saves configurations, but iptables does not. You’ll have to implement your own deployment scheme. Do not use iptables (or proceed) unless you are willing to accept all involved risks.

Digital Ocean droplets routinely use “eth0" as the public interface name.

Default/initial iptables entries:

sudo iptables -F INPUT
sudo iptables -P INPUT ACCEPT
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

Permit admin access using one of the following options:

Least secure: this option is the bare minimum to permit access (never recommended).

sudo iptables -A INPUT -p tcp --dport 7777 -j ACCEPT

More secure: if your home/office router has a STATIC (unchanging) IP address, modify the rule to permit only access to that IP:

sudo iptables -A INPUT -p tcp -s ALLOWED_IP --dport 7777 -j ACCEPT

Most secure: using the integrated OpenVPN connection:

sudo iptables -A INPUT -p tcp --match multiport --dports 12000:12100 -j ACCEPT

Permit unsecured Terminal access:

If you need to reconnect a “lost” or new BATM/Terminal, you must grant it unsecured access:

sudo iptables -A INPUT -p tcp --dport 7741 -j ACCEPT

Permit Terminal VPN & Extension access

sudo iptables -A INPUT -p tcp --dport 7742 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 7743 -j ACCEPT
sudo iptables -A INPUT -p tcp --match multiport --dports 13000:13050 -j ACCEPT

Finally: block everything else:

sudo iptables -I INPUT 1 -i lo -j ACCEPT
sudo iptables -A INPUT -j DROP

That’s it, the iptables are now configured (until you reboot).


Troubleshooting

When requested by Support, please forward the iptables in a ticket.

Enable UFW:

ufw enable

List the firewall rules:

iptables -S

Disable UFW again (if unusable):

ufw disable


Related articles

The content by label feature displays related articles automatically, based on labels you choose. To edit options for this feature, select the placeholder below and tap the pencil icon.

Related issues