Home > Articles > Security > Network Security

Linux Firewalls: Packet Filtering

Before developing your firewall, read this sample chapter to learn the basic underlying concepts and mechanisms on which a packet-filtering firewall is based. These concepts include a general frame of reference for what network communication is, how network-based services are identified, what a packet is, and the types of messages and information sent between computers on a network.
This sample chapter is excerpted from Linux Firewalls, by Robert Ziegler and Carl Constantine.
This chapter is from the book

This chapter is from the book

A small site may have Internet access through a T1 line, a cable modem, DSL, ISDN, or often, a PPP connection to a phone line dial-up account. The computer connected directly to the Internet is the focus for security issues. Whether you have one computer or a local area network (LAN) of linked computers, the initial focus for a small site will be on the machine with the direct Internet connection. This machine will be the firewall machine.

The term firewall has a number of meanings depending on its implementation and purpose. At this opening point in the book, firewall means the Internet-connected machine. This is where your primary security policies for Internet access will be implemented. The firewall machine's external network interface card is the connection point, or gateway, to the Internet. The purpose of a firewall is to protect what's on your side of this gateway from what's on the other side.

A simple firewall setup is sometimes called a bastion firewall because it's the main line of defense against attack from the outside. All your security measures are mounted from this one defender of your realm. Consequently, everything possible is done to protect this system. It's your one and only bastion of defense.

Behind this line of defense is your single computer or your group of computers. The purpose of the firewall machine might simply be to serve as the connection point to the Internet for other machines on your LAN. You might be running local, private services behind this firewall, such as a shared printer or shared file systems. Or, you might want all your computers to have access to the World Wide Web. One of your machines might host your private financial records. You might want to have Internet access from this machine, but you won't want anyone getting in. At some point, you might want to offer your own services to the Internet. One of the machines might be hosting your own web site for the Internet. Another might function as your mail server or gateway. Your setup and goals will determine your security policies.

The firewall's purpose is to enforce the security policies you define. These policies reflect the decisions you've made about which Internet services you want to be accessible to your computers, which services you want to offer the world from your computers, which services you want to offer to specific remote users or sites, and which services and programs you want to run locally for your own private use. Security policies are all about access control and authenticated use of private or protected services, programs, and files on your computers.

Home and small business systems don't face all the security issues of a larger corporate site, but the basic ideas and steps are the same. There just aren't as many factors to consider, and security policies often are less stringent than those of a corporate site. The emphasis is on protecting your site from unwelcome access from the Internet. (A corporate site would emphasize internal security, which isn't much of an issue for a home-based site.) A packet-filtering firewall is one common approach to, and one piece of, network security and controlling access to and from the outside.

Something to keep in mind is that the Internet paradigm is based on the premise of end-to-end transparency. The networks between the two communicating machines are intended to be invisible. In fact, if a network device somewhere along the path fails, the idea is that traffic between the two endpoint machines will be silently re-routed.

Firewalls should be transparent, ideally. Nevertheless, they break the Internet paradigm by introducing a single point-of-failure within the networks between the two endpoint machines. Additionally, not all network applications use communication protocols that are easily passed through a simple packet-filtering firewall. It isn't possible to pass certain traffic through a firewall without additional application support or more sophisticated firewall technology.

Further complicating the issue has been the introduction of dynamically allocated IP addresses (DHCP and IPCP) and network address translation (NAT, or masquerading in Linux parlance). Both technologies, in their current form, were primarily developed as stopgaps to alleviate the global IP address shortage problem. As such, both technologies are widely used, even though they make some types of network traffic difficult, impossible, complex, or expensive.

A final complication has been the proliferation of multimedia and peer-to-peer protocols used in both realtime communication software and often in popular networked games. These protocols are antithetical to today's firewall technology. Today, specific software solutions must be built and deployed for each application protocol. The firewall architectures for easily and economically handling these protocols are in process in the standards committees' working groups.

It's important to keep in mind that the combination of firewalling, DHCP, and NAT introduces complexities for which practical solutions don't yet exist or aren't generally economically feasible for small sites. Home sites often have to compromise system security to some extent to use the network services the home users want. Small businesses often have to deploy multiple LANs and more complex network configurations to meet the varying security needs of the individual local hosts.

Before going into the details of developing a firewall, this chapter introduces the basic underlying concepts and mechanisms on which a packet-filtering firewall is based. These concepts include a general frame of reference for what network communication is, how network-based services are identified, what a packet is, and the types of messages and information sent between computers on a network.

The TCP/IP Reference Networking Model

In order to provide a framework for this chapter and for the rest of the book, I'm going to use a few terms before they're defined in the following sections of this chapter. The definitions are old hat to computer science and networking people, but they might be new to less technically inclined people. If this is all new to you, don't worry. Right now, I'm just trying to give you a conceptual place on which to hang the upcoming definitions so that they make more sense.

If you've had formal academic training in networking, you're familiar with the Open Systems Interconnection (OSI) reference model. The OSI reference model was developed in the late 1970s and early 1980s to provide a framework for network interconnection standards. The OSI model is a formal, careful, academic model. Textbooks and academicians use this model as their conceptual framework when talking about networking.

Networking was just taking off in the late 1970s and early 1980s, so the world functioned without a standardized model during the seven years the OSI reference model was being hammered out. As TCP/IP became the de facto standard for Internet communication between UNIX machines during this time, a second, informal model called the TCP/IP reference model developed. Rather than being an academic ideal, the TCP/IP reference model is based on what manufacturers and developers finally came to agree upon for communication across the Internet. Because the model focuses on TCP/IP from a practical, real-world, developer's point of view, the model is simpler than the OSI model. So where OSI explicitly delineates seven layers, the TCP/IP model clumps them into four layers.

This book uses the TCP/IP reference model. As with most people with a computer science background, I tend to mix and match vocabulary, but I map the OSI model onto the TCP/IP conceptual model.

Network communication is conceptualized as a layered model, with communication taking place between adjacent layers on an individual computer, and between parallel layers on communicating computers. The program you're running (for example, your web browser) is at the top, at the application layer, talking to another program on another computer (for example, a web server).

In order for your web browser client application to send a request for a web page to the web server application, it has to make library and system calls that take the information from the web browser and encapsulate it in a message suitable for transport between the two programs across the network. These messages are either transport-layer TCP segments or UDP datagrams. To construct these messages, the application layer calls the transport layer to provide this service. The transport-layer messages are sent between the web browser client and the web server. The transport layer knows how to deliver messages between a program on one computer and a program on the other end of the network. Both the OSI model and TCP/IP model call this layer the transport layer, although the OSI model breaks this layer into several different layers functionally.

In order for these transport-layer messages to be delivered between the two programs, the messages have to be sent between the two computers. To do this, the transport layer calls functions in the operating system that take the TCP or UDP transport message and encapsulate it in an Internet datagram suitable for sending to the other computer. These datagrams are IP packets. The IP Internet packets are sent between the two computers across the Internet. The Internet layer knows how to talk to the computer on the other end of the network. The TCP/IP reference model calls this layer the Internet layer. The OSI reference model vocabulary is commonly used for this layer, so it's more commonly called the network layer. They are one and the same.

Beneath the network layer is the subnet, or link, layer. Again, the packet is encapsulated in an Ethernet datagram. At the subnet level, the message is now called an Ethernet frame. From the TCP/IP point of view, the subnet layer is a clump of everything that happens to get the IP packet delivered to the next computer. This clump includes all the addressing and delivery details associated with routing the frame between the computers, from one router to the next, until the destination computer is finally found. This layer includes translating the network frame from one kind of network to another along the way. Most public networks today are Ethernet networks but along the way can be other network technologies, ATM being the most common.

This clump includes the hardware, the physical wires connecting two computers, and the signals, the voltage changes representing the individual bits of a frame, and the control information required to frame an individual byte. It includes the routing, signaling and security protocols sent between routers. It includes the mechanism to translate the IP address to the network card's hardware MAC address. And so on. None of this is visible to the firewall, usually.

The summary idea, as shown in Figure 1.1, is that the application layer represents communication between two programs. The transport layer represents how this communication is delivered between the two programs. Programs are identified by numbers called service ports. The network layer represents how this communication is carried between the two end computers. At the network layer, computers, or their individual network interface cards, are identified by unique numbers called IP addresses. The subnet layer represents how this communication is carried between each individual computer along the way. On an Ethernet network, these computer network interfaces are identified by numbers called Ethernet addresses, which you are probably familiar with as your network card's burned-in hardware MAC address.

The unique IP addresses are carried end-to-end, from the source computer to the destination computer. The unique Ethernet or MAC addresses are passed between adjacent computers in the network. Each intermediate router along the way replaces the source Ethernet address with its own, and the destination Ethernet address with that of the next hop along the route.

Figure 1.1. TCP/IP reference model.

The next sections describe the information these layers pass among themselves that ends up being used by a packet-filtering firewall.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020