In this exercise, you will configure and test firewall rules that use the nftables back end.
Outcomes
In this exercise, you will configure and test firewall rules that use the nftables back end.
Log in to servera as the root user.
[student@workstation ~]$ssh root@servera
Nftables basic usage and configuration.
List all tables currently active.
[root@servera ~]#nft list tablestable ip filter table ip6 filter ...output omitted...
List all currently active chains.
[root@servera ~]#nft list chainstable ip filter { chain INPUT { type filter hook input priority 0; policy accept; } chain FORWARD { type filter hook forward priority 0; policy accept; } chain OUTPUT { type filter hook output priority 0; policy accept; } } table ip6 filter { chain INPUT { type filter hook input priority 0; policy accept; } chain FORWARD { type filter hook forward priority 0; policy accept; } chain OUTPUT { type filter hook output priority 0; policy accept; } } ...output omitted...
Add a firewall rule allowing inbound HTTP.
[root@servera ~]#nft insert rule ip filter INPUTtcp dport http accept
List all chains for the table ip filter in order to locate the handle for the rule just added.
[root@servera ~]#nft list table ip filter -n -atable ip filter { # handle 1 chain INPUT { # handle 1 type filter hook input priority 0; policy accept;tcp dport http accept # handle 4} ...output omitted...
Remove the rule currently allowing HTTP access using the handle.
[root@servera ~]#nft delete rule filter INPUT handle 4
Create a rule enabling access for multiple ports at the same time.
[root@servera ~]#nft insert rule ip filter INPUT \>tcp dport { ssh, http, https, 8181 } accept
Set the INPUT chain default policy to drop all traffic not specifically accepted.
[root@servera ~]#nft add chain ip filter INPUT \>{ type filter hook input priority 0\; policy drop\; }
Remove rules added during this exercise.
Set the INPUT chain default policy to accept all traffic by default.
[root@servera ~]#nft add chain ip filter INPUT \>{ type filter hook input priority 0\; policy accept\; }
Find the handle and remove the rule currently allowing access for SSH, HTTP, HTTPS, and 8181.
[root@servera ~]#nft list table ip filter -n -atable ip filter { # handle 1 chain INPUT { # handle 1 type filter hook input priority 0; policy accept; tcp dport { ssh, http, https, 8181 } accept # handle 6 } ...output omitted...[root@servera ~]#nft delete rule filter INPUT handle 6
Log off from servera.
[root@servera ~]#exitConnection to servera closed.
This concludes the guided exercise.