Denne nyttige guiden fant jeg her. Den er på engelsk, men hvorfor ikke :)
A new Ubuntu Server install (as of 10.04) contains a firewall (iptables) that is not enabled. Ubuntu.com has a great tutorial that explains that ufw is the default configuration tool for iptables. After I set up my server, I used ufw to close all ports by default, then open up ports for the services I use. I don’t have complex security needs or run a proxy server, so my rules are simple.
The following commands open ports for named services that I use: namely, SSH (port 22), a web server (port 80), and Webmin (port 10000). Any services named in /etc/services may be identified by name instead of port number.
UFW also has a list of application presets, for common servers such as Apache, OpenSSH, Lighttpd, and Samba. You can view the list by issuing the command:
You can implement firewall rules for Samba and Lighttpd by using the commands below, which specify the application name, not the service name. Note that you must enclose in quotation marks any application names that include spaces.
It’s better to limit Samba access to hosts on your LAN. Using ufw’s more complex syntax, you can do just that. Note that you have to add “app” before the application name in this case.
The following commands open the ports required by my Transmission-Daemon server. Here I must specify port numbers explicitly. Note that you use a colon instead of a dash to specify port ranges. Plus, when creating rules for port ranges, you must specify whether they apply to TCP or UDP.
The following command opens up ports needed for MySQL, but only to hosts within the local network.
If you wish to open up MySQL to the world, you could use a simpler syntax.
For example:
You can also delete all the rules with a single command.
A new Ubuntu Server install (as of 10.04) contains a firewall (iptables) that is not enabled. Ubuntu.com has a great tutorial that explains that ufw is the default configuration tool for iptables. After I set up my server, I used ufw to close all ports by default, then open up ports for the services I use. I don’t have complex security needs or run a proxy server, so my rules are simple.
Adding Rules
Before adding rules, it’s best to explicitly set the default behavior. By default, I like to block everything: both incoming and outgoing traffic. After that is done, I selectively open ports to support the services I wish to run. In contrast, UFW, by default, denies all incoming traffic but allows all outgoing traffic. That setup is accomplished manually with the following commands.$ sudo ufw default deny incoming
$ sudo ufw default allow outgoing
The following commands open ports for named services that I use: namely, SSH (port 22), a web server (port 80), and Webmin (port 10000). Any services named in /etc/services may be identified by name instead of port number.
$ sudo ufw allow ssh
$ sudo ufw allow www
$ sudo ufw allow webminUFW also has a list of application presets, for common servers such as Apache, OpenSSH, Lighttpd, and Samba. You can view the list by issuing the command:
$ sudo ufw app listYou can implement firewall rules for Samba and Lighttpd by using the commands below, which specify the application name, not the service name. Note that you must enclose in quotation marks any application names that include spaces.
$ sudo ufw allow SambaIt’s better to limit Samba access to hosts on your LAN. Using ufw’s more complex syntax, you can do just that. Note that you have to add “app” before the application name in this case.
$ sudo ufw allow from 10.0.0.0/8 to 127.0.0.1 app Samba
$ sudo ufw allow to 10.0.0.0/8 from 127.0.0.1 app SambaThe following commands open the ports required by my Transmission-Daemon server. Here I must specify port numbers explicitly. Note that you use a colon instead of a dash to specify port ranges. Plus, when creating rules for port ranges, you must specify whether they apply to TCP or UDP.
$ sudo ufw allow 9091
$ sudo ufw allow 20500:20599/tcp
$ sudo ufw allow 20500:20599/udp
The following command opens up ports needed for MySQL, but only to hosts within the local network.
$ sudo ufw allow from 10.0.0.0/8 to any port 3306/tcpIf you wish to open up MySQL to the world, you could use a simpler syntax.
$ sudo ufw allow mysqlDeleting Rules
Deleting rules is pretty simple. Just use the following syntax, and replace <…> with the entire rule that you wish to delete.$ sudo ufw delete <...>For example:
$ sudo ufw delete allow ssh
$ sudo ufw delete allow 10000You can also delete all the rules with a single command.
$ sudo ufw resetEnabling the Firewall
The following command enables the firewall rules immediately, and upon subsequent system restarts. This command will also refresh the rules. Run this command each time you update your firewall configuration.$ sudo ufw enableDisabling the Firewall
To disable the firewall, simply issue the following command.$ sudo ufw disableChecking the Configuration
You can check your configuration by issuing one of the following commands. The “verbose” version shows more information.$ sudo ufw status
$ sudo ufw status verbose
Kommentarer