Thursday, 12 December 2019

How to open ports on Ubuntu

I've recently had a situation where I was running HTTP server (written in Go) on port 8080 on my Ubuntu machine and had to access it from my Windows machine (which was on the same network). At first I got a connection time out error and I assumed Ubuntu was just rejecting connections for not having 8080 port opened. I was right. I used UFW (Uncomplicated Firewall) to open port on my Linux machine. UFW comes with Ubuntu (18.04 in my case) so didn't have to install any additional packages.

Let's see all ufw commands:

$ ufw --help
Usage: ufw COMMAND

 enable                          enables the firewall
 disable                         disables the firewall
 default ARG                     set default policy
 logging LEVEL                   set logging to LEVEL
 allow ARGS                      add allow rule
 deny ARGS                       add deny rule
 reject ARGS                     add reject rule
 limit ARGS                      add limit rule
 delete RULE|NUM                 delete RULE
 insert NUM RULE                 insert RULE at NUM
 route RULE                      add route RULE
 route delete RULE|NUM           delete route RULE
 route insert NUM RULE           insert route RULE at NUM
 reload                          reload firewall
 reset                           reset firewall
 status                          show firewall status
 status numbered                 show firewall status as numbered list of RULES
 status verbose                  show verbose firewall status
 show ARG                        show firewall report
 version                         display version information

Application profile commands:
 app list                        list application profiles
 app info PROFILE                show information on PROFILE
 app update PROFILE              update PROFILE
 app default ARG                 set default application policy

You need to be root in order to perform majority of ufw operations.

To check firewall's status (whether it's active or not):

$ sudo ufw status

To enable it:

$ sudo ufw enable

To open 8080 port for TCP connections:

$ sudo ufw allow 8080/tcp

To verify the result:

$ sudo ufw status

Status: active

To                         Action      From
--                         ------      ----
8080/tcp                   ALLOW       Anywhere                  
8080/tcp (v6)              ALLOW       Anywhere (v6) 


UFW - Community Help Wiki

No comments: