Could somebody give some simple steps with configuration example how to setup simple firewall on Ubuntu (using console only)? Only ssh, http and https access should be allowed.
|
|
sudo ufw default deny sudo ufw allow http sudo ufw allow https sudo ufw allow ssh sudo ufw enable |
|||||||||||||||||||||
|
|
Use this script. Just decide if you want to allow incoming ICMP (ping) or not.
|
|||
|
|
|
As noted in comments to another answer, you don't want to lose your connection before you allow the ssh port. From the man page: "REMOTE MANAGEMENT When running ufw enable or starting ufw via its initscript, ufw will flush its chains. This is required so ufw can maintain a consistent state, but it may drop existing connections (eg ssh). ufw does support adding rules before enabling the firewall, so administrators can do:
before running ’ufw enable’. The rules will still be flushed, but the ssh port will be open after enabling the firewall. Please note that once ufw is ’enabled’, ufw will not flush the chains when adding or removing rules (but will when modifying a rule or changing the default policy)." So here is an approach that uses a script to set it. You will get logged out when you run this script, but having run it you can then log in again over ssh. Put the following in a script and call it start-firewall.sh
And then make it executable and run it by doing
To learn more, read the man page. |
||||
|
|
|
If you familiarize yourself with scripting |
|||
|
|
|
Quicktables helped me to learn iptables rules. Just run the script and it will generate an iptables script for you... then you can open it and view the associated commands generated by the questions it asked of you. It's a great learning resource. Unfortunately, it is no longer maintained. |
|||
|
|
|
I really like using firehol (package). To create setup rules you like you would need to edit the file /etc/default/firehol and change START_FIREHOL=YES And you would want to make your /etc/firehol/firehol.conf look like this.
One of the great things about firehol is the 'try' command. You can adjust your configuration file and do a 'firehol try', if you where connected via ssh, and something about what you changed killed your network access then firehol will revert the changes. To have the changes actually go into effect, you must say commit. |
|||||||||
|
|
I would prefer Shorewall. It is easy to setup but flexible at the same time. |
|||
|
|
|
Maybe you should take a look at http://iptables-tutorial.frozentux.net/iptables-tutorial.html. Also you can find more information on lartc.org |
|||
|
|
|
Then, look in the System->Administration menu. |
|||||||||||||||||
|