Linux Networking Cookbook - Gregory Boyce - E-Book

Linux Networking Cookbook E-Book

Gregory Boyce

0,0
29,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Over 40 recipes to help you set up and configure Linux networks

About This Book

  • Move beyond the basics of how a Linux machine works and gain a better understanding of Linux networks and their configuration
  • Impress your peers by setting up and configuring a Linux server and its various network elements like a pro
  • This is a hands-on solution guide to building, maintaining, and securing a network using Linux

Who This Book Is For

This book is targeted at Linux systems administrators who have a good basic understanding and some prior experience of how a Linux machine operates, but want to better understand how various network services function, how to set them up, and how to secure them. You should be familiar with how to set up a Linux server and how to install additional software on them.

What You Will Learn

  • Route an IPv6 netblock to your local network
  • Modify your named instance to support setting hostnames for your IPv6 addresses
  • Use SSH for remote console access
  • Configure NGINX with TLS
  • Secure XMPP with TLS
  • Leverage iptables6 to firewall your IPv6 traffic
  • Configure Samba as an Active Directory compatible directory service

In Detail

Linux can be configured as a networked workstation, a DNS server, a mail server, a firewall, a gateway router, and many other things. These are all part of administration tasks, hence network administration is one of the main tasks of Linux system administration. By knowing how to configure system network interfaces in a reliable and optimal manner, Linux administrators can deploy and configure several network services including file, web, mail, and servers while working in large enterprise environments.

Starting with a simple Linux router that passes traffic between two private networks, you will see how to enable NAT on the router in order to allow Internet access from the network, and will also enable DHCP on the network to ease configuration of client systems. You will then move on to configuring your own DNS server on your local network using bind9 and tying it into your DHCP server to allow automatic configuration of local hostnames. You will then future enable your network by setting up IPv6 via tunnel providers.

Moving on, we'll configure Samba to centralize authentication for your network services; we will also configure Linux client to leverage it for authentication, and set up a RADIUS server that uses the directory server for authentication.

Toward the end, you will have a network with a number of services running on it, and will implement monitoring in order to detect problems as they occur.

Style and approach

This book is packed with practical recipes and a task-based approach that will walk you through building, maintaining, and securing a computer network using Linux.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 199

Veröffentlichungsjahr: 2016

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Linux Networking Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
eBooks, discount offers, and more
Why Subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Configuring a Router
Introduction
Setting up the physical network
How to do it…
How it works…
Configuring IPv4
How to do it…
How it works…
Configuring IPv4 permanently
How to do it…
How it works…
Connecting two networks
How to do it…
How it works…
Enabling NAT to the outside
How to do it…
How it works…
Setting up DHCP
How to do it…
How it works…
Setting up a firewall with IPtables
How to do it…
How it works…
Setting up port forwarding
How to do it…
How it works…
Adding VLAN Tagging
How to do it...
How it works...
2. Configuring DNS
Introduction
Setting up your system to talk to a nameserver
How to do it…
How it works…
Setting up a local recursive resolver
How to do it…
How it works…
There's more…
Configuring dynamic DNS on your local network
How to do it…
How it works…
Setting up a nameserver for your public domain
How to do it...
How it works…
Setting up a slave nameserver
How to do it…
How it works…
3. Configuring IPv6
Introduction
Setting up an IPv6 tunnel via Hurricane Electric
How to do it…
How it works…
Using ip6tables to firewall your IPv6 traffic
How to do it…
How it works…
Route an IPv6 netblock to your local network
How to do it...
How it works…
4. Remote Access
Introduction
Installing OpenSSH
How to do it…
How it works…
Using OpenSSH as a basic shell client
How to do it…
How it works…
Using OpenSSH to forward defined ports
How to do it…
How it works…
Using OpenSSH as a SOCKS proxy
How to do it…
How it works…
Using OpenVPN
How to do it…
How it works...
5. Web Servers
Introduction
Configuring Apache with TLS
How to do it…
How it works…
Improving scaling with the Worker MPM
How to do it…
How it works…
Setting up PHP using an Apache module
How to do it…
How it works…
Securing your web applications using mod_security
How to do it…
How it works…
Configuring NGINX with TLS
How to do it…
How it works...
Setting up PHP in NGINX with FastCGI
How to do it…
How it works…
6. Directory Services
Introduction
Configuring Samba as an Active Directory compatible directory service
How to do it…
How it works…
Active Directory requirements
Selecting a realm and domain name
Using Samba-tool
Bind configuration
Joining a Linux box to the domain
How to do it…
How it works…
7. Setting up File Storage
Introduction
Serving files with SMB/CIFS through Samba
How to do it…
How it works…
Granting authenticated access
How to do it…
How it works…
Setting up an NFS server
How to do it…
How it works…
There's more…
Configuring WebDAV through Apache
How to do it…
How it works…
Apache modules
Directory directive
Authnz_external configuration
Directory definition
Authentication/Authorization:
Basic Apache directory configuration:
Enable WebDAV:
Granting write access
8. Setting up E-mail
Introduction
Configuring Postfix to send and receive e-mail
How to do it…
How it works…
There's more…
Setting up aliases
Setting up a smarthost
Relays without authentication
Relays with Auth
Setting up DNS records for e-mail delivery
How to do it…
How it works…
Configuring IMAP
How to do it...
How it works…
Configuring authentication for outbound e-mail
How to do it…
How it works…
Configuring Postfix to support TLS
How to do it…
How it works…
Blocking spam with Greylisting
How to do it…
How it works…
Filtering spam with SpamAssassin
How to do it…
How it works…
9. Configuring XMPP
Introduction
Installing ejabberd
How to do it...
How it works…
Configuring authentication
Configuring listening ports
C2S service
S2S service
HTTP Service
Access control
Modules
mod_muc
mod_roster
mod_announce
Configuring DNS for XMPP
How to do it…
How it works…
Configuring the Pidgin client
How to do it…
Install pidgin
Configuring your account
How it works…
10. Monitoring Your Network
Introduction
Installing Nagios
How to do it…
How it works…
Adding Nagios users
How to do it…
How it works…
Adding Nagios hosts
How to do it…
How it works…
Monitoring services
How to do it…
How it works…
Defining commands
How to do it…
How it works…
Monitoring via NRPE
How to do it…
How it works…
On the target
On the Nagios host
Monitoring via SNMP
How to do it...
How it works…
11. Mapping Your Network
Introduction
Detecting systems on your network with NMAP
How to do it…
How it works…
Detecting Systems Using Arp-Scan
How to do it…
How it works…
Scanning TCP ports
How to do it…
TCP CONNECT scan
TCP SYN scan
How it works…
Scanning UDP ports
How to do it…
How it works…
Identifying services
How to do it…
How it works…
Identifying operating systems
How to do it...
How it works…
12. Watching Your Network
Introduction
Setting up centralized logging
Input methods
Output methods
How to do it…
How it works…
Installing a Snort IDS
How to do it…
How it works…
WAN Interface
LAN interface
Dedicated interface
Managing your Snort rules
How to do it...
How it works…
Managing Snort logging
How to do it...
How it works…
Ubuntu stock
Enable fast logging
Enabling Tcpdump logging
Other logging options
Index

Linux Networking Cookbook

Linux Networking Cookbook

Copyright © 2016 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author(s), nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: June 2016

Production reference: 1220616

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78528-791-6

www.packtpub.com

Credits

Author

Gregory Boyce

Reviewer

Jean-Pol Landrain

Acquisition Editor

Sonali Vernekar

Content Development Editor

Onkar Wani

Technical Editor

Naveenkumar Jain

Copy Editor

Sneha Singh

Project Coordinator

Ulhas K

Proofreader

Safis Editing

Indexer

Hemangini Bari

Graphics

Kirk D'Penha

Production Coordinator

Shantanu N. Zagade

Cover Work

Shantanu N. Zagade

About the Author

Gregory Boyce is a technologist with nearly 20 years of experience in using and managing Linux systems. When he's not at work or spending time with his wife and two daughters, he is playing around with new technologies.

Gregory spent the last 15 years working at Akamai Technologies, where he has worked in roles ranging from Network Operations, Internal IT, Information Security, Software Testing, and Professional Services.

Currently, he heads up the Linux OS team that manages Akamai's custom Linux operating system, which runs on their massively distributed customer facing network.

I'd like to thank my wife, Vanessa, for all the support and Akamai for surrounding me with such a wonderful assortment of intelligent and interesting people.

About the Reviewer

Jean-Pol Landrain has a BSc degree in software engineering with a focus in network, real-time, and distributed computing. He gradually became a software architect with more than 18 years of experience in object-oriented programming, in particular with C++, Java/JEE, various application servers, and related technologies.

He works for Agile Partner, an IT consulting company based in Luxembourg. From early 2006 he became dedicated to the promotion, education, and application of agile development methodologies.

He has reviewed numerous books both for Manning and Packt Publishing about Docker, Git, Spring, and message-oriented middleware.

I would like to thank my fantastic wife, Marie, and my 9 year old daughter, Phoebe, for their daily patience regarding my passion for technology and the time I dedicate to it. I would also like to thank my friends and colleagues because a life dedicated to technology would be boring without the fun they bring to it.

www.PacktPub.com

eBooks, discount offers, and more

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Preface

Network administration is one of the main tasks of Linux system administration. By knowing how to configure system network interfaces in a reliable and optimal manner, Linux administrators can deploy and configure several network services including file, web, mail, and servers while working in large enterprise environments.

What this book covers

Chapter 1, Configuring a Router, starts by getting you to manually configure the IP address information on your system and then properly configure the system to bring up its interfaces automatically. From there, we'll move on to extending our system to act as a router for your own network, including DHCP for dynamically configuring client systems.

Chapter 2, Configuring DNS, will cover setting up your internal DNS server for both resolving external hostnames for you, as well as hosting DNS records for your own domain.

Chapter 3, Configuring IPv6, will provide a brief introduction of IPv6. We'll configure a tunnel to provide IPv6 connectivity, implement firewalling using iptables6, and provide IPv6 addresses to the rest of your network.

Chapter 4, Remote Access, will look at methods for remotely interacting with your new network using OpenSSH and OpenVPN.

Chapter 5, Web Servers, will set up web servers hosting PHP code, using both the Apache HTTPD server and NGINX.

Chapter 6, Directory Services, will tell us how to use Samba 4 to create an Active Directory-compatible directory service for your network.

Chapter 7, Setting up File Storage, will give us several options to explore for hosting your own file storage, including Samba, NFS, and WebDAV.

Chapter 8, Setting up E-mail, will tell us how to set up an e-mail server. We'll talk about how e-mail works as a service, set SMTP and IMAP mail services, and enable some spam filtering.

Chapter 9, Configuring XMPP, will tell us how to configure our own XMPP based IM service, configure it to communicate with other XMPP services, and configure Pidgin as a client to utilize the service.

Chapter 10, Monitoring Your Network, will tell us how to start monitoring services on our network using Nagios.

Chapter 11, Mapping Your Network, will cover mapping out the network in order to discover what is actually there.

Chapter 12, Watching Your Network, will cover watching over our network through centralized logging and managing an intrusion detection system using Snort.

What you need for this book

For this book you'll need a copy of Linux, preferably Ubuntu 14.04.

You'll also want access to three computers to install Linux on. One of the servers will need to have three network cards built into it.

For this purpose, I would strongly recommend using Virtual machines (VMs). Virtual Box will allow you to do this for free and is available on Windows, Linux, or OS X. You may find that the commercial offerings from VMWare, Parallels, or Microsoft may provide better performance, however.

Who this book is for

This book is targeted at Linux system administrators who have a good basic understanding and some prior experience of how a Linux machine operates, but want to better understand how various network services function, how to set them up, and how to secure them. You should be familiar with how to set up a Linux server and how to install additional software on them.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Modify /etc/default/isc-dhcp-server to add the interface which you should serve requests on."

A block of code is set as follows:

auto eth0 iface eth0 inet static address 10.0.0.1 netmask 255.255.255.0

Any command-line input or output is written as follows:

# ip link set dev eth0 up# ip link show eth0

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Under User Functions, click Create Regular Tunnel. You may create up to 5 tunnels."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Configuring a Router

In this chapter, we will cover:

Setting up the physical networkConfiguring IPv4Configuring IPv4 permanentlyConnecting two networksEnabling NAT to the outsideSetting up DHCPSetting up a firewall with IPtablesSetting up port forwardingAdding VLAN Tagging

Introduction

This chapter introduces some of the basic networking concepts and the methods to utilize them on Linux systems. It provides us with a good base to build upon. We're going to start with two computers connected with a single network cable and work our way from there to configure a router to connect your network to the Internet.

Routers are devices that are configured to span multiple networks and forward packets between them as needed. They also perform Network Address Translation (NAT) in order to allow your private network to share a single public IPv4 address.

Setting up the physical network

Before we start configuring the networking within Linux, we need to physically connect the systems. The simplest configuration involves connecting the two computers with a single cable, although connecting them to a switch may make more sense for additional expansion. Once physically connected, we need to confirm that they are working as expected.

How to do it…

On each Linux system, use the ip command to check for a network link as shown:

# ip link set dev eth0 up# ip link show eth02: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 00:0c:29:6e:8f:ab brd ff:ff:ff:ff:ff:ff

Some people may choose to use ethtool, mii-tool, or mii-diag to perform the same action.

Make sure to run the same command on both the systems, especially if you're connecting to a switch rather than directly connecting the two systems.

How it works…

The first command brings up the network interface card (NIC). This activates the interface and allows it to start the process to check for a network link or electrical connection between the two systems.

Next, the show command gives you a bunch of information about the link. You should see a state showing UP. If it shows DOWN, then you have a link issue of some sort. This could be a disconnected/bad cable, a bad switch, or you forgot to bring up the network interface.

Configuring IPv4

Now that we've established a link between the machines, let's put some IP addresses on the systems so that we can communicate between them. For now, let's look at manually configuring IP addresses rather than auto-configuring them via DHCP.

How to do it…

We need to manually configure the IP addresses using the ip command. Let's start with server 1:

# ip addr add dev eth0 10.0.0.1/24# ip addr list eth02: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:6e:8f:ab brd ff:ff:ff:ff:ff:ff inet 10.0.0.1/24 brd 192.168.251.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe6e:8fab/64 scope link valid_lft forever preferred_lft forever

Now we need to perform the same action on server 2, but with 10.0.0.2/24 instead of 10.0.0.1/24.

How it works…

There are a few things in play here, so it probably makes sense to go through them one at a time.

First, let's start off by looking at the IP address that we're configuring. The 10.0.0.1 and 10.0.0.2 are a part of a series of netblocks set aside for private networks by RFC1918, IP Address Allocation for Private Internets. RFC1918 sets aside three large ranges, 10.0.0.0-10.255.255.255 (10.0.0.0/8), 172.16.0.0-172.31.255.255 (172.16.0.0/12), and 192.168.0.0-192.168.255.255 (192.168.0.0/16).

For our purpose, we're configuring 10.0.0.1/24, which is an IP range that includes 10.0.0.0-10.0.0.255. This includes 256 addresses, of which 254 are usable after setting aside 10.0.0.0 as the network address and 10.0.0.255 as the broadcast address. Both our systems get one IP in that range, which should allow them to communicate between them.

Next, we use the ip command to define an address on the eth0 device using one of the IP addresses in that range. You need to make sure that each machine in that range has a different IP address in order to prevent IP address conflicts, which would make communication between the two systems impossible and communication with different systems difficult.

Some people may be accustomed to seeing the ifconfig command rather than the ip command used here. While it will certainly do the job in most cases, net-tool (and its ifconfig command) has been deprecated by most distributions since the turn of the century, in favor of iproute2 and its ip command.

Once the commands have been run on both servers, you should be able to ping them from each other. Log in to 10.0.0.1 and run the following:

# ping –c 2 –n 10.0.0.2

If everything is configured properly, you will be able to see successful ping responses at this point.

Configuring IPv4 permanently

In the previous section we configured the network interface, but this configuration is only valid while the system is up and running. A reboot will clear this configuration, unless you take steps to make sure that it is configured on each boot. This configuration will be specific to the distribution that you are running, although most distributions fall under either the Debian or Red Hat methods.

How to do it…

Let' see how it works in Debian/Ubuntu:

Add eth0 configuration to /etc/network/interfaces:
auto eth0 iface eth0 inet static address 10.0.0.1 netmask 255.255.255.0
Bring up the network interface:
# ifup eth0

Let' see how it works in Red Hat/CentOS:

Add the eth0 configuration to /etc/sysconfig/network-scripts/ifcfg-eth0:
DEVICE=eth0 BOOTPROTO=none ONBOOT=yes NETWORK=10.0.0.0 NETMASK=255.255.255.0 IPADDR=10.0.0.1 USERCTL=no
Bring up the network interface:
# ifup eth0

How it works…

Linux distributions are configured through init systems, such as Upstart, SystemD, or SysVInit. During the initialization process, the interfaces, or ifcfg-eth0 files, are used as a configuration for the networking setup scripts. These scripts then use the same ip commands, or possibly ifconfig commands to set up and bring up the network interface.

Connecting two networks

For our next step, we're going to add a second interface to server 1. In addition to 10.0.0.1/24 being configured on eth0, we're going to configure 192.168.0.1/24 on eth1. The second interface could just as easily be 10.0.1.1/24, but let's make sure that the networks are obviously different.

The systems should be configured similar to Figure 1:

How to do it…

Let's connect two networks:

Configure the network interface on eth1 on server 1:
# ip link set dev eth1 up# ip addr add dev eth1 192.168.0.1/24# ip addr list eth13: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:99:ff:c1 brd ff:ff:ff:ff:ff:ff inet 192.168.0.1/24 scope global eth1 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe99:ffc1/64 scope link valid_lft forever preferred_lft forever
Connect your third system to eth1 on server 1.Configure eth0 on server 3 with an IP address of 192.168.0.2:
# ip link set dev eth0 up# ip addr add dev eth0 192.168.0.2/24# ip addr list eth13: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:0c:29:99:ff:c2 brd ff:ff:ff:ff:ff:ff inet 192.168.0.2/24 scope global eth1 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe99:ffc1/64 scope link valid_lft forever preferred_lft forever
Add a default route on server 3:
# ip route add default via 192.168.0.1
Enable routing on server 1:
# echo net.ipv4.ip_forward=1 > /etc/sysctl.conf# sysctl -p /etc/sysctl.conf
Add a default route on server 2:
# ip route add default via 10.0.0.1

How it works…

When you