Skip to content

Commit d32c00b

Browse files
committed
move firewall rules into code directory
1 parent 434aaa4 commit d32c00b

File tree

7 files changed

+33
-32
lines changed

7 files changed

+33
-32
lines changed

code/fwrule1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(198.51.100.14, 1234, 192.0.2.11, 80, TCP)

code/fwrule2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(*, *, 192.0.2.11, 80, TCP)

code/fwrule3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(*, *, 198.51.100.9, 25)

code/fwsnip1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$ sudo ufw deny to 192.0.2.11 port 80
2+
rule added
3+
$

code/fwsnip2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$ sudo ufw status
2+
Status: active
3+
4+
To Action From
5+
-- ------ ----
6+
192.0.2.11 80 DENY Anywhere
7+
8+
$

code/fwsnip3

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
$ sudo ufw default deny incoming
2+
Default incoming policy changed to 'deny'
3+
(be sure to update your rules accordingly)
4+
$ sudo ufw allow to 198.51.100.9 port 25
5+
rule added
6+
$ sudo ufw status
7+
Status: active
8+
9+
To Action From
10+
-- ------ ----
11+
198.51.100.9 25 ALLOW Anywhere

firewall.rst

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,17 @@ may also include the specific value of the layer 4 protocol (TCP, UDP, etc.).
125125
For example, a firewall might be configured to filter out (not forward)
126126
all packets that match the following description:
127127

128-
.. code:: c
128+
.. literalinclude:: code/fwrule1
129129

130-
(198.51.100.14, 1234, 192.0.2.11, 80, TCP)
131130

132131
This pattern says to discard all TCP packets from port 1234 on host
133132
198.51.100.14 addressed to port 80 on host 192.0.2.11. (Port 80 is the
134133
well-known TCP port for HTTP.) Of course, it’s often not practical to
135134
name every source host whose packets you want to filter, so the patterns
136135
can include wildcards. For example,
137136

138-
.. code:: c
137+
.. literalinclude:: code/fwrule2
139138

140-
(*, *, 192.0.2.11, 80, TCP)
141139

142140
says to filter out all packets addressed to port 80 on 192.0.2.11,
143141
regardless of what source host or port sent the packet. Notice that
@@ -150,24 +148,13 @@ Linux has a firewall feature called ``ufw`` (uncomplicated firewall)
150148
that can apply firewall rules on a host. We can implement the policy
151149
described above with the following command:
152150

153-
.. code:: c
151+
.. literalinclude:: code/fwsnip1
154152

155-
$ sudo ufw deny to 192.0.2.11 port 80
156-
rule added
157-
$
158153

159154
Then we can check that our rule was applied correctly:
160155

161-
.. code:: c
162-
163-
$ sudo ufw status
164-
Status: active
165-
166-
To Action From
167-
-- ------ ----
168-
192.0.2.11 80 DENY Anywhere
169-
170-
$
156+
.. literalinclude:: code/fwsnip2
157+
171158

172159
In the preceding discussion, the firewall forwards everything except
173160
where specifically instructed to filter out certain kinds of packets. A
@@ -177,25 +164,14 @@ of blocking access to port 80 on host 192.0.2.11, the firewall might be
177164
instructed block everything except access to port 25 (the SMTP mail port) on a
178165
particular mail server, such as
179166

180-
.. code:: c
181167

182-
(*, *, 198.51.100.9, 25)
168+
.. literalinclude:: code/fwrule3
183169

184-
We can specify this behavior with ufw:
185170

186-
.. code::
171+
We can specify this behavior with ufw:
187172

188-
$ sudo ufw default deny incoming
189-
Default incoming policy changed to 'deny'
190-
(be sure to update your rules accordingly)
191-
$ sudo ufw allow to 198.51.100.9 port 25
192-
rule added
193-
$ sudo ufw status
194-
Status: active
173+
.. literalinclude:: code/fwsnip3
195174

196-
To Action From
197-
-- ------ ----
198-
198.51.100.9 25 ALLOW Anywhere
199175

200176
Experience has shown that firewalls are very frequently configured
201177
incorrectly, allowing unsafe access, or breaking applications that

0 commit comments

Comments
 (0)