- [Instructor] It's cumbersome,
to keep typing IP tables commands,
into our command line interface or CLI.
You can automate this process by creating a shell script.
We'll start by creating a file for the shell script.
Let's first change our working directory to Documents
by typing cd Documents.
Press Enter.
Type nano, space, the name of the file, which is
M-Y-F-W, standing for my firewall dot S-H.
Press Enter,
nano is one of the pre-installed Linux text editors.
Let's start by typing iptables space dash P
meaning the default firewall rule,
space INPUT for all the incoming traffic.
We'll be dropping all the incoming traffic
which is why we type DROP next.
Now the second rule is for the outgoing traffic.
The net filter chain for that is output.
We allow all the outgoing traffic
which is why we type iptables, space, dash P, OUTPUT,
space, ACCEPT.
Press Enter.
Next type iptables, space dash P space FORWARD.
The forward chain is going to be disabled.
Therefore we type FORWARD space DROP.
Now save the file by pressing Control + X together.
Type Y, press Enter to accept the current file name
which is myfw.sh.
Before running our shell script, we want to make sure
our shell script is executable.
To check this type ls space dash l.
Press Enter.
The permissions are read-write, read and read
for the user of the file, group and others.
We need to change the permissions to make a file executable.
To do this type chmod
standing for change mode, space, U-G-O plus sign X space
and then the name of the file M-Y-F-W dot S-H.
X here means executable and U-G-O plus X indicates
adding execute permission to the user, group and others.
Press Enter.
Let's do ls -l again,
to see if the file permissions have been updated.
Press Enter.
The color of the file name, myfw.sh is now green,
indicating that the file is executable.
You can also see the X is having added
to the file permissions.
R-W-X here, R-X for group, R-X for others.
Finally, we're ready to run the shell script.
Usually all you have to do is type the name
of the shell script, but in our case,
the commands in the shell script require root permissions,
which is why we're typing sudo again.
sudo space, a period, meaning the current directory,
and then forward slash and the name of the file, myfw.sh.
Press Enter to run the shell script.
We lose our remote desktop connection again
which means the shell script worked, great job!
You just automated your Netfilter configuration process.
We'll be using shell scripts from now on
for all the Netfilter configuration activities.