0721 Packet Filtering Firewalls Linux
0721 Packet Filtering Firewalls Linux
c
2017 Avinash Kak, Purdue University
Goals:
2
Computer and Network Security by Avi Kak Lecture 18
3
Computer and Network Security by Avi Kak Lecture 18
user programs, on the one hand, and the hardware (CPU, memory, disk, network interfaces, etc.), on the other.
The core part of an OS is usually referred to as its kernel. Unless you are using highly specialized hardware,
access by a user program to the hardware in a general-purpose computing platform must go through the kernel.
By the same token, any new data made available by the hardware in such general-purpose machines is likely
to be seen first by the kernel. Therefore, when a new data packet becomes available at a network interface,
the kernel is in a position to immediately determine its fate — provided the kernel has the TCP/IP capability
built into it. Just imagine how much slower it would be if a packet coming off a network interface had to be
handed over by the kernel to a user-level process for its processing. Kernel-level packet filtering is particularly
efficient in Linux because of the monolithic nature of the kernel. Linux is monolithic despite the fact that much
of its capability these days comes in the form of loadable kernel modules. In general, a kernel is monolithic
when its interaction with the hardware takes place in the same address space in which the kernel itself is being
executed. (The “loadable kernel modules” of Linux that you can see with a command like lsmod are executed
in the same address space as the kernel itself.) The opposite of a monolithic kernel is a microkernel in which
the interaction with the hardware is delegated to different user-level processes (and, thus, is subject to address-
space translations required for process execution). Recall that each process comes with its own address space
that must be translated into actual memory addresses when the process is executed. For a very fascinating
discussion on monolithic kernels vs. microkernels at the dawn of the Linux movement (in the early 90s), see
prophet of Linux, and Andrew Tanenbaum, the high-priest of operating systems in general. Even though this
discussion is now over 20 years old, much of what you’ll find there remains relevant today. ]
4
Computer and Network Security by Avi Kak Lecture 18
• The iptables tool inserts and deletes rules from the kernel’s
packet filtering table. Ordinarily, these rules created by the
iptables command would be lost on reboot. However, you can
make the rules permanent with the commands iptables-save and
iptables-restore. The other way is to put the commands re-
quired to set up your rules in an initialization script.
• Despite its many advantages over iptables, there has not yet
been a wholesale switchover from iptables to nftables — proba-
bly because there do not yet exist tools capable of automatically
5
Computer and Network Security by Avi Kak Lecture 18
• If you would like to see how you can transition from iptables to
nftables, here is a wonderful document you can read:
https//www.sans.org/reading-room/whitepapers/firewalls/nftables-second-language-35937
6
Computer and Network Security by Avi Kak Lecture 18
• The iptables command with all its options can appear at first
sight to be daunting to use. The “demo” presented in this section
illustrates how easy it is to use this command. Basically, I will
show how you can create a single-rule firewall to achieve some
pretty amazing protection for your computer.
– Demo Goal 2: How you can allow others to ssh into your
machine, but block it for every other access.
sudo iptables -L
you will see the following sort of output in the terminal window:
8
Computer and Network Security by Avi Kak Lecture 18
• To be a bit more precise, the above output tells us that there are
currently no rules in the filter table of the firewall. So, as far
as the firewall is concerned, every packet will be subject to the
policy ACCEPT. That is, every packet will get to its destination,
coming in or going out, unhindered.
• Later in this lecture, I will talk about the fact the iptables
supports four tables: filter, mangle, nat, and raw. I will
also mention later that the command ‘iptables -L’ is really a
short form for the more table-specific command ‘iptables -L -t
filter’ for examining the contents of the filter table. [So the
output shown previously tells us that there is currently nothing in only the filter table.
But note that the packets may still be subject to filtering by the rules in the other
tables. Later in this demo I will show an example in which the packets of a certain kind
will be denied entry into the Ubuntu laptop even when the filter table has nothing in
it.]
• If the output you see for the ‘iptables -L’ command is different
from what I have shown on the previous slide, please flush the
filter table (meaning get rid of the rules in the filter table) by
iptables -F
For this demo to work as I will present it, ideally you should be flushing out all of the rules (after you
have saved the rules by iptables-save using the syntax I will show later) in all of the tables by
iptables -t filter -F
iptables -t filter -X
iptables -t mangle -F
iptables -t mangle -X
iptables -t nat -F
iptables -t nat -X
9
Computer and Network Security by Avi Kak Lecture 18
iptables -t raw -F
iptables -t raw -X
The ’-X’ option is for deleting user-defined chains. I will explain later what that means.
• Now let’s go to the first goal of this demo: You don’t want
others to be able to ping your Ubuntu laptop.
where the ‘-A INPUT’ option says to append a new rule to the INPUT
chain of the filter table. The ‘-p icmp’ option specifies that
the rule is to be applied to ICMP packets only. The next option
mentions what specific subtype of the ICMP packets this rule
applies to. Finally, ‘-j DROP’ specifies the action to be taken for
such packets. [As I will explain later, the above command enters a rule in the
INPUT chain of the filter table. This rule says to drop all incoming icmp packets that
are of the type echo-request. As stated in Section 18.11 of this lecture, that is the
type of ping ICMP packets.]
• Now use the other machine to ping the Ubuntu laptop by using
either the ‘ping hostname’ syntax or the ‘ping xxx.xxx.xxx.xxx’ syntax
where the argument to ping is the IP address. You will notice
10
Computer and Network Security by Avi Kak Lecture 18
that you will not get back any echos from the Ubuntu machine.
If you had pinged the Ubuntu machine prior to the entry of the
above firewall rule, you would have received the normal echos
from that machine. [On some platforms, such as Solaris, you may have to use ‘ping -s’ to
get the same behavior as what you get with ‘ping’ in Ubuntu.]
• To get ready for our second demo goal, now delete the rule you
entered above by
sudo iptables -F
• Recall that the objective now is to allow others to ssh into our
Ubuntu laptop, but we we do not want the Ubuntu laptop to
respond to any other service request coming from other comput-
ers. I am assuming that the SSH server sshd is running on the
Ubuntu laptop. [You can verify that the SSH server is running my executing a command like “ps
ax | grep ssh” and you should see a line for the sshd process.]
11
Computer and Network Security by Avi Kak Lecture 18
where the ‘-A INPUT’ option says to append the rules to the INPUT
chain of the filter table. The ‘-p tcp’ option says the rule is
to be applied to TCP packets. The next option mentions the
destination port on the local machine for these incoming pack-
ets. Finally, the option ‘-j ACCEPT’ says to accept all such packets.
Recall that 22 is the port registered for the SSH service.
• To see that you have entered two new rules in the INPUT chain of
the filter table, execute the ‘sudo iptables -L’ command as root.
You should see the following:
• Now when you use the other laptop to ssh into the Ubuntu laptop
with its firewall set as above, you should experience no problems.
However, if the other laptop makes any other type of access (such
12
Computer and Network Security by Avi Kak Lecture 18
• To see the effect of the second rule — the REJECT rule — try
pinging the Ubuntu laptop and see what happens. The machine
that is doing the pinging will receive and display a ‘Destination
Port Unreachable’ message.
• To get ready for our third demo goal, now delete the two rules
you entered above by
sudo iptables -F
13
Computer and Network Security by Avi Kak Lecture 18
• Recall that the goal of this part of the demo is to reject all requests
for new connections coming from other hosts in the network. As
mentioned in Lecture 16, when a host wants to make a new con-
nection with your machine, it sends your machine a SYN packet.
To block all such packets, we could use a rule very similar to what
we have shown so far. But, just to add an interesting twist to the
demo, we will use the mangle table for the purpose. So go ahead
and execute the following command line as root:
sudo iptables -t mangle -A PREROUTING -p tcp -m tcp --tcp-flags SYN NONE -j DROP
The ‘-t’ option says that the new rule is meant for the mangle
table. We want the rule to be appended to the PREROUTING chain
(assuming that this chain was empty previously). You can check
that the rule is in the mangle table by executing the command
• With the above rule in place in the mangle table, use the other
laptop to try to make any sort of connection with the Ubuntu
laptop. You could, for example, try to SSH into the Ubuntu
laptop. You will not be able to do. (You will still be able the
ping the Ubuntu laptop since ping packets do not have the SYN
flag set. More accurately speaking, the rule we entered is just for the TCP protocol packets. The ping
packets belong to a different protocol — the ICMP protocol, which resides at the Network Layer, as shown in
14
Computer and Network Security by Avi Kak Lecture 18
15
Computer and Network Security by Avi Kak Lecture 18
16
Computer and Network Security by Avi Kak Lecture 18
• Each packet is subject to each of the rules in a chain and the fate
of the packet is decided by the first matching rule.
• The filter table contains at least three rule chains: INPUT for
processing all incoming packets, OUTPUT for processing all outgo-
ing packets, and FORWARD for processing all packets being routed
through the machine. The INPUT, OUTPUT, and FORWARD chains of
the filter table are also referred to as the built-in chains since
they cannot be deleted (unlike the user-defined chains we will
talk about later).
are likely to be in a Class C private network. The allowed address range for such networks is 192.168.0.0
to 192.168.255.255. On the other hand, when you are connected to the Purdue wireless network (PAL2 or
PAL3), you are in a Class A private network. The allowed address range for such a network is 10.0.0.0 to
10.255.255.255. When a packet in a private network is routed out to the internet at large, it is subject to
network address translation. The same things happens when a packet from the internet at large is routed
to your machine in a private network; it is also subject to NAT, which would be the reverse of the address
17
Computer and Network Security by Avi Kak Lecture 18
]
translation carried out for the outgoing packet.
18
Computer and Network Security by Avi Kak Lecture 18
• If the routing decision is that the packet is intended for the ma-
chine in which the packet is being processed, the packet passes
downwards in the diagram to the INPUT chain.
Incoming Packets
Outgoing Packets
Routing FORWARD
Chain
Decision
Rules
OUTPUT
INPUT Chain
Chain Rules
Rules
20
Computer and Network Security by Avi Kak Lecture 18
sent to the other interface. [If the kernel does not have forwarding enabled or
if the kernel does not know how to forward the packet, the packet is simply dropped.]
• If a packet reaches the end of a chain, then the Linux kernel looks
at what is known as the chain policy to determine the fate of
the packet. In a security-conscious system, this policy usually
tells the kernel to DROP the packet.
21
Computer and Network Security by Avi Kak Lecture 18
lsmod | grep ip
where lsmod shows you what kernel modules are currently loaded
in. On my laptop running Ubuntu Linux, this returns
iptable_raw 3328 0
ipt_REJECT 5760 0
iptable_mangle 3840 0
iptable_nat 8708 0
nf_nat 20140 1 iptable_nat
nf_conntrack_ipv4 19724 2 iptable_nat
nf_conntrack 65288 4 xt_state,iptable_nat,nf_nat,nf_conntrack_ipv4
nfnetlink 6936 3 nf_nat,nf_conntrack_ipv4,nf_conntrack
iptable_filter 3968 1
ip_tables 13924 4 iptable_raw,iptable_mangle,iptable_nat,iptable_filter
x_tables 16260 5 ipt_REJECT,xt_state,xt_tcpudp,iptable_nat,ip_tables
ipv6 273892 21
If you do not see all these modules, that does not mean that
iptables is not installed and running on your machine. Many of
the kernel modules are loaded in dynamically as they are needed
by the application programs.
22
Computer and Network Security by Avi Kak Lecture 18
sudo iptables -L
23
Computer and Network Security by Avi Kak Lecture 18
Note that these are the only four tables recognized by the ker-
nel. (Unlike user-defined chains in the tables, there are no user-
defined tables.)
• For the filter table shown on the previous slide, note the policy
shown for each built-in chain right next to the name of the chain.
As mentioned earlier, only built-in chains have policies. Policy is
what is applied to a packet if it is not trapped by any of the rules
in a chain.
24
Computer and Network Security by Avi Kak Lecture 18
#!/bin/sh
# Create a new user-defined chain for the filter table: Make sure you first
# flush the previous rules by ’iptables -t filter F’ and delete any
# previously user-defined chains by ’iptables -t filter -X’
iptables -t filter -N myfirewall.rules
# You must not block packets that correspond to TCP/IP protocol numbers 50
# (ESP) and 51 (AH) for VPN to work. (See Lecture 20 for ESP and AH.). VPN
25
Computer and Network Security by Avi Kak Lecture 18
# also needs the UDP ports 500 (for IKE), UDP port 10000 (for IPSec
# encapsulated in UDP) and TCP port 443 (for IPSec encapsulated in
# TCP). [Note that if you are behind a NAT device, make sure it does not
# change the source port on the IKE (Internet Key Exchange) packets. If
# the NAT device is a Linksys router, just enable "IPSec Passthrough":
iptables -A myfirewall.rules -p 50 -j ACCEPT
iptables -A myfirewall.rules -p 51 -j ACCEPT
iptables -A myfirewall.rules -p udp --dport 500 -j ACCEPT
iptables -A myfirewall.rules -p udp --dport 10000 -j ACCEPT
# For multicast DNS (mDNS) --- allows a network device to choose a domain
# name in the .local namespace and announce it using multicast. Used by
# many Apple products. mDNS works differently from the unicast DNS we
# discussed in Lecture 17. In mDNS, each host stores its own information
# (for example its own IP address). If your machine wants to get the IP
# address of such a host, it sends out a multicast query to the multicast
# address 224.0.0.251.
iptables -A myfirewall.rules -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
# Accept all packets that are in the states ESTABLISHED and RELATED (See
# Section 18.11 for packet states):
iptables -A myfirewall.rules -p all -m state --state ESTABLISHED,RELATED -j ACCEPT
# Drop all other incoming packets. Do not send back any ICMP messages for
# the dropped packets:
iptables -A myfirewall.rules -p all -j REJECT --reject-with icmp-host-prohibited
26
Computer and Network Security by Avi Kak Lecture 18
chmod +x myfirewall.sh
• To see the rule structure created by the above shell script, execute
the following command
iptables -L -n -v --line-numbers
where the ‘-n’ switch suppresses address lookup and display all
IP address in the dot-decimal notation and the switch ‘–line-
numbers’ displays a line number at the beginning of each line
in a rule chain. The switch ‘-v’ is for the verbose mode. This
command will generate the following display for the filter table
in your terminal window:
27
Computer and Network Security by Avi Kak Lecture 18
• In the output shown above, note that the last column, with no
heading, contains ancillary information related to a rule. It may
mention a port (as in tcp dpt:443, where dpt stands for “des-
tination port”), the state of a packet, etc.
target :
The action part of a rule. The target can be one of the following: ACCEPT, DROP,
REJECT, REDIRECT, RETURN, or the name of the chain to jump to.
DROP means to drop the packet without sending an error message to the origi-
nator of that packet. REJECT has the same effect as DROP, except that the
sender is sent an error message that depends on the argument supplied to this tar-
get. REDIRECT means to send the packet to a new destination (used with NAT).
RETURN means to return from this chain to the calling chain and to continue ex-
amining rules in the calling chain where you left off. When RETURN is encountered
in a built-in chain, the policy associated with the chain is executed.
28
Computer and Network Security by Avi Kak Lecture 18
proto :
The protocol associated with the packet to be trapped by this rule. The protocol
may be either named symbolically or specified by a number. Each standard protocol
has a number associated with it. The protocol numbers are assigned by Internet
Assigned Numbers Authority (IANA).
opt : optional
Note that when the fifth column (the proto column) mentions
a user-defined service as opposed to a protocol, then the last
column (without a title) must mention the port specifically. On
the other hand, for packets corresponding to standard services,
the system can figure out the ports from the entries in the file
/etc/services.
29
Computer and Network Security by Avi Kak Lecture 18
• Since both the built-in INPUT and the built-in FORWARD chains jump
to the user-defined myfirewall.rules chain, let’s look at the first
rule in this user-defined chain in some detail. This rule is:
num pkts bytes target prot opt in out source destination
1 327 34807 ACCEPT 0 -- lo * 0.0.0.0/0 0.0.0.0/0
• Let’s now examine the rule in line 2 for the user-defined chain
myfirewall.rules shown in the display produced by the command
‘iptables -L -n -v --line-numbers’ command:
• Let’s now examine the OUTPUT chain in the filter table. [(See the
output shown earlier in this section that was produced by the command ‘iptables
-L -n -v --line-numbers’ command.) There are no rules in this
chain. Therefore, for all outbound packets, the policy associated
with the OUTPUT chain will be used. This policy says ACCEPT,
implying that all outbound packets will be sent directly, without
further examination, to their intended destinations.
31
Computer and Network Security by Avi Kak Lecture 18
32
Computer and Network Security by Avi Kak Lecture 18
iptables -t nat -n -L
we get
• The nat table is used only for translating either the packet’s
source address field or its destination address field.
• Only the first packet in a stream of packets hits this table. After
that, the rest of the packets in the stream will have this network
address translation carried out on them automatically.
• The ‘targets’ for the nat table (meaning, the actions that are
permitted for the rules) are
DNAT
SNAT
MASQUERADE
REDIRECT
• The DNAT target is mainly used in cases where you have a single
public IP for a local network in which different machines are
being used for different servers. When a remote client wants to
make a connection with a local server using the publicly available
IP address, you’d want your firewall to rewrite the destination
IP address on those packets to the local address of the machine
where the server actually resides.
35
Computer and Network Security by Avi Kak Lecture 18
iptables -t mangle -n -L
returns
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
the DROP target. The rules in the PREROUTING chain are applied
before the operating system applies a routing decision to a packet.
37
Computer and Network Security by Avi Kak Lecture 18
iptables -t raw -L
This output shows that the raw table supports only two chains:
PREROUTING and OUTPUT.
• As mentioned earlier, the raw table is used for specifying the ex-
emptions from connection tracking that we will talk about later.
When rules are specified for the raw table, the table takes priority
over the other tables.
38
Computer and Network Security by Avi Kak Lecture 18
• For the answer, the INPUT chain of the mangle table has priority
over the chain of the same name in the filter table.
• Along the same lines, the OUTPUT chain of the mangle table
has priority over the OUTPUT chain of the filter table.
39
Computer and Network Security by Avi Kak Lecture 18
iptables -h
• Here are some other optional flags for the iptables command and
a brief statement of what is achieved by each flag:
40
Computer and Network Security by Avi Kak Lecture 18
• After the first level flags shown above that name a chain, if this
flag calls for a new rule to be specified (such as for ‘-A’ flag)
you can have additional flags that specify the state of the packet
that must be true for the rule to apply and specify the action
part of the rule. We say that these additional flags describe the
filtering specifications for each rule.
-p args
for specifying the protocol (tcp, udp,
icmp, etc) You can also specify a protocol
by number if you know the numeric protocol
values for IP.
-s args
41
Computer and Network Security by Avi Kak Lecture 18
--sport args
for specifying source port(s)
-d args
for specifying destination address(es)
--dport args
for specifying destination port(s)
(For the port specifications, you can supply
a port argument by name, as by ‘www’, as
listed in /etc/services.)
--icmp-type typename
[ for spcifying the type of ICMP packet as
described in the standards documents RFC792
and RFC 4884. The icmp type names can be
found by the comamnd
42
Computer and Network Security by Avi Kak Lecture 18
redirect (type 5)
network-redirect
host-redirect
TOS-network-redirect
TOS-host-redirect
echo-request (ping) (type 8)
router-advertisement (type 9)
router-solicitation (type 10)
time-exceeded (ttl-exceeded)(type 11)
ttl-zero-during-transit (code 0)
ttl-zero-during-reassembly (code 1)
parameter-problem (type 12)
ip-header-bad
required-option-missing
timestamp-request (type 13)
timestamp-reply (type 14)
address-mask-request (type 17)
address-mask-reply (type 18) ]
-j args
the name of the target to execute when
the rule matches; ‘j’ stands for ‘jump to’
-i args
for naming the input interface (when an
interface is not named, that means all
interfaces)
-o args
for specifying an output interface
43
Computer and Network Security by Avi Kak Lecture 18
44
Computer and Network Security by Avi Kak Lecture 18
• Many rule specification flags (such as ‘-p’, ‘-s’, ‘-d’, ‘-f’ ‘–syn’, etc.)
can have their arguments preceded by ‘!’ (that is pronounced
‘not’) to match values not equal to the ones given. This is referred
to as specification by inversion. For example, to indicate
45
Computer and Network Security by Avi Kak Lecture 18
-s ! ip_address
• For the ‘-f’ option flags, the inversion is done by placing ‘!’ before
the flag, as in
! -f
The rule containing the above can only be matched with the first
fragment of a fragmented packet.
what flags should be examined for the packet and where comp declares the flags that must be set. Both
mask and comp are comma separated lists. The declaration shown above calls for the SYN, RST, ACK,
and FIN flag to be examined and, of these, the SYN flag must be set and the rest unset. Do ’man
iptables-extensions’ and search for ’--tcp-flags mask comp’ to see this information in greater
detail. ] Note that ‘-d’, and ‘-s’ are also TCP extension flags. These
46
Computer and Network Security by Avi Kak Lecture 18
flags work only when the argument for the protocol flag ‘-p’ is
‘tcp’.
1. The most common way is to use the full name, such as localhost
or www.linuxhq.com.
4. The fourth way uses the net mask directly to specify a group
of IP addresses. What was accomplished by 199.95.207.0/24
above is now accomplished by 199.95.207.0/255.255.255.0.
Both of these imply that all 32 bits must match, implying that
only one IP address can be matched. Obviously, the opposite
of the default /32 is /0. This means all 32 address bits can be
anything. Therefore, /0 means every IP address. The same is
meant by the specifying the IP address range as 0/0 as in
48
Computer and Network Security by Avi Kak Lecture 18
49
Computer and Network Security by Avi Kak Lecture 18
50
Computer and Network Security by Avi Kak Lecture 18
51
Computer and Network Security by Avi Kak Lecture 18
or as in
iptables -A INPUT -m mac --mac-source ! 00:60:08:91:CC:B7 DROP
The second rule will drop all incoming packets unless they are
from the specific machine with the MAC address shown.
52
Computer and Network Security by Avi Kak Lecture 18
53
Computer and Network Security by Avi Kak Lecture 18
--to-destination 10.0.0.1-10.0.0.25
This will now spread the load of the service over 25 machines,
including the gateway machine if its LAN address is 10.0.0.1.
• So the basic idea in port forwarding is that you forward all the
traffic received at a given port on our firewall computer to the
designated machines in the LAN that is protected by the firewall.
55
Computer and Network Security by Avi Kak Lecture 18
• One can also use LOG as a target. So if you did not want to
drop a packet for some reason, you could go ahead and accept it
but at the same time log it to decide later if your current rule for
such packets is a good rule. Here is an example of a LOG target
in a rule for the FORWARD chain:
iptables -A FORWARD -p tcp -j LOG --log-level info
info
debug
57
Computer and Network Security by Avi Kak Lecture 18
• As I showed in Section 18.6, you can write a shell script with the
iptables commands in it for creating the different rules for your
firewall. You can load in the firewall rules simply by executing
the shell script. If this is the approach you use, make sure
you invoke ‘iptables -F’ and ‘iptables -X’ for each of the
tables before executing the script.
Subsequently, when you reboot the machine, you can restore the
firewall by using the command iptables-restore as root:
to save the firewall I created with the shell script in Section 18.6,
here is what is placed in the MyFirewall.bk file:
59
Computer and Network Security by Avi Kak Lecture 18
• Note that when a system is rebooted, the firewall rules are au-
tomatically flushed and reset — in most cases to empty tables
(implying really no firewall protection).
/etc/network/interfaces
60
Computer and Network Security by Avi Kak Lecture 18
auto eth0
iface eth0 inet dhcp
pre-up iptables-restore < /etc/iptables.rules
post-down iptables-save > /etc/iptables.rules
• Note that on Red Hat Linux and its variants, you can start and
stop iptables by
/etc/init.d/iptables start
/etc/init.d/iptables stop
/etc/init.d/iptables restart
Also on Red Hat Linux, if you are doing NAT, make sure you
turn on IP packet forwarding by setting
net.ipv4.ip_forward = 1
61
Computer and Network Security by Avi Kak Lecture 18
– Note that the names of built-in chains, INPUT, OUTPUT, and FOR-
WARD, must always be in uppercase.
– The ‘-p tcp’ and ‘-p udp’ options load into the kernel the TCP and
UDP extension modules.
– Even if the condition part of a rule is matched, if the rule does not
specify a target, the next rule will be considered.
62
Computer and Network Security by Avi Kak Lecture 18
| | | LAN addresses:
\ | / 192.168.1.0/24
\ | /
\ | /
-----------------------------------
| ROUTER |
-----------------------------------
|
|
|
| interface eth1, IP adress: 192.168.1.1
-----------------------
| |
| Gateway | loopback: localhost
| Machine | addess: 127.0.0.1
| (firewall computer) | interface: lo
| |
-----------------------
| interface eth0, IP address: 123.45.67.89
|
|
internet
63
Computer and Network Security by Avi Kak Lecture 18
We will also assume that the gateway machine has its IP address
assigned dynamically (DHCP) by some ISP. We will assume that the
gateway machine is using Linux as its OS and that iptables based
packet filtering software is installed. We want the firewall installed
in the gateway machine to allow for the following:
• It should allow for unrestricted internet access from all the ma-
chines in the LAN.
• Allow for SSH access (port 22) to the firewall machine from out-
side the LAN for external maintenance of this machine.
• Let’s say that the LAN is hosting a web server (on behalf of
the whole LAN) and that this HTTPD server is running on the
machine 192.168.1.100 of the LAN. So the firewall must use NAT
to redirect the incoming TCP port 80 requests to 192.168.1.100.
64
Computer and Network Security by Avi Kak Lecture 18
• We also want the firewall to accept the ICMP Echo requests (as
used by ping) coming from the outside.
• The firewall must log the filter statistics on the external interface
of the firewall machine.
tcp_services = "22,113"
icmp_types = "ping"
comp_httpd = "192.168.1.100"
# NAT/Redirect
modprobe ip_nat_ftp
iptables -t nat -A POSTROUTING -o $ext_if -j MASQUERADE
iptables -t nat -A PREROUTING -i $ext_if -p tcp --dport 80 \
-j DNAT --to-destination $comp_httpd
65
Computer and Network Security by Avi Kak Lecture 18
66
Computer and Network Security by Avi Kak Lecture 18
3. What are the four tables maintained by the Linux kernel for
processing incoming and outgoing packets?
6. Show how you would use the iptables command to reject all
incoming SYN packets that seek to open a new connection with
your machine?
8. If you see the string ‘icmp type 255’ at the end of a line of the
output produced by the ‘iptables -L’ command, what does
that mean?
68
Computer and Network Security by Avi Kak Lecture 18
wall know that the incoming packets all belong to the same on-
going connection?
13. What are the different packet states recognized by the connection
tracking iptables extension module state?
69