@@ -125,19 +125,17 @@ may also include the specific value of the layer 4 protocol (TCP, UDP, etc.).
125125For example, a firewall might be configured to filter out (not forward)
126126all 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
132131This pattern says to discard all TCP packets from port 1234 on host
133132198.51.100.14 addressed to port 80 on host 192.0.2.11. (Port 80 is the
134133well-known TCP port for HTTP.) Of course, it’s often not practical to
135134name every source host whose packets you want to filter, so the patterns
136135can include wildcards. For example,
137136
138- .. code :: c
137+ .. literalinclude :: code/fwrule2
139138
140- (*, *, 192.0.2.11, 80, TCP)
141139
142140says to filter out all packets addressed to port 80 on 192.0.2.11,
143141regardless of what source host or port sent the packet. Notice that
@@ -150,24 +148,13 @@ Linux has a firewall feature called ``ufw`` (uncomplicated firewall)
150148that can apply firewall rules on a host. We can implement the policy
151149described 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
159154Then 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
172159In the preceding discussion, the firewall forwards everything except
173160where 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
177164instructed block everything except access to port 25 (the SMTP mail port) on a
178165particular 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
200176Experience has shown that firewalls are very frequently configured
201177incorrectly, allowing unsafe access, or breaking applications that
0 commit comments