Hands-on lab for basic ufw usage

You'll need to complete this lab on a clean snapshot of your Ubuntu virtual machine. Let's get started:

  1. Shut down your Ubuntu virtual machine and restore the snapshot to get rid of all of the iptables stuff that you just did. (Or, if you prefer, just start with a fresh virtual machine.)
  2. When you've restarted the virtual machine, verify that the iptables rules are now gone:
sudo iptables -L
  1. View the status of ufw. Open port 22/TCP and then enable ufw. Then, view the results:
sudo ufw status
sudo ufw allow 22/tcp
sudo ufw enable
sudo ufw status
sudo iptables -L
sudo ip6tables -L
  1. This time, open port 53 for both TCP and UDP:
sudo ufw allow 53
sudo iptables -L
sudo ip6tables -L
sudo ufw status
  1. cd into the /etc/ufw directory. Familiarize yourself with the contents of the files that are there.
  2. Open the /etc/ufw/before.rules file in your favorite text editor. At the bottom of the file, below the COMMIT line, add the following code snippet:
# Mangle table added by Donnie
*mangle
:PREROUTING ACCEPT [0:0]
-A PREROUTING -m conntrack --ctstate INVALID -j DROP
-A PREROUTING -p tcp -m tcp ! --tcp-flags FIN,SYN,RST,ACK SYN -m conntrack --ctstate

NEW -j DROP
COMMIT
  1. Repeat step 6 for the /etc/ufw/before6.rules file.
  2. Reload the firewall by using the following command:
sudo ufw reload
  1. Observe the rules by using the following command:
sudo iptables -L
sudo iptables -t mangle -L
sudo ip6tables -L
sudo ip6tables -t mangle -L
  1. Take a quick look at the ufw status:
sudo ufw status

That's the end of the lab – congratulations!

As cool as ufw is, it still uses the old-school iptables technology as its core engine. Is there something more modern that we can use instead? You bet, and we'll look at that in the next chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.200.211