Ubuntu – How to open up firewall while keeping it safe

bittorrentfirewallopenvpnsambavirtualbox

Since I've installed Firestarter I have encountered connectivity issues that are all resolved by disabling the firewall. I'd prefer to have the firewall running and allow all the traffic I normally use:

  1. Wired network + wireless network, whichever I'm connected to, or both (1)
  2. OpenVPN
  3. VirtualBox internal network
  4. Samba (for accessing shared Windows folders and sharing folders to Windows) (2)
  5. BitTorrent
  6. And everything else I use that I can't think of 🙂

All the above works without a firewall.

(1) I used the Firestarter wizard and selected wlan0 as my primary connection, now whenever I plug in a network cable, I lose all connectivity. Should I just redo the wizard for eth0, or will I then lose wlan0?

(2) If it makes a difference I'm sharing a directory that I share between local users using bindfs. See my answer to Good and easy way to share files on local machine

Best Answer

Here is one easy way to do it. My answer is going to assume that you have disabled all other firewall rules / packages you have tried.

Ubuntu has a nice very simple command line interface to "iptables" (Linux firewall) which is call UFW for Uncomplicated FireWall.

simply do this:

sudo ufw status

you'll see that your firewall is currently inactive:

"Status: inactive"

if you then issue the following command:

sudo ufw enable

you'll then get this message if it worked:

"Firewall is active and enabled on system startup"

Final Thoughts / Wrap Up:

Honestly this is all you'll probably need as the default ufw policy allows all outbound traffic (i.e. you surfing, downloading, etc) and blocks all inbound traffic to your box.

If you wanted to allow say... ssh/scp connections to your box/laptop for some reason you could simple add a rule such as this:

sudo ufw allow proto tcp from 192.168.1.0/24 to any port 22

In my opinion the syntax / commands are very simple and a gui app or overlay isn't bad, but not necessarily needed for what you seem to be wanting to achieve.

For more info check out the community docs on UFW here: https://help.ubuntu.com/community/UFW

I hope this has been helpful. =)

##### EDIT ##### (adding this in case people don't see my comment reply below and to add a resource link)

If you are wanting to open up certain ports click this link and look up all the ports you need (tcp and/or udp) for the services you listed: http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

Then to open that port up from anywhere to your machine do this:

sudo ufw allow proto tcp from any to any port __

or

sudo ufw allow proto udp from any to any port __

If you only want to open it up to ONLY your home 192.168.1.x network you could do this:

sudo ufw allow proto tcp from 192.168.1.0/24 to any port __

or

sudo ufw allow proto udp from 192.168.1.0/24 to any port __