Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

built-in firewall. UFW simplifies the user tasks and syntax but really just uses
iptables. You probably won’t need to know this on your Ubuntu machine,


but for completeness and to help you in case you use a different Linux
distribution in the future, Table 20.2 lists simple, basic commands as a brief
introduction to iptables.


In the table, you see words in all-caps like ACCEPT and DROP, which are
policies to be set for things called chains. Chains are descriptions of specific
types of network access, such as INPUT, FORWARD, and OUTPUT in Table
20.2, as well as other interactions in a network. You can, for example, define
the default policy as DROP, which means to reject, and then ALLOW specific
types of traffic to go through the firewall. iptables is quite complex and
incredibly powerful.


Table 20.2 Useful Commands for iptables


Command Actions Performed

Usage: command

sudo    iptables    -LLists the currently   set firewall    rules

sudo    iptables    -L
-vn

Lists   the currently   set firewall    rules   but with    more
detail

sudo    iptables    -FDeletes   all currently   set firewall    rules

sudo    iptables    -P
INPUT DROP

Drops   all incoming    traffic

sudo    iptables    -P
FORWARD ACCEPT

Accepts all forwarded   traffic

sudo    iptables    -P
OUTPUT DROP

Drops   all outgoing    traffic

sudo    iptables    -A
INPUT -s 8.8.8.8
-j DROP

Drops   all traffic from    a   specific    IP  address (the
example here is a Google DNS server, and you
probably don’t want to block that one...)

You can block or allow traffic based on IP address, NIC, port, network, and
more. You can set iptables to log all actions or just specific actions. You

Free download pdf