Linux Home Networking

Grief Relief For The Home And Small Office

Peter Harrison
www.linuxhomenetworking.com
May 3, 2003

To Diana: “Turn off the PC and go to bed”

Copyright
© Peter Harrison 2002-2003, All rights reserved. ISBN 0-9729355-0-9 Unless otherwise stated, the material published within this document is copyright of the author, Peter Harrison. No part of of this document, including page design, interior design, cover design and icons may be reproduced or transmitted in any form, by any means, (electronic, photocopying, recording, or otherwise) without the prior consent of the publisher/author.

Disclaimer – The Website and Manual
While every effort will be made to ensure that the information contained within the is website and manual is accurate and up to date, the author makes no warranty, representation or undertaking whether expressed or implied, nor does it assume any legal liability, whether direct or indirect, or responsibility for the accuracy, completeness, or usefulness of any information.

Disclaimer - Other sites
Hypertext links to sites outside this website are provided as a convenience to users and should not necessarily be construed as an endorsement. Although every care is taken to provide links to suitable material from this site, the nature of the Internet prevents the author from guaranteeing the suitability or accuracy of any of the material that this site may be linked to. Consequently, the author can accept no responsibility for unsuitable or inaccurate material that may be encountered and accepts no liability whether direct or indirect for any loss or damage a person suffers because that person had directly or indirectly relied on any information stored in the hypertext links. Further, the author is not and can not be responsible for the accuracy or legitimacy of information found elsewhere on the Internet and there is therefore no guarantee or warranty that any of the sites listed will be available at any particular time. The author does not guarantee or warrant any services that might be announced - use at your own risk. The author makes no warranty, representation or undertaking whether expressed or implied nor does it assume any legal responsibility for the accuracy, completeness of usefulness of the information in the hypertext links.

Introduction During the “.com” gold rush, I decided to set up a small website dedicated to Caribbean art. The
company I used made it really easy, all I had to do was copy my files to the web server using the username and password they provided. One day at work I overheard some friends saying that they were hosting their websites from home using their DSL line. I suddenly decided to do the same and moved www.simiya.com literally “in-house”. Of course, it wasn’t as easy as they had made it seem. I generally found a majority of Linux resources on the web to be either too detailed or too vague or just inaccurate. There were many excellent articles on specific topics, but they were usually part of a general interest publication, and information on related topics on the site was sometimes hard to find. There just wasn’t a site out there for intermediate Linux home users who wanted to get their feet wet in web hosting, nor did there seem to be any similar sites targeting the poor I.T. people who are told to “get Linux working by tomorrow”. After a few months I decided that no one should have to repeat my pain and I added some technical pages to the site. Soon, www.linuxhomenetworking.com was born. This manual assumes you have a few weeks of Linux experience and understand the basics, such as file management and the use of text editors such as “vi”. This approach was taken in order to keep its focus on the intermediate user who requires a compact guide. It’s ironic to know that in the beginning I learned from the web as I just wasn’t prepared to buy too many Linux books, now I’ve created this manual because web users were constantly asking me to write one. If you like this manual, feel free to visit the site and let me know. Without your encouragement it wouldn’t have happened at all. Peter

..................................................................................................................................................................................................17 How To Tell The Groups To Which A User Belongs ........................................................................................................31 How To List Installed RPMs .........29 How to Install Source RPMs......26 Speakeasy ...........................................................................................................................................................................................................29 Using CDROMs..........................................................................16 How To Delete Users ........23 RPMs On Your Installation CDs ...............................................................................i Table Of Contents Chapter 1 ........................................................................................................................................................................24 RPMs Downloaded From Redhat...........................................................32 Some Necessary Facts About up2date ..............................................32 RedHat Up2date ......20 General Guidelines ..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................17 Chapter 2 .................................................................................................................................................... 23 Installing RPM Software ..............................................................................................................................................................................24 Downloading RPMS To Your Linux Box...........................................................................................................................................................................................................................................................................29 Using Downloaded Files ............................................................................................................................ 23 Where To Get Commonly Used RPMs....................................................................................................................................................................................................................................................................34 Chapter 4 ....................................................................................................................................................................................................................... 19 What is sudo?..............................................................................................26 RedHat.................................................................................................... 15 Who Is The Super User? ..........19 Download and Install The sudo Package .....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................20 The visudo Command .............................................................29 Newer Linux Versions ............................................................ 37 .............................................15 How To Change Passwords..............................................................................................................................................................................30 Older Linux Versions ..21 Chapter 3 ........................................................................................................................................................................ 15 Adding Linux Users ...................................................................................................20 How To Use sudo .............................................................24 How to Easily Access CD RPMs With Automount ....................20 The /etc/sudoers File ..........................................26 How To Install The RPMs ..........................24 RPMs Downloaded From Speakeasy ...........................................31 How Uninstall RPMs............................. 19 Using Sudo.......................................................................................................................................................26 Getting RPMs Using Command Line Anonymous FTP ....................................................................20 Simple Examples ..................................................................................................................................................................................................................................................................................21 Using syslog To Track All sudo Commands .........................................................15 How To Add Users..........................................................25 Getting RPMs Using Web Based FTP....................................................

..........................................................51 What’s The Range Of Addresses On My Network? ................................................................................................................................................................................................................................................................................................................................................41 Chapter 5 ..............44 Cons...............................................................................................54 What Is A NIC?.............40 Chkconfig Examples..............................................................................................................................................................................................45 Pros .............................................................39 How To Set Which Programs Run At Each runlevel ..................................................................................................................................................................................................................................................................................................................................................................54 What Is A Route? ................................................................ 37 The RedHat Boot Sequence .40 Use Chkconfig To Get A Listing Of Sendmail's Current Startup Options ................................41 Final Tips On chkconfig....................................................................................................................................................................................................................................................................... 47 What Is TCP/IP? .............................................................................................................................................................................................................................................................................................linuxhomenetworking.......49 What is ICMP?............................................................50 How Many Addresses Do I Get With My Mask? ......................................................................................................................................................................................................................................................................................................................... 43 Network Diagram ...................................40 Turn it back on again ...................................................................................................................................................................................................................................................................................................................................................................................................39 Using Virtual Terminals ..............................................................................................................com The Linux Boot Process ........49 What Do IP Addresses Look Like?..........................................................................................................................................................................................................................................................................................................................................................................................................................................................44 Pros ........................................................................................39 Halt / Shutdown The System.............................................................................................................48 What is UDP? .............................................39 Using A GUI Terminal Window .......................................46 Chapter 6 ............................51 Manual Calculation ..........................................................................................................................................................................54 What Is A Default Gateway? ..........................45 How To Migrate From An External Provider ...........................................................................................................................................................................38 Get A Basic Text Terminal Without Exiting The GUI ..................................................44 Factors To Consider Before Hosting Yourself ...............................................................45 Cons.......................................................48 What is TCP?.....................................................................................48 What is a TTL? ......................................52 What Is Duplex? .............................................................................................................................................................................39 Reboot The System ..................................................................................................................................................................................................................................43 Alternatives To Home Web Hosting ......................................................................55 ...............................................................................................................................44 Small Office Based Websites........................................................................................44 Home Based Websites.........................................................................................................................................................37 Determining The Default Boot runlevel...................................................................................................................................................................................................51 Calculation Using A Script ...........................................................................................................53 What Is A Gateway?......40 Doublecheck That Sendmail Will Not Startup.......................................................................................................................................................................................................... 43 Why Host Your Own Site?.........................................................40 Switch Off Sendmail Starting Up In Levels 3 and 5 .................................................. 47 Introduction To Networking...................50 What Is A Subnet Mask? ..................53 What Is A LAN?................................................................................................................................................................................................49 Private IP Addresses .............................................................................................................................................................................ii www.......................52 What Is A Switch?...................................................................................................................................................................52 What Is A Hub? .....................................................53 What Is A Router?...................................................................................................................................................................................50 What Is Localhost? ..........38 Get A GUI Console ....................................................................................48 What are TCP / UDP Ports?............................................................................................................................39 System Shutdown And Rebooting.....................................................................................................................

..............................................................................................................d Directory.....................................................59 What is FTP? ...................59 Anonymous FTP .. 63 Troubleshooting Linux With Syslog....................................................................... 71 How To Configure Your NIC's IP Address ........................................................................................................................................................................................................68 The /etc/logrotate...................60 Search For All Instances Of A Word ...55 What Is ARP? .......................................................................71 Determining Your IP Address...............................................................................66 Syslog Configuration and Cisco Network Devices................................................................................................................................................ 71 Linux Networking .............56 What Is DHCP? ....69 Activating logrotate .......................................................74 Some Important Files Created By adsl-setup .......................................67 Sample contents of /etc/logrotate..........77 Simple Troubleshooting ........................................................................................Table Of Contents iii What Is A MAC Address? ........................................65 Configuring the Linux Client ................................................................................................................................................................................conf .................................60 Chapter 7 ..............................................................................................55 What Is A Firewall?........................................................................................67 Logrotate .........................................................................56 What Is NAT? ..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................60 Finding General Information On A Command ..............................................................................................72 network-scripts File Formats ...........................68 The /etc/logrotate..............................56 What Is Port Forwarding With NAT? ..................................................................57 What Is DNS?.........................................................................69 The /etc/logrotate..................73 IP Address Assignment For A Direct DSL Connection......................................................................................................................................................82 Your NIC's /etc/hosts File Format..........................59 Regular FTP...conf File .........................................................................................................67 Syslog and Firewalls......................................................78 How To Change Your Default Gateway ........................................................................................................................................d/apache File (For Apache) ............................................................................65 Logging Syslog Messages To A Remote Linux Server ...........................................................................................................................................................................................82 .................................................................................................................................................................................................................................................................................................................57 How Can I Check The IP Address For A Domain?....................................................................................................................................................................81 Configuring Your /etc/hosts File.................................................................................................................................73 Multiple IP Addresses On A Single NIC ......65 Configuring the Linux Syslog Server.........................................................................................................................................................................................................................................59 Where is Linux Help? ..................................................................................................................................................................................59 Static or Dynamic DNS? .................................................................................................................................................................................................................................................................................................................................................................................58 How Do I Get My Own DNS Domain Name? ...................................................................................... 63 Syslog ................................d/samba File (for SAMBA) ..........................................................................................................................................................................................................................................................................................................................................................................67 The /etc/logrotate..................................................................................................................................................................................................................................71 Changing Your IP Address .................................................................................................................................................................................d/syslog File (For General System Logging)...............................................................................................................................................................................................................................69 Chapter 8 ...........................................................................................................68 The /etc/logrotate.............................80 How To Convert Your Linux Server Into A Router ............63 Syslog Facilities..................................................64 Activating Changes To The syslog Configuration File...............................................................................................................................................................79 How To Delete A Route ..................65 How To View New Log Entries As They Happen.63 About syslog ..................................................................................80 How To View Your Current Routing Table ...........79 How Configure Two Gateways .............................................................................................................................

.........................................................................................................................................................................................105 PCI Cards – Installed Using RPMs ...................................................................................................................104 Simulate a Reboot ..........................................91 Viewing Packet Flow With TCPdump .....................................................................................................................................................................................................................................................................................................101 Configure The New wlan0 Interface Driver (PCI Cards) ............................................................97 The Linksys WMP11 NIC and Linux ...............................................................112 Packet Processing In iptables .................................................................................................................................107 De-activating Encryption ...........................105 PCI Cards – Installed Using TAR Files.............................105 PCMCIA Cards ...............................104 Select the Wireless mode and SSID ......................................... 85 Simple Network Troubleshooting ...........................................................................................................................................................87 Possible Traceroute Messages...............................................................................................................................................................................................................................................................................................................................................101 Download And Install The Linux-WLAN TAR File ..................................................................................................................................................................................................117 Descriptions Of The Most Commonly Used Targets ................................................................98 Linux-WLAN Preparation ....................................... 111 Linux Firewalls Using iptables.......104 Configure The New wlan0 Interface......................................................................................................................................................................112 How To Get iptables Started ..115 Packet Processing For Data Sent By The Firewall ...................................................................... 97 Wireless Linux Compatible NICs ......93 Chapter 10...............................................................................................................................................................................................................................................................................................................................................................................................................................112 Processing For Packets Routed By The Firewall..117 ................................................................................105 Check For Interrupt Conflicts..99 PCMCIA Type Card Specific Information .....................................................112 Download And Install The Iptables Package ............................................................105 Linux-WLAN Encryption For Security ..............................................................................................................85 How To Use "Ping" To Test Network Connectivity .......com Chapter 9 .................114 Packet Processing For Data Received By The Firewall.............................................................................................................................7 Card .........................................................100 Determining The Kernel Version.......................................................................................................................109 Chapter 11....................98 The WMP 11 Version 2........................... 97 Linux Wireless Networking............................90 Possible Reasons For Failed Traceroutes ........89 Ping & Traceroute Troubleshooting Example ..................................................................................................................... 85 How To See MAC Addresses .......Using RPMs ....................................................................iv www............................................................................................................................................................................................................................................................................................. 111 What Is iptables?.....................................................................................................101 Install the Kernel Source Files .............................7 WMP 11 Card..........................................................................................................................98 Pre Version 2..............................................................linuxhomenetworking..............................................92 Useful TCPdump Expressions ...........................................................................................................................................................................................................................................................99 Installing The Linux-WLAN Drivers ............100 Linux-WLAN Installation – Using TAR files ............................................99 Linux-WLAN Installation ............................................................................................88 Always Get A Bidirectional Traceroute ............................................................................................................................................99 Determining The Kernel Type ...........................................................................................................................92 Possible TCPdump Messages .........................................................................................102 Configure The New wlan0 Interface Driver (PCMCIA Cards) ............................................................................................................................................................................................................................................................................................................................104 Disable Your Existing Ethernet NIC ............................116 Targets And Jumps.............108 Troubleshooting Your Wireless LAN ............................................................99 Determining The OS Version ....................................................................................................................................................................................................................................................................................................................................................103 Post Installation Steps........86 Using "traceroute" To Test Connectivity.............................................................................................................................................

............................................................................................................................................. 141 Linux FTP Server Setup.............................................................................................................................................................................................................................................................................................................................................146 What Is Anonymous FTP?.................................................139 Chapter 13...............................................................................................................................................................................................................................................131 Chapter 12......................................................... TFTP and XINETD .....121 Common Match Extensions Criteria...................................................................144 Solutions........................................................................144 How To Download And Install The VSFTP Package......................138 Cisco CSS 111000 "Arrowpoints"..........................135 TFTP .....................................................................................................................................124 Basic Initialization...................119 General Iptables Match Criteria ...................................121 Using User Defined Chains .....................128 Static NAT .............................................................................................................................137 Cisco Router .................................................145 How To Get VSFTP Started ......................................................................................................................138 Cisco Local Director...............................................................................................................................................................conf File.......Table Of Contents v Important Iptables Command Switch Operations...........................................142 FTP Data Channel .......................................................................................................................................................................127 Masquerading (Many to One NAT) .............................................................................................................................................................................................................124 Allowing DNS Access To Your Firewall ...............143 Solutions............................................................146 Testing To See If VSFTP Is Running.......................................................................................125 Allowing WWW And SSH Access To Your Firewall.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................141 FTP Control Channel ......148 Using SCP As Secure Alternative To FTP .....................................................................................................................................................................................................................................148 FTP Greeting Banner ................................................................................................126 Allow Your Home Network To Access The Firewall ..............................................................................134 Setting Up A Telnet Server.........................................................................................................148 Anonymous Upload ...................................................................................................................................................................................................................................................................................................135 What is TFTP?...........................................................................................................................................................................................................................................148 Example #1: ...........................................147 The /etc/vsftpd...................................................................143 Problems With FTP And Firewalls..............................148 The /etc/vsftpd........................................143 Server Protected By A Firewall Problem ............................................................................................................................................................................................................................................................................................................................................................................... 133 Telnet ..............................................................................................................149 ...................................................ftpusers File ....................135 Setting up a TFTP server.....................TCP Port 20.................................142 Active FTP...............................................................147 FTP Security Issues ....... 141 FTP Overview.......................................................................................................................................................................TCP Port 21 .........................................................................................................................................................................................................................................................................................................142 Passive FTP.................................................................137 Cisco PIX firewall .........................................................................................................................................................................................................................126 Allowing Your Firewall To Access The Internet.........136 Configuring Cisco Devices for TFTP..............................137 Cisco Switch Running CATOS......... 133 Telnet...................................................................123 Sample iptables Scripts......................................................................................................................119 Common TCP and UDP Match Criteria ...........................................................................................................................................................................................................................................................................................................................................................................................................................138 Using TFTP To Restore Your Router Configuration .................................................................120 Common ICMP (Ping) Match Criteria .............................................................................127 Port Forwarding Type NAT (DHCP DSL) ......................................................................................................................................................................................130 Logging & Troubleshooting........................................................................................143 Client Protected By A Firewall Problem..134 What is Telnet? ......

......................................................................................160 How To Get SAMBA Started ...167 Make Your PC Clients Aware Of Your Samba PDC.................................................................................................................................................................................162 The Windows XP Built In Firewall..............................................................................................................................170 Domain Groups And Samba .....................................................................................163 Adduser’s Command Switches ......................153 Testing To See If SSH Is Running .....156 Using SCP as a more secure replacement for FTP..................................................................................................157 Copying Files To The Remote Linux Box......................163 Create An Administrator Domain Password ..............................150 Chapter 14.....................................................................167 Windows 95/98/ME ......154 The etc/ssh/sshd_config File.......................................................................................................................... 153 Using Secure Shell As A Replacement For Telnet ..............................................164 Make The Administrator One Of The Samba Admin Users...............................155 User “root” Logs In To smallfry As User “peter” .........................................linuxhomenetworking.......................................... 159 Windows..............................................161 Zone Alarm...............................................164 Create A Samba PDC ..........................169 Map A Drive Share................................................................................................................................................................................................................155 User “root” Logs In To smallfry As User “root”.171 Chapter 16..........................................................................................................................................................................................................................................................160 Configuring SWAT ...................................................169 Map The Linux Users To An smbpassword .................................................................................................................................................................................................................................................................................................................................................169 Add The Users In Linux...............................................169 Mapping Using “My Computer” .......................................................................................171 Delete The Users In Linux .....................................................................................................................................................154 Using SSH To Login To A Remote Machine ............................................................................................................................................................................................................................168 How To Add Users To Your Samba Domain ..162 Create The Administrator User Under Linux...................................... 173 ..................................................................................................................................155 What You Should Expect To See When You Log In ...........................................................................................................................157 Chapter 15......................................................................................................................................................169 Mapping From The Command Line.........................................................................................................................................................................................................................................162 How To Create A Samba PDC Administrator User ..............................164 Create Your PC Machine Trusts............................................................................................................................................................................. 173 Sharing Resources With Samba........................ 159 Download and Install Packages.............................................................................................................................................................................................................................................................................161 Samba and PC Firewall Software.....................................................171 Delete The Users Using smbpasswd..........................................................166 Dynamic Creation Of Machine Trust Accounts..................................................168 Windows 2000 ............................................................................................................155 Using port 435 .............com FTP Users With Only Read Access To A Shared Directory .............162 Create The Administrator’s User Group and Directories .......................................................................................................................................................................................................................................155 Deactivating Telnet once SSH is installed ....................................................164 How to Configure a Samba PDC ...................................................................................................................168 Windows XP...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................170 How To Delete Users From Your Samba Domain ............................................................................................................157 Copying Files To The Local Linux Box ............................................................149 Sample Login Session To Test Funtionality................................vi www....................... 153 Secure Remote Logins And File Copying........... Linux And Samba .....................................................................................................................................................................................................................166 Manual Creation Of Machine Trust Accounts (NT Only)......................................................................................................................155 Using default port 22 .................167 Windows NT...........................................................................................................................................................................................................................

...............................................................193 DHCP Considerations For DNS...........................................................conf File.........182 When To Use Dynamic DNS.......................................199 Sign Up With A DDNS Provider ......................................................................................................................... MX................177 Windows 98/ME ...............................................................................................................................................173 Adding The Printer To Linux...........................................200 ez-ipupdate And NAT ...........................................179 Not Prompted For Password Method..174 Configure The Printer Driver On The Workstations .................................................................................................................................................................................193 How To Migrate Your Website In-House...........................................................................182 How To Get BIND Started ..............183 Configuring A Caching Nameserver......................................197 What Is Dynamic DNS? ..............................................................................................................189 Loading Your New Configuration Files .............................................................176 Configure The Share In SWAT .......178 Test Your Windows Client Configuration...................................................................................................................................181 When To Use A DNS Caching Nameserver ......................................................................................................199 Installing And Using ez-ipupdate .........................................................200 ........................179 Using The smbmount Command Method..............................................................199 Update Your DNS Registration ......................................................................................................................................................................................................................................................................................................................................................................................................................175 Creating Group Shares in SAMBA ..............................................181 What Is BIND?.....conf File.........................................................................................................................................................................................................................................................................................................188 Sample Reverse Zone File .......... 197 Dynamic DNS..................................Table Of Contents vii Adding A Printer To A Samba PDC ......................................................................................................................................................................................182 The /etc/resolv.....................................................................177 Windows XP...........................................................................184 Configuring The Zone Files ............................................................176 Create The Directory And User Group ...................................................................................................182 When To Use A Regular DNS Server.........................................................................................................................177 Windows 2000 ...............178 Create A ZIP Drive Mount Point On Your Samba Server ...............................................................................179 Chapter 17.....................................................................................192 Make Sure Your /etc/hosts File Is Correctly Updated....................................................................................................................................................................................................................................................................................................................177 Windows Setup .......................................................................................................177 Windows Drive Sharing With Your SAMBA Server ...................................................198 Dynamic DNS Prerequisites.................................................................................................................. 197 What Is DNS?.........................................................................................................................................................................................................................................................................................................................................................................................................182 How To Download and Install The BIND Packages .................................................................................................................................................... 181 Configuring DNS........................................................................................conf ...................................198 Dynamic DNS And NAT Router/Firewalls ............................................................................................................................................................................................................................................................................................................................................189 What You Need To Know About NAT And DNS .......................................................................................................................178 Prompted For Password Method ...192 Configure Your Firewall.......................................194 Chapter 18.173 Make Samba Aware Of The Printer ......................................................................................................................................................................................................................................................................................................................................................................199 The /etc/ez-ipupdate...................................................................................................................................... 181 What Is DNS?......................................................................................................................................... A And CNAME Records .........................................................184 Configuring A Regular Nameserver ................187 Sample Forward Zone File ........................................................185 NS.............192 Fix Your Domain Registration ............................................................................184 Configuring named.....................................................................................................176 Map The Directory Using “My Computer”............................................................................................................................................................................................................................................................................................................................................................................................................................185 The SOA Record...............................................................

......................................................................................................................................................................................................................................215 Download and Install The MRTG Packages .208 Using Data Compression On Web Pages ...........................221 Configuring DNS ..................................212 Incompatible /etc/httpd/conf/http..........................................................................................................................................212 Chapter 20...........................................206 Configuration – Multiple Sites And IP Addresses...................................................................................................0 and Indexmaker................................203 How To Get Apache Started ............................................................................................................................................................................................................................................................................213 What is SNMP? ................................224 Why Sendmail Only Listens On The Loopback Interface By Default ..............218 Make Webalizer run in Quiet Mode ............................................216 RedHat Version 8....................................conf files ..............204 Named Virtual Hosting ....................................................221 An Overview Of How Sendmail Works ..............................................................................................205 Disabling SSL – (Not Recommended) ........linuxhomenetworking.................................................................................................................................206 A Note On Virtual Hosting And DNS ...............................................................................210 File Permissions And Apache ....218 How To View Your Webalizer Statistics ...............................................................................................................................................................................................................218 Webalizer .......................................................................................................................224 The /var/log/maillog File ...............................................................................................................................................................................................................................................200 The /etc/ddclient......0....................................... 213 Monitoring Server Performance .............................................................................................................................. 213 SNMP...............................................................conf File........................................................................................................................................................217 Using MRTG To Monitor Other Subsystems ..........................................................................................................................................................202 Chapter 19.......................................................................................................................................................................................................................................................................................................................................................... 203 Download and Install The Apache Package ........................................................................................................................................................................................................................223 Errors With The m4 Command ...................................................................................218 Chapter 21................ 203 The Apache Web Server ..............................................................................................................................................................................................................................................210 How To Protect Web Page Directories With Passwords .....................222 Installing And Starting Sendmail..................223 Errors With The Newaliases Command...................................................................................................................206 Use Wild Cards Sparingly.......................................................................204 Configuring DNS For Apache...............................209 Apache Running On A Server Behind A Firewall..................................................................................................................................................................215 Configuring MRTG ................208 Compression Configuration Example .................................................................................222 Restart Sendmail After Editing Your Configuration Files ........................................................................................213 SNMP on a Linux Server ................................................................................................................................................................................................................................................................215 What is MRTG?..........................................................................................224 ................................................................................213 MRTG .........................201 Testing Your Dynamic DNS ............................................................223 Errors When Restarting sendmail.....................................................................................205 A Note On Virtual Hosting And SSL................................................................210 Issues When Upgrading To Apache 2...............................................................................................................................................................................................................218 The Webalizer Configuration File .................................................205 IP Based Virtual Hosting ..........................................................................................218 What Is Webalizer?..............................................................................................................................................................................................224 The /etc/mail/sendmail..........................mc File ............................... 221 Configuring Linux Mail Servers ..................................204 General Configuration Steps ...........................................................viii www....................................................................................................................................................................................com Installing And Using DDclient...............................................................................................................................202 Testing Port Forwarding......................... 221 Configuring Sendmail ...........................................................................................................................................................................................................................................................................................................

..................................................................................241 How to get DHCP started ....................................................................................................................230 Which User Should Really Receive The Mail? ...............234 Other Masquerading Notes ..................................................................................................................................................................248 Configuring Cisco Devices To Use An NTP Server................236 How To Configure Your Windows Mail Programs.................0..........................226 Now Make Sure Sendmail Is Listening On All Interfaces.............................................................225 Regenerate The sendmail........................................................................................................239 The /etc/dhcp.............................................. 239 Download and Install The DHCP Package ...................................................................................230 The /etc/mail/virtusertable file ...............................................................................243 Chapter 23..................................................................................... .........................................................................................................................................................................................231 Simple Mailing Lists Using Aliases...................................................251 Accessing the PIX command line .........................................234 A Simple PERL Script To Help Stop SPAM............................235 Installing Your POP Mail Server ....242 Permanent Solution ..................................................................................................................................................................................................................................... 251 Configuring Cisco PIX Firewalls........................226 The /etc/hosts File.......................................................................252 ...................................................................................................conf File............................................................................................................................................................................................233 Testing Masquerading...........................cf File........................................................231 The /etc/aliases File....................249 Chapter 24.................................................................................................mc File.............247 Determining If NTP Is Synchronized Properly .........mc To Make Sendmail Listen On NICs Too.237 Chapter 22....................................................................252 Via The Console Port ..........................................................233 Configuring masquerading............................................................................ 239 Configuring The DHCP Server .....................................................240 Upgrading Your DHCP Server ..... 251 Network Address Translation (NAT) ......................................................................................................conf File .................................................................................................................................................................................................................242 Temporary solution ........................................................ 245 What is NTP?..........229 The /etc/mail/local-host-names File..............252 Via Telnet ..........................................................................................................................................................................................................................................................................................227 Symptoms Of A Bad /etc/hosts File.......................................................................................................................................................................................................................................................237 How to handle overlapping email addresses...................................................................................................................................................................................................................................243 Error Found When Upgrading From Redhat 7...........................................................................................233 Sendmail Masquerading Explained..............................................................................................................................................................................................232 An Important Note About The /etc/aliases File .....................................226 A General Guide To Using The sendmail.............................................................................................245 Download and Install The NTP Package......................248 Cisco IOS ....246 The /etc/ntp..........236 Configuring Your POP Mail Server..................................................................................................................................................227 The /etc/mail/relay-domains File..........228 The /etc/mail/access File ..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................248 CAT OS .........................................................................................242 Modify Your Routes for DHCP on Linux Server ...............................................................................................................................249 Firewalls and NTP................................................................................Table Of Contents ix Edit /etc/mail/sendmail.........................................................................................................................................................................................................................................................................................................................................246 How To Get NTP Started ............................................................................... 245 The NTP Server ........243 Configuring Linux clients to use DHCP ..............................................................................................................................................................................................................................................................................................................3 To 8...........................................................................................................................225 Restart sendmail to load the new configuration ......235 Configuring Your POP Mail Server..........................................................

...............x www..........................................................................................................................................................................267 Appendix I ..........................273 VPN Security And Firewalls......................................................................258 Via The Console Port .........................................................................277 ...............................................270 Transport mode AH packet format ....................................................273 Transforms ...........................................................................................272 Shared keys ........274 Running Linux Without A Monitor .............................................271 Tunnel mode AH packet format .............................................................................................................................266 How To Verify That NAT Is Working Correctly .....................................258 Introduction to accessing the router command line .........................258 Sample Configurations...........................................................................................DHCP................................................................................................Static IP ........................................................................linuxhomenetworking....................................................................................................................................................................................................................................................................................................................................................................................Static IPs ....................272 Public key cryptography using RSA encryption.............................270 Tunnel mode VPNs...............................................................................................................................................................................................................................................................................275 Configuration Steps ...........................................................................260 DSL Router With Built-In Modem ...............................................................................................................................271 IKE authentication methods....................................................................................................................................................................................................................................................................................................................................................254 Dynamic DNS Port Forwarding Entries .......................................................................................269 Authentication .......271 Authentication methods.............................................................................................................................262 DSL Router With External Modem .............................................................................................................. 269 Miscellaneous Topics.............................................................266 Commonly Used TCP And UDP Ports...................255 Incoming Connections NAT Configuration ............................................... 257 Configuring Cisco DSL Routers ................................................................253 NAT Configuration .....................................................................................................273 IKE and ISAKMP..270 IPSec ................................................................................................................................275 Preparing To Go “Headless” ...........................................................269 Encryption ..........................................................................................................................273 Types Of Dial Up VPN Authentication ............................................270 Encapsulating Security Protocol (ESP) .....................................................................................270 Transport mode VPNs..........................258 Via Telnet .......................................................................................270 Authentication Header (AH)......................................................................................275 Make Your Linux Box Emulate A VT100 Dumb Terminal...............................................................................................................................................................................................................255 Chapter 25......................................................................................................................254 Sample PIX configuration: DSL .......................................................................................................................................................Static IP ..............................com Sample PIX Configuration: DSL ...............................................................271 Internet Key Exchange (IKE).................................................................255 Outgoing Connections NAT Configuration ....................................................................................................................................... 269 VPN Terminologies.............................................................................................................................................................................................................................................253 Configuring PPPoE........................................................................277 Configuration Steps ........................................................................................... 257 An Introduction to Network Address Translation (NAT) .......................................................................264 Other NAT Topics ....................................................................................................................................................................DHCP...............................................................................................................................................................................................271 Encryption methods ....................................................................................................................................................................................................254 How To Get Static IPs For DSL Cheaply ................................................273 VPN User Authentication Methods For Temporary Connections .................................................................................................................271 Tunnel mode AH / ESP packet format..................260 DSL Router With Built-In Modem ...................................................273 Shared keys .........................................................................................................................................................................................................272 IKE's role in creating Security Associations ..................................................................................................................................................................................................................................................................................................................266 How To Troubleshoot NAT .....................................................................................270 Transport mode AH / ESP packet format .......

290 Contents Of The UDP Header ..........304 IPtables NTP Server............................................................................................................................326 ICMP Codes...................................................................................reject File..................................................................................................................................................................................................287 What Can I Do When I Run Out Of Disk Space?................................................................................................................... 333 Wireless Linux ....................................................................................................................................................................288 TCP/IP Packet Format .................................................................................................................................................................................................................................................. 333 Bibliography .................................................................................297 The mail-filter..........................................................................322 Sendmail Sample /etc/mail/local-host-names File .......................................................................................................................................................................................................................288 The Seven OSI Layers ....................................................................................................... Scripts and Configurations ................................................................285 "/".................................................................................................323 Sendmail Sample /etc/mail/sendmail.........................................................327 Cisco PIX Firewall ...................................................................329 Cisco PIX Firewall .............289 Contents Of The TCP Header..............................................294 Apache File Permissions Script ...........................................................................................................................................................283 Disk Partitioning Explained...............................................................................................................................................298 The mail-filter..........................................................................280 Cisco PIX Filewalls ......................................................................................282 The Sample Cisco syslog.......... Also Known As "root".......................................................287 The OSI Networking Model .....................................................................320 Sendmail Sample /etc/mail/access File ........................................................com ...................................................................................................................................334 Cisco PIX Firewall Configuration Examples.....................................................................................322 Sendmail Sample /etc/aliases File .......................................................................................................................................................................................................................Table Of Contents xi Syslog Configuration and Cisco Devices .................................................................320 Reverse Zone File For A Home Network Using NAT ...................................................................................................................334 Cisco Router Configuration Examples..........................................................................................................................................................................................................................................................accept File...................................................................................................................................................................................conf File ........280 Cisco Local Director....................................................330 Appendix III.........................................................................................................................................................................................................................................................................305 IPtables Complex script .. 293 Codes.......................................mc File .........................................................................................................................................................DHCP DSL Configuration........................................com ...........................319 DNS Zone File For my-other-site................................................................................284 How Linux Links Filesystems And Partitions .............................................................................................................................284 What Is A Partition? .........................................................................................................285 swap...............................................................................................298 The mail-filter Script.............305 DNS Zone File For my-site...........................................................................................................................................................................................................................................................................................................285 /boot ......................................284 What Is A Filesystem?..319 Forward Zone File For A Home Network Using NAT ..............................................296 Sendmail SPAM Filter Script ..298 IPtables FTP Client....................289 Contents Of The IP Header ..................285 Some Recommended Partition Sizes .....282 Cisco CSS11000 (Arrowpoints) ........................................................................................................ 293 Subnet Calculator Script .....................................................................................324 Sendmail Sample /etc/mail/virtusertable File................................................................................................................................................................................................................................................................................................................................................................................................285 Recommended Sizes For Disk Partitions............284 What Partitions Are Mandatory?..............................................................303 IPtables FTP Server .............................334 ............................................................................................Static DSL Configuration..........................................................................................................................................................................................286 How Much Space Do I Have On My Partitions?......................280 Cisco Routers ....................................280 Catalyst CAT Switches running CATOS..........................................................................................................................................................................................................................................................................................................................................290 Appendix II.................................

...........................................................................................................................................................................337 Static DNS..................................................................................................................................................................335 SSH Servers and SSH Clients..........................335 General Home Networking Resource Pages...........................................................................................................................................................................................................335 The Windows SCP client called WinSCP.............................................................338 General Linux Resource Pages ........com Netfilter ..........................................................................................................339 Network Monitoring..........337 POP Mail Server ............................................338 Disk Partitioning ..................................................................................................................................................................................336 FTP Server and FTP Clients ......................linuxhomenetworking....................................................339 ...........................................................338 Samba ...............336 Sendmail Mail Configuration ..............................339 My Other Sites.....................................................................................................................................336 Apache Web Server Software.............................................336 DHCP Server ............337 NTP Server .............................................................................................................................Linux as a Windows File Server .........iptables Configuration .................................................................................................................................................................................................................................................................................................................Hosting Your Website at Home ......................................................................336 Dynamic DNS .....xii www....................................................................................................................................................................................................................................................................

Table Of Contents xiii .

linuxhomenetworking.xiv www.com .

Who Is The Super User? The super user with unrestricted access to all system resources and files is the user named "root".15 Chapter 1 Adding Linux Users =========================================== In This Chapter Chapter 1 Adding Linux Users Who Is The Super User? How To Add Users How To Change Passwords How To Delete Users How To Tell The Groups To Which A User Belongs © Peter Harrison. You will need to log in as user root to add new users to your Linux box How To Add Users Adding users takes some planning. I have included some simple examples to provide a foundation for future chapters. www.com =========================================== One of the most important activities in administering a Linux box is the addition of users. In this example there are three groups "parents". . "children" and "soho".linuxhomenetworking. read through the steps below before starting: • Arrange your list of users into groups by function. A more detailed description of the process is beyond the focus of this book. You may use the command “man useradd” to get the help pages on adding users with the useradd command or the “man usermod” to become more familiar with modifying users with the usermod command.

com Parents Paul Jane • Children Alice Derek Soho Accounts Sales Add the Linux groups to your server: [root@bigboy tmp]# groupadd parents [root@bigboy tmp]# groupadd children [root@bigboy tmp]# groupadd soho • Add the Linux users. New password: Retype new password: .16 www.linuxhomenetworking. assign them to their respective groups [root@bigboy [root@bigboy [root@bigboy [root@bigboy [root@bigboy [root@bigboy tmp]# tmp]# tmp]# tmp]# tmp]# tmp]# useradd useradd useradd useradd useradd useradd -g -g -g -g -g -g parents parents children children soho soho paul jane derek alice accounts sales If you don't specify the group with the "-g". [root@bigboy tmp]# ll /home drwxr-xr-x 2 root root drwx-----2 accounts soho drwx-----2 alice children drwx-----2 derek children drwx-----2 jane parents drwx-----2 paul parents drwx-----2 sales soho [root@bigboy tmp]# ll /home 12288 1024 1024 1024 1024 1024 1024 Jul Jul Jul Jul Jul Jul Jul 24 24 24 24 24 24 24 20:04 20:33 20:33 20:33 20:33 20:33 20:33 lost+found accounts alice derek jane paul sales How To Change Passwords You’ll need to create passwords for each account. they will be prompted for their new permanent password. RedHat Linux will create a group with the same name as the user you just created. When each new user first logs in. • Each user's personal directory will be placed in the /home directory. • User "root" changing the password for user "paul" [root@bigboy root]# passwd paul Changing password for user paul. The directory name will be the same as their user name. This is done with the "passwd" command. You will be prompted once for your old password and twice for the new one.

[paul@bigboy paul]$ How To Delete Users • The userdel command is used. [paul@bigboy paul]$ passwd Changing password for paul Old password: your current password Enter the new password (minimum of 5. New password: your new password Re-enter new password: your new password Password changed. [root@bigboy root]# • Users may wish to change their passwords at a future date. Here is how unprivileged user "paul" would change his own password. The "-r" flag removes all the contents of the user's home directory [root@bigboy tmp]# userdel -r paul How To Tell The Groups To Which A User Belongs • Use the "groups" command with the username as the argument [root@bigboy root]# groups paul paul : parents [root@bigboy root]# . maximum of 8 characters) Please use a combination of upper and lower case letters and numbers.Chapter 1 : Adding Linux Users 17 passwd: all authentication tokens updated successfully.

linuxhomenetworking.com .18 www.

What is sudo? • Sudo is a command that allows users defined in the /etc/sudoers configuration file to have temporary root access to run certain privileged commands.linuxhomenetworking. www. • When running the command you will be prompted for your regular password before it is executed. . • The command you want to run must first begin with the word "sudo" followed by the regular command syntax. here's how.Chapter 1 : Adding Linux Users 19 Chapter 2 Using Sudo =========================================== In This Chapter Chapter 2 Using Sudo What is sudo? Download and Install The sudo Package The visudo Command The /etc/sudoers File How To Use sudo Using syslog To Track All sudo Commands © Peter Harrison.com =========================================== You can give selected users temporary "root" privileges using the "sudo" command.

com • You may run other privileged commands using sudo within a five minute period without being reprompted for a password • All commands run as sudo are logged in the log file /var/log/messages Download and Install The sudo Package Fortunately the package is installed by default by RedHat The visudo Command • "visudo" is the command used to edit the /etc/sudoers configuration file. If you run out of space on a line. The keyword "ALL" can mean all usernames. "visudo" uses the same commands as the "vi" text editor. It is not recommended that you use any other editor to modify your sudo parameters. • "visudo" is best run as user "root" The /etc/sudoers File General Guidelines o The /etc/sudoers file has the general format: usernames/group o o o o o o o target-servername = command Groups are the same as user groups and are differentiated from regular users by a % at the beginning The "#" at the beginning of a line signifies a comment line You can have multiple usernames per line separated by commas Multiple commands can be separated by commas too. you can end it with a "\" and continue on the next line.20 www. The NOPASSWD keyword provides access without you being prompted for your password Simple Examples o Users "paul" and "mary" have full access to all privileged commands paul. Spaces are considered part of the command.linuxhomenetworking. groups. commands and servers. mary ALL=(ALL) ALL .

.. . [paul@bigboy paul]$ Using syslog To Track All sudo Commands All sudo commands are logged in the log file /var/log/messages.. COMMAND=/bin/more sudoers [root@bigboy tmp]# . logname=paul uid=0 euid=0 tty=pts/0 ruser= rhost= user=paul Nov 18 22:51:25 bigboy sudo: paul : TTY=pts/0 ..Chapter 2 : Using Sudo 21 o Users with a groupid of "operator" has full access to all commands and won't be prompted for a password when doing so. user "paul" attempts to view the contents of the /etc/sudoers file [paul@bigboy paul]$ more /etc/sudoers /etc/sudoers: Permission denied [paul@bigboy paul]$ • Paul tries again using sudo and his regular user password and is successful [paul@bigboy paul]$ sudo more /etc/sudoers Password: . ... USER=root . [root@bigboy tmp]# grep sudo /var/log/messages Nov 18 22:50:30 bigboy sudo(pam_unix)[26812]: authentication failure. PWD=/etc . Here is sample output from the above example. %operator ALL=(ALL) NOPASSWD: ALL How To Use sudo • In this example.

linuxhomenetworking.com .22 www.

thereby making life easier for the software developer who wrote the package. they more easily installed across a wide variety of Linux flavors. and source RPMs for non standard installations. As the procedure for installing source RPMs involves compiling source code.linuxhomenetworking. Where To Get Commonly Used RPMs Here are three commonly used sources for RPMs: .com =========================================== A lot of Linux system software is available using RPM packages for default Linux installs.23 Chapter 3 Installing RPM Software =========================================== In This Chapter Chapter 3 Installing RPM Software Where To Get Commonly Used RPMs How to Easily Access CD RPMs With Automount Downloading RPMS To Your Linux Box Getting RPMs Using Web Based FTP Getting RPMs Using Command Line Anonymous FTP How To Install The RPMs How to Install Source RPMs How To List Installed RPMs How Uninstall RPMs RedHat Up2date © Peter Harrison. www.

See the section about using Automount to easily access your CDROM drive to obtain RPM files. If you’re new to FTP.linuxhomenetworking. Always remember to select the RPM that matches your version of Linux http://speakeasy. This will make your Linux system act more like Windows. though you run the risk of some of the packages being obsolete due to newer releases on the RedHat website.com RPMs On Your Installation CDs This is usually easier than having to download files from a remote website.1. A good general purpose source is RPMfind.7-33 [root@bigboy tmp]# • You can then ensure that it runs when the system boots using the chkconfig command. You can check this using the following commands.rpmfind. start your search in the /pub/redhat/linux/ directory and move down the directory tree. • Autofs is the package that supports Automount is installed by default with newer versions of RedHat Linux. RPMs Downloaded From Speakeasy RedHat only has their approved software on their site.com/apps/download/advanced_search. RPMs Downloaded From Redhat Advanced searches for all versions of RedHat can be done using this web link: http://www.redhat. [root@bigboy tmp]# chkconfig --level 345 autofs on [root@bigboy tmp]# . [root@bigboy tmp]# rpm -qa | grep autofs autofs-3. FTP downloading it’ll be explained later.html RedHat also has a highly used FTP site.redhat. don’t worry.24 www.com.net/ How to Easily Access CD RPMs With Automount Using the Linux installation CDs is usually easier. It is usually simplest to configure your system to Automount your CDROM. ftp. This makes the files on it immediately accessible whenever you access it without having to use the "mount" command.

Chapter 3 : Installing RPM Software

25

• There are two automount configuration files in /etc, one called auto.master and the other called auto.misc. My auto.master looks like this: /misc /etc/auto.misc --timeout 60

The default version of this file normally has this line commented out so you’ll have to remove the "#" at the beginning of the line for the configuration to take effect when autofs is restarted. The first entry is not the mount point. It's where the set of autofs mount points will be. The second entry is a reference to the default map file /etc/auto.misc and the third option says that the mounted filesystems can try to unmount themselves 60 seconds after use. • You can create mount points for each of your removable devices, "floppy", "cdrom" and "zip" with the following commands. [root@bigboy [root@bigboy [root@bigboy [root@bigboy total 3 drwxr-xr-x 2 drwxr-xr-x 2 drwxr-xr-x 2 [root@bigboy tmp]# tmp]# tmp]# tmp]# mkdir /misc/cdrom mkdir /misc/floppy mkdir /misc/zip ll /misc

root root 1024 Nov 10 16:06 cdrom root root 1024 Nov 10 16:06 floppy root root 1024 Nov 10 16:06 zip tmp]#

• Edit your auto.misc file to include the CDROM. It should have an entry like this. cdrom -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom You'll find other entries such as "floppy" and "zip" commented out with a "#". If you need them, just delete the "#". The first column (the "key") is the mount point under directory /misc, so in this case you'll be doing auto mounting when you access /misc/cdrom. • Restart autofs. [root@bigboy /tmp]# /etc/init.d/autofs restart Stopping automount:[ OK ] Starting automount:[ OK ] [root@bigboy /tmp]#

Downloading RPMS To Your Linux Box
For casual searching and installing, I recommend using the http links above. If you are doing industrial strength stuff, then use a real FTP client such as (WSFTP or CuteFTP for GUI) or the command line.

26

www.linuxhomenetworking.com

Getting RPMs Using Web Based FTP
Let’s say you are running RedHat 8.0 and need to download an RPM for the DHCP server.

RedHat
• • • • • • • Use your web browser to go to the RedHat link above Type in dhcp in the search box Click the search button Scroll down for the RPM you need for the DHCP server Click on the appropriate "download" link Click on the FTP link Save the file to Linux box's hard drive

Speakeasy
• • • • • • • Go to the Speakeasy link Type in dhcp in the search box Click the search button Scroll down for the RPM that matches your version of RedHat The right hand column has the links with the actual names of the rpm files Click the link Save the file to Linux box's hard drive

It is best to download RPMs to a directory named "RPM", so you can find them later.

Getting RPMs Using Command Line Anonymous FTP
The Web based method above transparently uses anonymous File Transfer Protocol (FTP). Anonymous FTP allows you to log in and download files from a FTP server using the username “anonymous” and a password that matches your email address. This way anyone can access the data. • Let's try to FTP the SSH package from ftp.redhat.com [root@bigboy tmp]# ftp ftp.redhat.com Trying 66.77.185.38... Connected to ftp.redhat.com (66.77.185.38).

Chapter 3 : Installing RPM Software

27

220 Red Hat FTP server ready. All transfers are logged. Name (ftp.redhat.com:root): anonymous 331 Please specify the password. Password: 230 Login successful. Have fun. Remote system type is UNIX. Using binary mode to transfer files. ftp> ls 227 Entering Passive Mode (66,77,185,38,50,122) 150 Here comes the directory listing. drwxr-xr-x 5 0 0 4096 Jun 09 04:20 pub 226 Directory send OK. ftp> • Let's see the available help commands ftp> help Commands may be abbreviated. Commands are: ! $ account append ascii bell binary bye case cd cdup chmod close cr delete ftp> • The commands you'll most likely use are: FTP Commands Command binary cd dir exit Description Copy files in binary mode Change directory on the FTP server List the names of the files in the current remote directory Bye bye debug dir disconnect exit form get glob hash help idle image lcd ls macdef Mdelete mdir mget mkdir mls mode modtime mput newer nmap nlist ntrans open prompt passive proxy sendport put pwd quit quote recv reget rstatus rhelp rename reset restart rmdir runique send site size status struct system sunique tenex tick trace type user umask verbose ?

28

www.linuxhomenetworking.com

Command get lcd ls mget mput passive put pwd

Description Get a file from the FTP server Change the directory on the local machine Same as dir Same as get, but you can use wildcards like "*" Same as put, but you can use wildcards like "*" Make the file transfer passive mode Put a file from the local machine onto the FTP server Give the directory name on the local machine

• By using the search feature on the website ahead of time, I know that the RedHat 8.0RPMs are located in the pub/redhat/linux/8.0/en/os/i386/RedHat/RPMS directory. ftp> cd pub/redhat/linux/8.0/en/os/i386/RedHat/RPMS 250 Directory successfully changed. ftp> ls open* 227 Entering Passive Mode (66,77,185,38,45,180) 150 Here comes the directory listing. -rw-r--r-- 1 0 0 11191 Sep 03 21:32 open-1.4-16.i386.rpm -rw-r--r-- 1 0 0 2006950 Sep 03 21:32 openh323-1.9.3-4.i386.rpm -rw-r--r-- 1 0 0 256971 Sep 03 21:32 openh323-devel-1.9.3-4.i386.rpm ... ... -rw-r--r-- 1 0 0 217326 Sep 03 21:33 openssh-3.4p1-2.i386.rpm ... ... 226 Directory send OK. ftp> • Get the file we need and place it in the local directory /usr/rpm. Also print "#" hash signs on the screen during the download. ftp> hash Hash mark printing on (1024 bytes/hash mark). ftp> lcd /usr/rpm Local directory now /usr/rpm ftp> ftp> get openssh-3.4p1-2.i386.rpm local: openssh-3.4p1-2.i386.rpm remote: openssh-3.4p1-2.i386.rpm 227 Entering Passive Mode (66,77,185,38,57,102) 150 Opening BINARY mode data connection for openssh-3.4p1-2.i386.rpm (217326 bytes). ##################################################################### #####################################################################

Chapter 3 : Installing RPM Software

29

#################################################################### 226 File send OK. 217326 bytes received in 87.7 secs (2.4 Kbytes/sec) ftp> • Bye bye ftp> exit 221 Goodbye. [root@bigboy tmp]#

How To Install The RPMs
Using Downloaded Files
• • Download the source RPMs which usually have a file extension ending with (.rpm) into a temporary directory such as /tmp As user root, issue the following command: [root@bigboy tmp]# rpm -Uvh filename.rpm

Using CDROMs
• Insert the CDROM and check the files in /misc/cdrom/RedHat/RPMS [root@bigboy tmp]# cd /misc/cdrom/RedHat/RPMS [root@bigboy RPMS]# ls filename* filename.rpm [root@bigboy RPMS]# rpm -Uvh filename.rpm • When finished, eject the CDROM [root@bigboy RPMS]# cd /tmp [root@bigboy tmp]# eject cdrom [root@bigboy tmp]#

How to Install Source RPMs
Sometimes the packages you want to install need to be compiled in order to match your kernel version. This requires you to use source RPM files. • Download the source RPMs or locate them on your CD collection. They usually have a file extension ending with (.src.rpm)

30

www.linuxhomenetworking.com

• Run the following commands as root:

Newer Linux Versions
Compiling and installing source RPMs with newer RedHat Linux versions can be done simply with the rpmbuild command

[root@bigboy tmp]# rpmbuild --rebuild filename.src.rpm

o

Here is an example in which we install the tacacs plus package. [root@bigboy rpm]# rpmbuild --rebuild tac_plus-4.0.3-2.src.rpm Installing tac_plus-4.0.3-2.src.rpm Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.61594 + umask 022 + cd /usr/src/redhat/BUILD + cd /usr/src/redhat/BUILD + rm -rf tac_plus-4.0.3 + /usr/bin/gzip -dc /usr/src/redhat/SOURCES/tac_plus-4.0.3.tgz + tar -xvvf drwxr-xr-x nsen/25 0 1999-08-04 00:33:15 tac_plus-4.0.3/ -rw-r----- root/root 9029 1999-04-02 22:03:45 tac_plus4.0.3/CHANGES ... ... ... ... ... ... Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/tacacsd Wrote: /usr/src/redhat/RPMS/i386/tac_plus-4.0.3-2.i386.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.60207 + umask 022 + cd /usr/src/redhat/BUILD + cd tac_plus-4.0.3 + rm -rf /var/tmp/tacacsd + exit 0 Executing(--clean): /bin/sh -e /var/tmp/rpm-tmp.60207 + umask 022 + cd /usr/src/redhat/BUILD + rm -rf tac_plus-4.0.3 + exit 0 [root@bigboy rpm]#

o

Here we see that the regular RPM file, not the source RPM, has been installed correctly. [root@bigboy rpm]# rpm -qa | grep tac_plus tac_plus-4.0.3-2 [root@bigboy rpm]#

rpm o How To List Installed RPMs • The rpm –qa command will list all the packages installed on your system [root@bigboy tmp]# rpm –qa perl-Storable-1.rpm SPECS]# cd /usr/src/redhat/SPECS SPECS]# rpm –ba filename tmp]# cd /usr/src/redhat/RPM/i386 i386]# rpm -Uvh filename. You then have to install the new RPM file from this directory.4-9 e2fsprogs-1.3-3 … … … [root@bigboy tmp]# • You can also pipe the output of this command through the grep command if you are interested in only a specific package.2-7 audiofile-0.14-15 smpeg-gtv-0. In this example we are looking for all packages containing the string “ssh” in the name. regardless of case (“-i” meaning ignore case) [root@bigboy tmp]# rpm -qa | grep -i ssh openssh-server-3.0. o o The source files are first exported into the directory /usr/src/redhat/SPECS with the rpm command. You then have to run the rpm command again to compile the source files into a regular RPM file which will be placed in either the /usr/src/packages/RPMS/i386/ or the /usr/src/redhat/RPMS/i386/ directories.4p1-2 openssh-clients-3.2.4p1-2 openssh-3.27-9 libstdc++-3.4p1-2 openssh-askpass-gnome-3. [root@bigboy [root@bigboy [root@bigboy [root@bigboy [root@bigboy tmp]# rpm -Uvh filename.src.4.4p1-2 [root@bigboy tmp]# .4p1-2 openssh-askpass-3.Chapter 3 : Installing RPM Software 31 Older Linux Versions The process is more complicated with older RedHat Linux versions as can be seen below.

To install the key.linuxhomenetworking. Without it. run the following as root: rpm --import /usr/share/rhn/RPM-GPG-KEY [root@bigboy tmp]# • Issue the rpm command to get the keys [root@bigboy tmp]# rpm --import /usr/share/rhn/RPM-GPG-KEY [root@bigboy tmp]# . Here’s what to do: • After installing the operating system issue the up2date command. [root@bigboy tmp]# rpm –e package-name RedHat Up2date RedHat has a program called up2date which will update your Linux installation with the latest revisions of the RPMs from the RedHat website via a HTTPS/SSL connection running in the background.32 www. debug No 1. [root@bigboy tmp]# up2date 0. Just quit by typing “q” and up2date will give you the command to run to get the encryption keys from RedHat. It will prompt you to change the initial settings. depslist [] … … … Enter number of item to edit <return to exit. isatty Yes 2. public key.com How Uninstall RPMs • The rpm –e command will erase an installed package. you will be unable to verify that packages Update Agent downloads are securely signed by Red Hat. q to quit without saving>: Your GPG keyring does not contain the Red Hat. Inc. The package name given must match that listed in the rpm –qa command as the version of the package is important. Your Update Agent options specify that you want to use GPG.

.. ######################################## Fetching Obsoletes list for channel: redhat-linux-i386-8. name.. This is done with the up2date –u command. ######################################## cups-libs-1.0.2..4.1. ####################################### Testing package set / solving RPM inter-dependencies.0Pkg name/pattern [root@bigboy tmp]# ..18 24.Chapter 3 : Installing RPM Software 33 • Issue the up2date command again and it will prompt you through a number of registration screens which will ask for information such as: o o o The login name & password of your choice Your.. ######################################## Fetching rpm headers. This is what it looks like: [root@bigboy tmp]# up2date -u Fetching package list for channel: redhat-linux-i386-8.r ########################## Done..8. 1:cups-libs 2:cvs 3:cyrus-sasl … … … ########################################### [100%] ########################################### [100%] ########################################### [100%] The following Packages were marked to be skipped by your configuration: Name Version Rel Reason --------------------------------------------------------------------kernel 2.0.17-0.i386.... address and email address A profile name for your server • It will then present you with a list of all the packages installed on your server and ask you whether you want to register this software information with RedHat • The up2date updater will then register your system and exit back to the command prompt. • Now you have to actually update the software using up2date. … … … Preparing ########################################### [100%] Installing.

linuxhomenetworking. up2date automatically figures out these package inter-dependencies and will install all the required foundation packages as well. The “–u” switch will update all packages and the “-p” will register any additional packages you have installed without using up2date.34 www. If you have a firewall protecting your system. you will need TCP port 443 access to the internet Updating packages could cause programs written by you to stop functioning especially if they rely on the older version’s features or syntax. All additional profiles under the login name have an annual fee. You can selectively update the package mentioned in each email using the command: [root@bigboy tmp]# up2date package-name o o o o Only one profile per login name is free.com Some Necessary Facts About up2date o o You can update your contact information afterwards using the link http://www. Here is a sample script that you can run weekly using cron #!/bin/sh # # Updates system every week # up2date -p up2date -u o . up2date uses HTTPS/SSL to do its updating.com/network RedHat will regularly send you emails with the packages you need to update.redhat. You can write a small script to periodically update your system. Some RPMs won’t install unless other RPMs have been installed previously.

Chapter 3 : Installing RPM Software 35 .

36 www.linuxhomenetworking.com .

37 Chapter 4 The Linux Boot Process =========================================== In This Chapter Chapter 4 The Linux Boot Process The RedHat Boot Sequence Determining The Default Boot runlevel Get A GUI Console Get A Basic Text Terminal Without Exiting The GUI System Shutdown And Rebooting How To Set Which Programs Run At Each runlevel © Peter Harrison.linuxhomenetworking. These are listed below.d/rc1. www. After completing this first phase.d which provides only the most basic functionality and the ability to only handle a single user. the boot process will run a number of scripts located in subdirectories under directory /etc/rc.d. run level). The boot process first runs the scripts found in /etc/rc. . the boot process will run scripts in only one of the other directories depending on the startup mode (aka. This stage is known as “single user mode”.com =========================================== The way Linux boots up is very important information to know. The RedHat Boot Sequence When RedHat boots. You can alter it to change the type of login screen you get and also which programs get started.

d/rc4.d /etc/rc.d /etc/rc.linuxhomenetworking.halt (Do NOT set initdefault to this) # 1 .d/rc5. When set it to “3”. you get the GUI.d /etc/rc.d/rc6.X11 # 6 .unused # 5 .Multiuser.d Run Level Description Halt Single-user mode Not used (user-definable) Full multi-user mode (No GUI interface) Not used (user-definable) Full multi-user mode (With GUI interface) Reboot Determining The Default Boot runlevel The default boot runlevel is set in the file /etc/inittab with the "initdefault" variable.reboot (Do NOT set initdefault to this) # id:3:initdefault: # Console Text Mode id:5:initdefault: # Console GUI Mode • Most home users boot up with a Windows like GUI (Run Level 5) • Most techies will tend to boot up with a plain text based command line type interface (Run level 3) • Changing "initdefault" from 3 to 5 or vice-versa will only have an effect upon your next reboot.Single user mode # 2 . Get A GUI Console You have two main options if your system comes up in a text terminal mode on the VGA console and you want to get the GUI: • Manual Method: You can start the X terminal GUI application each time you need it by running the “startx” command at the VGA console. Remember that when you log out you will get the regular text based console again. when set to “5”. if you do not have networking) # 3 . Here is a sample snippet of the file: (Delete the initdefault line you don't need) # Default runlevel.d/rc0. The runlevels used by RHS are: # 0 . the system boots up with the text interface on the VGA console.d/rc2.Full multiuser mode # 4 . .d /etc/rc.d /etc/rc. without NFS (The same as 3.d/rc1.d/rc3.com Mode/Run Level 0 1 2 3 4 5 6 Directory /etc/rc. See the section below on how to get a GUI login all the time until the next reboot.d /etc/rc.38 www.

You can get the GUI login with the sequence <CTL> <ALT> <F7>. If the GUI is running. You will need to edit your “initdefault” variable in your /etc/inittab file as mentioned in the preceding section to keep this functionality even after you reboot. Click on Systems Tools.Chapter 4 : The Linux Boot Process [root@bigboy tmp]# startx • Automatic Method: You can have Linux automatically start the X terminal GUI console for every login attempt until your next reboot by using the init command. You'll get a new login prompt for each attempt. it will run under session number seven. [root@bigboy tmp]# init 5 Get A Basic Text Terminal Without Exiting The GUI Using A GUI Terminal Window You can open a GUI based window with a command prompt inside by doing the following: o o Click on the “Red Hat” Start button in the bottom left hand corner of the screen. o o o Sessions one through six are text sessions. or if the GUI is running after launching "startx" System Shutdown And Rebooting The "init" command will allow you to change the current runlevel. You can step through each text session by using the <CTL> <ALT> <F1> through <F6> key sequence. Halt / Shutdown The System [root@bigboy tmp]# init 0 Reboot The System [root@bigboy tmp]# init 6 . only in run level 5. then Terminal Using Virtual Terminals Linux actually has seven virtual console sessions running on the VGA console.

.. Let’s change it so that Sendmail doesn't startup at boot..d and the runlevels at which they will be "on" or "off" [root@bigboy tmp]# chkconfig --list keytable 0:off 1:on 2:on 3:on 4:on atd 0:off 1:off 2:off 3:on 4:on syslog 0:off 1:off 2:on 3:on 4:on gpm 0:off 1:off 2:on 3:on 4:on kudzu 0:off 1:off 2:off 3:on 4:on wlan 0:off 1:off 2:on 3:on 4:on sendmail 0:off 1:off 2:off 3:on 4:off netfs 0:off 1:off 2:off 3:on 4:on network 0:off 1:off 2:on 3:on 4:on random 0:off 1:off 2:on 3:on 4:on .linuxhomenetworking.com How To Set Which Programs Run At Each runlevel Most RedHat packages place a startup script in the directory /etc/init.40 www.. . Use Chkconfig To Get A Listing Of Sendmail's Current Startup Options [root@bigboy tmp]# chkconfig --list | grep mail sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off [root@bigboy tmp]# Switch Off Sendmail Starting Up In Levels 3 and 5 [root@bigboy tmp]# chkconfig --level 35 sendmail off [root@bigboy tmp]# Doublecheck That Sendmail Will Not Startup [root@bigboy tmp]# chkconfig --list | grep mail sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@bigboy tmp]# . The typical home/SOHO user doesn't have to be a scripting / symbolic linking guru to make sure everything works right because RedHat comes with a nifty utility called "chkconfig" to do it for you.d/rc. 5:on 5:on 5:on 5:on 5:on 5:on 5:on 5:on 5:on 5:on 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off Chkconfig Examples You can use chkconfig to change runlevels for particular packages.X directory. • Use this command to get a full listing of packages listed in /etc/init. Here we see Sendmail will start with a regular startup at runlevel 3 or 5.d and place symbolic links (pointers) to this script in the appropriate /etc/rc.

d directory. Don't add/remove anything to other runlevels unless you absolutely know what you are doing. . Don't experiment. The commands for starting and stopping the programs covered in this book are covered in each respective chapter.Chapter 4 : The Linux Boot Process Turn it back on again [root@bigboy tmp]# chkconfig --level 35 mail on [root@bigboy tmp]# chkconfig --list | grep mail sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off [root@bigboy tmp]# Final Tips On chkconfig • • • In most cases you'll want to modify runlevels 3 and 5 simultaneously AND with the same values. Chkconfig doesn’t start the programs in the /etc/init. it just configures them to be started or ignored when the system boots up.

42 www.linuxhomenetworking.com .

Before you do. Network Diagram . www.com =========================================== We have assumed you want to host your website in your home or home office using a topology similar to that in the diagram below.43 Chapter 5 Why Host Your Own Site? =========================================== In This Chapter Chapter 5 Why Host Your Own Site? Network Diagram Alternatives To Home Web Hosting Factors To Consider Before Hosting Yourself How To Migrate From An External Provider © Peter Harrison. you should at least weigh the merits of such a move.linuxhomenetworking.

com. . It takes about 3-4 days for DNS to propagate across the Web.linuxhomenetworking. You must make sure your new domain name’s DNS records point to the DNS server of the virtual hosting company. For the home based website these are usually not big issues. You should be able to buy this equipment second hand for about $100. so you’ll probably have to wait at least that long before you’ll be able to view your site using your domain. the IP address of your site plus the name of a private directory on a shared web server in which you’ll place your web pages. • Upload your web pages to your private virtual hosting directory. Changes can be made with little delay. security audits. The steps are fairly straight forward: • Sign up for the virtual hosting service.my-site.com Alternatives To Home Web Hosting It is easy to find virtual hosting companies on the Web which will offer to host a simple website for about $10 per month. New Skills: There is also the additional benefit of learning the new skills required to set up the site. They will provide you with a login name and password. technical support. Availability: Reliable virtual hosting facilities may not be available in your country and/or you may not have access to the foreign currency to host your site abroad.my-site. If your home already has DSL there would be no additional network connectivity costs. • Register your domain name. many will also provide an e-commerce feature which will allow you to have a shopping cart and customer loyalty programs.com. with companies like Register. Factors To Consider Before Hosting Yourself Virtual hosting is the ideal solution for many small websites. data base services and technical support offered by the virtual hosting company. o o Cons o Lost Services: You lose the convenience of many of the services such as backups. So for a savings of $10 per month the project should pay for itself in less than a year. redundant hardware. • Test viewing your site using your IP address in your web browser.com.44 www. load balancing. DNS.com. There are a number of reasons why you may want to move your website to your home or small office. For an additional charge. a number of email addresses and an easy to use web based GUI to manage your settings. Home Based Websites Pros o Cost: It is possible to host a website on most DSL connections. The virtual hosting provider will also offer free backups of your site. such as www. A website can be hosted on this data circuit for the only additional hardware cost of a network switch and a web server. www. Verisign or RegisterFree.

Proceed with the server migration only if you feel your staff can handle the job. Hosting providers may provide software patches to fix security vulnerabilities on your web servers and may even provide a firewall to protect it. There is a chapter on the iptables Linux firewall and general security policies for Linux servers to help you overcome these shortcomings. you will have to consider the following: In-house Web Hosting Savings • • Monthly out sourced web hosting fee Elimination of the cost of delays to implement desired services.Chapter 5 : Why Host Your Own Site? 45 o Security: One important factor to consider is the security of your new server. which may have been highly desirable and cost effective. Security: Always weigh the degree of security maintained by your hosting provider with that which you expect to provide in-house. time) Cons o o Lost Services: You won’t have access to the services provided by your old service provider. You will eventually be able to justify hosting your website inhouse based on this financial fact. These services may be more difficult to implement at home. o Small Office Based Websites Pros o o o Increased Control: You will be able to manage all aspects of your website if it is hosted on a server based either in-house or within your control at a remote data center. o . Technical Ability: You may have to incur additional training costs to ensure that your IT staff has the necessary knowledge to do the job internally. Technical Ability: Your service provider may have more expertise in setting up your site than you do. In order to determine the break even point of the proposal. Training The percentage of IT staff’s time installing and maintaining the site Potential cost of the risks (% likelihood of failure per month X cost of failure) • • Risks Likelihood of a failure and expected duration The cost of both the failure and post failure recovery (Hardware. • • • • • Costs New hardware & software Possible new application development. software. data restoration. Cost: The cost of using an external web hosting provider will increase as you purchase more systems administration services. The chapter on the Linux iptables firewall should help make the decision easier. Availability: Reliable virtual hosting facilities may not be available in your country and you may not have access to the foreign currency to host your site abroad.

linuxhomenetworking. You should also read the sections on mail and web server configuration to help provide a more rounded understanding of the steps involved.46 www.com How To Migrate From An External Provider The chapter on DNS has a detailed explanation of the steps involved in migrating your website from an external hosting provider to your home or small office. .

com =========================================== This chapter briefly explains some basic networking concepts for the home user.linuxhomenetworking. .47 Chapter 6 Introduction To Networking =========================================== In This Chapter Chapter 6 Introduction To Networking What Is TCP/IP? What Is An IP Addresses? What Is Localhost? What Is A Subnet Mask? How Many Addresses Do I Get With My Mask? How Can I Figure Out My Broadcast Address? What Is Duplex? What Is A Hub? What Is A Switch? What Is A LAN? What Is A Router? What Is A Gateway? What Is A Route? What Is A Default Gateway? What Is A NIC? What Is A MAC Address? What Is ARP? What Is A Firewall? What Is NAT? What Is Port Forwarding With NAT? What Is DHCP? What Is DNS? How Can I Check The IP Address For A Domain? How Do I Get My Own DNS Domain Name? What is FTP? Where is Linux Help? © Peter Harrison. www.

UDP is usually used for applications in which the data sent is not mission critical. It is part of the larger OSI model upon which most data communications is based. You could look at it as a combination used to create a connection ID number. Programs that use TCP therefore have a means of detecting connection failures and requesting the retransmission of missing packets. TCP is a good example of a “connection oriented” protocol. The source/destination port combination defines the program on the computer that sent/received the data. but both the UDP and the TCP datagram headers track the “port” being used. What are TCP / UDP Ports? So the data portion of the IP packet contains a TCP or UDP datagram sandwiched inside. Data is sent on a “best effort” basis with the machine that sends the data having no means of verifying whether the data was correctly received by the remote machine. Usually when a connection is made from a client computer requesting data to the server machine that contains the data: . For example. For manageability. How does the computer know what program needs the data? Each IP packet also contains a piece of information in its header called the “type” field. Certain programs are assigned specific that are internationally recognized. TCP keeps track of the packets sent by giving each one a sequence number with the remote server sending back “acknowledgement” packets confirming correct delivery. It then passes the data to the program that expects to receive it. The two most popular transportation mechanisms used on the Internet are Transmission Control Protocol (TCP) and User Datagram Protocol (UDP). Only the TCP datagram header contains sequence information. The remote computer then receives the packets and reassembles the data and checks for errors. What is UDP? UDP is a connectionless protocol. This informs the computer receiving the data about the type of transportation mechanism being used.linuxhomenetworking. those above 1024 are generally reserved for non system third party applications. One component of TCP/IP is the Internet Protocol (IP) which is responsible for ensuring that data is transferred between two addresses without being corrupted. port 80. What is TCP? TCP opens up a connection between client and server programs running on separate computers so that multiple and/or sporadic streams of data can be sent over an indefinite period of time. is reserved for HTTP web traffic and port 25 is reserved for SMTP email. the data is usually split into multiple pieces or “packets” each with its own error detection bytes in the control section or “header” of the packet. Ports below 1024 are reserved for privileged system functions. It is also used when data needs to be broadcast to all available servers on a locally attached network where the creation of dozens of TCP connections for a short burst of data is considered resource hungry.48 www.com What Is TCP/IP? TCP/IP is a universal standard suite of protocols used to provide connectivity between networked devices.

• IP addresses are in reality a string of binary digits or "bits".25. More information on ICMP messages can be found in both the Appendix and the chapter on network troubleshooting. It is not strictly a TCP/IP protocol. control. a bad connection. What is a TTL? Each IP packet has a Time to Live (TTL) section that keeps track of the number of network devices the packet has passed through to reach its destination. but a response to the initial port 80 HTTP query. For example. If the TTL value reaches “0”. then the network device will discard the packet. ICMP also includes echo and echo reply messages used by the Linux “ping” command to confirm network connectivity. 1095 and query the server on port 80 (HTTP) The server recognizes the port 80 request as an HTTP request and passes on the data to be handled by the web server software. If it is an HTTP request. and informational messages for use by the operating system. but TCP/IP based applications use it frequently. What Do IP Addresses Look Like? • All devices connected to the Internet have an Internet Protocol (IP) address. four numbers with dots in between. Each bit is either a 1 or a 0. TTLs help to reduce the clogging of data circuits with unnecessary traffic.12.Chapter 6 : Introduction To Networking 49 o the client selects a random unused "source" port greater than 1024 and queries the server on the "destination" port specific to the application. It will then issue an ICMP reject message to the original sending machine that the data should be resent. ICMP provides a suite of error.65. • For ease of use. • The numbers between the dots are frequently referred to as "octets" • Some groups of IP addresses are reserved for use only in private networks and are not routed over the Internet. it helps to uniquely identify a user of the system. An example of an IP address would be 97. None of the numbers between the dots may be greater than 255. Just like a telephone number. IP addresses have 32 bits in total. IP addresses are written in what is called a "dotted decimal" format. it tells the TCP application to respond back to port 1095 of the client using a source port of port 80. These are: . This mechanism helps to ensure that bad routing on the Internet won’t cause packets to aimlessly loop around the network. the client will use a source port of say. The server will usually detected this by examining the packet and correlating the contents to what it finds in the IP header’s error control section. o The client keeps track of all its requests to the server's IP address and will recognize that the reply on port 1095 isn't a request initiation for "Nicelink" (See the Bibliography for a link to a TCP/IP port listing). When the web server software replies to the client. The server sending the packet sets the TTL value and each network device that the packet passes through then reduces this value by “1”. IP packets will occasionally arrive at a server with corrupted data due to any number of reasons including. What is ICMP? There is another commonly used protocol called the Internet Control Message Protocol (ICMP). electrical interference or even misconfiguration.

158. a subnet mask of 255.168. and host #255 (192.172.168.255.158.255. What Is Localhost? Whether or not your computer has a network interface card it will have a “built in” IP address with which network aware applications can communicate with one another.253.Available 97.255.168.0.1. So if your server has an IP address of 192.0.linuxhomenetworking.168. For example if the ISP provides you with a "public" network address of 97.255.27 .255 • Home networking equipment / devices usually are configured in the factory with an IP address in the range 192.255.255.1.26 . The (808) represents the area code.158.192. then your IP addresses will be: • • • • • 97.248 and a gateway of 97. • If you purchased a DSL service from your Internet service provider (ISP) that gives you fixed IP addresses.158.1. You can then use IP addresses from #1 to #254 on your "private" network.0.168. host #0 (192.255.25 . the 225-2468 represents the telephone within that area code.0.0. • Subnet masks allow you to specify how long you want the area code to be (network portion) at the expense of the number of telephones in that are in the area code (Host portion) • Most home networks use a subnet mask of 255.248 that defines 8 IP addresses.253.255.0 .255.1.Available .1 and the server or host would be device #25 on that network.Gateway 97.24 – Network base address 97. such as (808) 225-2468.253.24.1 and is frequently referred to as “localhost” What Is A Subnet Mask? • Subnet masks are used to tell which part of the IP address represents: • The network on which the computer is connected (Network portion) • The computer's unique identifier on that network (Host portion) • A simple analogy would be a phone number.168. This IP address is defined as 127. then they will most likely provide you with a subnet mask of 255.253.255 192.253.158.0.0 .50 www.255.168.158.255.255) is reserved for broadcast traffic intended to reach all hosts on the network at the same time.10.255 172.25 and a subnet mask of 255.0.0) is reserved to represent the network itself.0.255.1.24. • In this example.168.253.255.253. then the network portion would be 192.com Private IP Addresses 10.16.Available 97.158.28 . Each "255" means this octet is for the area code (network portion).1 to 192.31. • You can check the Linux networking topics page on how to configure the IP address of your Linux box.0 .

The broadcast address is 97. Multiply this result by the result of step 1 to get the network address (8 x 3 = 24).255.158.30 .255. how do you determine the network address and the broadcast address.224 = 32 56 / 32 = 1 32 x 1 = 32.248) = 8 Divide the last octet of the IP address by the result of step 1. Therefore the broadcast address is 192.255.75 with a mask of 255.Chapter 6 : Introduction To Networking 51 • • • 97. (24 + 8 -1 = 31).253.56 with a mask of 255.0.Broadcast How Many Addresses Do I Get With My Mask? The method described in this section only works for subnet masks that start with “255.255.1 = 63.29 .168. 128.248.192) What’s The Range Of Addresses On My Network? If someone gives you an IP address of 97.240 = 16 .168. 4.255.253.253. Think of it as "The broadcast address is always the network address plus the number of IP addresses in the subnet minus 1". Think of it as "This is the third subnet with 8 addresses in it". 224.3.31 .253. if you have a subnet mask of 255.255. don't bother with the remainder (28/8 = 3). The Network address is therefore 97. These are 0.255. (256 .63 Let's do this for 10.255.240 1. 2. 3.24 The broadcast address is the result of step 3 plus the result of step 1 minus 1.224 1. 192.Available 97.253. 248.253.255” which should be sufficient for your home network.32 32 + 32 . 256 .158. Therefore the network base address is 192.3. 252 • You can calculate the number of IP addresses for each of the above values by subtracting the value from 256 • So for example.158. 256 .168.158.31 o o Let's do this for 192.28 and a subnet mask of 255. • There are only 7 possible values for the last octet of a subnet mask. in other words the boundaries of my network? Here are the steps: Manual Calculation o o Subtract the last octet of the subnet mask from 256 to give the number of IP addresses in the subnet.255.3. This will give you the theoretical number of subnets of the same size that are below this IP address.0.158. 240.Available 97.192 then you have 64 IP addresses in your subnet (256 .158.

Here is a sample of how to use it.64 64 + 16 -1 = 79.151.255. Calculation Using A Script There is a BASH script in the Appendix which will do this for you.79 Note: As a rule of thumb.0. • Data transfer speeds will be low and error levels will be high if you have a device at one end of a cable set to full duplex.92 Network Base Address : 216.255. • Full duplex uses separate pairs of wires for transmitting and receiving data so that incoming data flows don't interfere with outgoing data flows. .92 /28 IP Address : 216.0. Therefore the network base address is 10. Error detection and retransmission mechanisms ensure that data reaches the destination correctly even if it were originally garbled by multiple devices starting to transmit at the same time.193.255.151. 4.linuxhomenetworking. this only works with subnet masks that start with 255. just provide the IP address followed by the subnet mask as arguments.80 Broadcast Address : 216. If you are sub-netting a large chunk of IP addresses it’s always a good idea to lay it out on a spreadsheet to make sure there are no overlapping subnets. 3.0.sh 216. • Most modern network cards can auto-negotiate duplex with the device on the other end of the wire.193. Once again. Therefore the broadcast address is 10. It is for this reason that duplex settings aren’t usually a problem for Linux servers.193. Hubs physically cross-connect all their ports with one another which causes all traffic sent from a server to the hub to be blurted out to all other servers connected to that hub whether they are the intended recipient or not. Devices that want to transmit information have to wait their turn until the "coast is clear" at which point they send the data.0.255. It will accept subnet masks in dotted decimal format or "/value" format [root@bigboy tmp]# .com 2. 75 / 16 = 4 16 x 4 = 64.95 Subnet Mask Subnet Size [root@bigboy tmp]# : 255.240 : 16 IP Addresses What Is Duplex? • Duplex refers to the ability of a device to transmit and receive data at the same time.52 www. What Is A Hub? • A hub is a device into which you can connect all devices on a home network so that they can talk together. • Half duplex uses the same pairs of wires for transmitting and receiving data. the last octet of your network base address must be divisible by the “256 minus the last octet of your subnet mask” and leave no remainder. and another device at the other end of the cable set to half duplex./subnet-calc.193.151.151.

• Routers will connect into multiple switches to allow these networks to communicate with one another. For example. • Routers can also be configured to deny communication between specific servers on different networks. • Switches regulate traffic. • Pure switches provide no access control between servers connected to the same LAN. more expensive switches can be configured to assign only certain ports to pre-specified Virtual LANs or (VLANs) chosen by the network administrator. Routers therefore direct and regulate traffic between separate networks. In this case. The router is also capable of filtering traffic passing between the two LANs therefore providing additional security. after a random time interval. They can also filter traffic based on the TCP port section of each packet. Switches therefore provide more efficient traffic flow. Unlike a hub. Simple home switches can be connected in a chain formation to create a LAN with more ports. • Larger. much like a traffic policeman. the switch houses ports on multiple LANs. • It is for these reasons that devices that plug into hubs should be set to half duplex. • Devices that plug into switches should be set to full duplex to take full advantage of the dedicated bandwidth coming from each switch port. When this happens the servers try again. A router is still needs to be connected to each VLAN for inter-network communication. switches and hubs usually only have servers connected to them that have been configured as being part of the same network. They will also ensure that they don’t mix servers on different IP networks on the same LAN segment. until the message gets through correctly. It is possible for multiple servers to speak at once with all of them receiving garbled messages. it is possible to deny communication between two servers on different networks that intend to communicate on TCP port 80. A good rule of thumb is to have only one network per LAN. What Is A LAN? • A Local Area Network (LAN) is a grouping of ports on a hub. switch or tied to a wireless access point (WAP) that can only communicate with each other. . What Is A Router? • As stated before. • It is possible to have LANs that span multiple switches. and allow all other traffic between them.Chapter 6 : Introduction To Networking 53 • Hubs have none or very little electronics inside and therefore do not regulate traffic. This is often called “daisy chaining”. • Communication to devices on another LAN requires a router directly connected to both LANs. thereby eliminating the possibility of message garbling. This is why network administrators group trusted servers having similar roles on the same LAN. The only exception is broadcast traffic which is blurted out to all the servers simultaneously. What Is A Switch? • A switch is also a device into which you can connect all devices on a home network so that they can talk together. traffic sent from Server A to Server B will only be received by Server B.

linuxhomenetworking. What Is A Route? • In the broader networking sense.46.123.0) and the internet R2 is connected to both your SOHO home network (192.0 255. and can therefore intelligently redirect traffic to bypass failed network links.1.X.54 www.0) which is also connected to other corporate networks with addresses starting with 10. • Usually when we speak about a route on a Linux box. you must reserve an IP address for a router and make sure that the router is directly connected to the LAN associated with that network.0.0) and your credit card transaction payment the network (10. then for each network.168.168. R1 therefore would be considered your default gateway • You could put a route on your SOHO servers that states: o o • For most home networks. your default gateway would be the router / firewall connected to the Internet. What Is A Gateway? • Another name for a router.0. Each router along the way may also be referred to as a hop.1. a route refers to the path data takes to traverse from its source to its destination.X Go to network 10. What Is A Default Gateway? • A default gateway is really a gateway of last resort. we are referring to the IP address of the first hop needed to reach the desired destination network.com • If you intend to route between networks. It is assumed that this first hop will know how to automatically relay the packet. • Routers are designed to exchange routing information dynamically.0 via router R2 Go to everything else via router R1. • You can check the Linux networking topics page on how to configure the default gateway on your Linux box. • In home networks. routers most frequently provide connectivity to the Internet using network address translation or NAT.0. .X.0. Home Linux boxes frequently don't run a dynamic routing protocol and therefore rely on "static" routes issued by the system administrator at the command line or in configuration files to determine the next hop to all desired networks. • The Linux network topics page shows how to add static routes to your Linux box and also how you can convert it into a simple router. Say for example: o o o You have two routers R1 and R2 R1 is connected to both your SOHO home network (192.

Chapter 6 : Introduction To Networking 55 What Is A NIC? Your network interface card is frequently called a NIC.1. If there is an ARP entry. the server will issue an ARP request asking that router 192.1. ARP entries are not permanent and will be erased after a fixed period of time depending on the operating system used.1. MAC addresses therefore only have significance on the locally attached network.1 respond with its MAC address so that the delivery can be made. Currently. As the packet hops across the Internet. the packet is sent and the ARP table is subsequently updated with the new MAC address. Every IP packet is sent out of your NIC wrapped inside an Ethernet frame which uses MAC addresses to direct traffic on your locally attached network. the most common types of NIC used in the home are Ethernet and wireless Ethernet cards. If it doesn't. Once a reply is received. the ARP table only contains the MAC addresses of devices on the locally connected network. but the MAC addresses are reassigned by each router on the way using a process called ARP. an ARP request is made asking the target server for its MAC address. the packet is sent and the ARP table is subsequently updated with the new MAC address.168. • The Linux network topics page shows how to see your ARP table and the MAC addresses of your server's NICs. a similar process occurs. it will in turn continue with the ARP-ing process to relay the packet to the final destination. What Is A MAC Address? The media access control address (MAC) can be equated to the serial number of the NIC. the server checks it's ARP table to see whether it has the MAC address of the router's NIC. As each router in the path receives the packet. • The server will not send the data to its intended destination unless it has an entry in its ARP table.168. Once a reply is received. • If there is a valid router. If there is no ARP entry. its source/destination IP address stays the same. the server sends the IP packet to its NIC and tells the NIC to encapsulate the packet in a frame destined for the MAC address of the router. let's say with an IP address of 192. What Is ARP? The Address Resolution Protocol (ARP) is used to map MAC addresses to network IP addresses. If no entry is available. the application needing to communicate will issue a timeout or "time exceeded" error. • As can be expected. • If the target server is on the same network as the source server. The ARP table is queried. . When a server needs to communicate with another server it does the following steps: • The server first checks its routing table to see which router provides the next hop to the destination network.

56 www. As the router / firewall is located at the “border crossing” to the Internet it can easily keep track of all the various outbound connections to the Internet by monitoring: • The IP addresses and TCP ports used by each home based server and mapping it to • The TCP ports and IP addresses of the Internet servers with which they want to communicate. Examples of NAT may be found in the IP masquerade section of the Linux iptables firewall chapter and also in the Cisco PIX firewall chapter. What Is Port Forwarding With NAT? In our simple home network. the two most commonly stated are: • No one on the Internet knows your true IP address. The reverse isn’t true. all servers accessing the Internet will appear to have the single “public” IP address of the router / firewall because of “many to one” NAT. You can configure NAT to be “one to one” in which you assign multiple IP addresses to the outside “public” interface of your firewall and pair each of these addresses to a corresponding server on the inside network. you won’t be able to access the public NAT IP addresses from servers on your home network. As there normally has been no prior connection association . Basic NAT testing will require you to ask a friend to try to connect to your home network from the Internet. A short list of capabilities includes: • Throttling traffic to a server when two many unfulfilled connections are made to it • Restricting traffic being sent to obviously bogus IP addresses • Providing network address translation or NAT What Is NAT? Your router / firewall will frequently be configured to make it appear to other devices on the Internet that the servers on your Home network have a valid “public” IP address. and not a “private” IP address. This is called network address translation (NAT) and is often also called IP masquerading in the Linux world. Specifically. • Hundreds of PCs and servers behind a NAT device can masquerade as a single "public" IP address. NAT protects your home PCs by assigning them IP addresses from “private” IP address space that cannot be routed over the internet. This greatly increases the number of devices that can access the Internet without running out of "public" IP addresses. There are many good reasons for this. This arrangement works well with a single NAT IP trying to initiate connections to many Internet addresses. not just by port and IP address like routers.linuxhomenetworking. firewalls can detect malicious attempts to subvert the TCP/IP protocol. Connections initiated from the Internet to the “public” IP address of the router / firewall face a problem. As a general rule. You can also use “many to one” NAT in which the firewall maps a single IP address to multiple servers on the network.com What Is A Firewall? Firewalls can be viewed as routers with more enhanced abilities to restrict traffic. This prevents hackers from directly attacking your home systems as packets sent to the “private” IP will never pass over the Internet.

• Most home computers will get the IP address of their DNS server via DHCP from their router / firewall.com" name server. once it has a fixed IP address. to make your Linux box provide the DHCP addresses for the other machines on your network. subnet mask. The most commonly used form of DSL will also assign the outside interface of your router / firewall with a single DHCP provided IP address. You can also make your Linux box into a DHCP server.org. The assignment usually occurs when the DHCP configured machine boots up. DHCP can be used to automatically assign IP addresses. this process can cause a noticeable delay when you are browsing the web.dhcp. • The root server will then redirect your query to one of the Internet's ". For example. the router / firewall has no way of telling which of the many home PCs behind it should receive the relayed data. You can also check the chapter on Configuring a DHCP Server. • The router / firewall will then redirect the DNS queries from your computer to the DNS name server of your Internet service provider (ISP).com As you can imagine.com" DNS name servers which will then redirect the query to the "linuxhomenetworking. port forwarding is one of the most common methods used to host websites at home with DHCP DSL. You can make your Linux box into a caching DNS server for your home network too. Port forwarding is a method of counteracting this. Here step by step description of what happens with a DNS lookup. Most home router / firewalls are configured in the factory to be DHCP servers for your home network. • The "linuxhomenetworking. DNS server and default gateway information. (and) to deliver TCP/IP stack configuration parameters such as the subnet mask and default router”. or regains connectivity to the network. Each server in the chain will store the most frequent DNS name to IP address lookups in a memory cache which helps to speed up the response. What Is DNS? The domain name system (DNS) is a worldwide server network used to help translate easy to remember domain names like www. What Is DHCP? According to www.linuxhomenetworking. • Home router / firewall providing DHCP services often provides its own IP address as the DNS name server address for home computers. The DHCP client sends out a query requesting a DHCP server which in turn provides the client PC with its IP address.Chapter 6 : Introduction To Networking 57 between the Internet server and any protected server on the home network. you can configure your router / firewall to forward TCP port 80 (Web/HTTP) traffic destined to the outside NAT IP to be automatically relayed to a specific server on the inside home network As you may have guessed.com" name server will then respond with the IP address for www.com into an IP address that can be used behind the scenes by your computer. . You can check the chapter on Linux networking topics page on how to configure your Linux box to get its IP address via DHCP.linuxhomenetworking. "The Dynamic Host Configuration Protocol (DHCP) is an Internet protocol for automating the configuration of computers that use TCP/IP. • Your ISP's DNS server will then probably redirect your query to one of the 13 "root" name servers.

elan.net.92 [root@bigboy tmp]# host www.elan. Consider using the `dig' or `host' programs instead.com How Can I Check The IP Address For A Domain? If you have the domain.92 Note: nslookup is deprecated and may be removed from future releases.192.151.92 92.0.0.0.in-addr.193.58 www.151.in-addr.in-addr.151.arpa name = extra193-92.linuxhomenetworking.1 Address: 127. Consider using the `dig' or `host' programs instead.arpa nameserver = dns2.151. Run nslookup with the `-sil[ent]' option to prevent this message from appearing.arpa domain name pointer extra193-92. 193.193.net. [root@bigboy tmp]# nslookup www. Authoritative answers can be found from: 193.elan.com has address 216.216.92 [root@bigboy tmp]# You can also use the nslookup and host commands to get the reverse information.in-addr.0. Server: 127.151.151.0.com Address: 216. Server: 127. dns1.net.216.linuxhomenetworking.elan. [root@bigboy tmp]# .0. then you can use either the nslookup command or host command to get the associated IP address.151.193.linuxhomenetworking.1#53 Non-authoritative answer: 92.com Note: nslookup is deprecated and may be removed from future releases. [root@bigboy tmp]# nslookup 216. Run nslookup with the `-sil[ent]' option to prevent this message from appearing.linuxhomenetworking.net internet address = 216.net.1#53 Name: www.216.151.216.com www. but can still be used with Windows . nslookup will be removed from future releases of Linux.linuxhomenetworking.193.0.1 Address: 127.1 [root@bigboy tmp]# [root@bigboy tmp]# host 216.elan.193.arpa nameserver = dns1.151.0.193.

Chapter 6 : Introduction To Networking 59 How Do I Get My Own DNS Domain Name? • There are many companies that provide DNS name registration. This helps DNS root servers know exactly where to get the information for the IP address for your new website. These are active and passive FTP which is covered in more detail in the FTP Chapter. RegisterFree is the one I use. at which point the user will type "anonymous". o What is FTP? This is one of the most popular applications used to copy files between computers via a network connection. There are a number of commercially available GUI based clients you can load on your PC to do this. Static or Dynamic DNS? o If you didn't specifically reserve static IP addresses from your ISP. From the systems administrator's perspective. • The registration process will prompt you for your two primary DNS servers. then static DNS is the way to go. after you follow the steps below. The password is usually your valid email address. Regular FTP o o This is used primarily to allow specific users to download files to their systems. there are two types of FTP. such as WSFTP and CuteFTP. there are another two categories. In this case you'll want to use a dynamic DNS service. The remote FTP server will prompt you for a username. Anonymous FTP o o This is used primarily to allow any remote user to download files to their systems. The password will be your regular password for your user account. You can use them to determine whether the name you want is available and you can purchase the domain you want using a credit card with your web browser. don't worry you can do this later. From the remote user's perspective. You also FTP from the command line as shown in the RPM chapter. then your router is probably getting its "public" Internet IP address via DHCP from your ISP. If you bought static IP addresses. The remote FTP server will prompt you for a username. at which point the user will be the username you normally use to log into the FTP server. • If you don't have the names and/or IP addresses for you primary name servers. .

[root@bigboy tmp]# man -k ssh Tcl_DecrRefCount [Tcl_IsShared] (3) .60 www.linuxhomenetworking. From the command line you issue the man command followed by the Linux command or file you wish to get information about. then use the man command with the –k switch.OpenSSH SSH client (remote login program) SYNOPSIS ssh [-l login_name] hostname | user@hostname [command] ssh [-afgknqstvxACNPTX1246] [-b bind_address] [-c cipher_spec] [-e escape_char] [-i identity_file] [-l login_name] [-m mac_spec] [-o option] [-p port] [-F configfile] [-L port:host:hostport] [-R port:host:hostport] [-D port] hostname | user@hostname [command] DESCRIPTION ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine.com It is good to remember that FTP isn't very secure as usernames. Here are some examples: Finding General Information On A Command Here we get information on the ssh command: [root@bigboy tmp]# man ssh SSH(1) BSD General Commands Manual SSH(1) NAME ssh . Using this information you can use the man command. Where is Linux Help? Linux help files are accessed using the “man” or manual pages. to narrow your help search. It is intended to replace rlogin and rsh. If you want to get information on the ssh command. then you’d use the command “man ssh”. and provide secure encrypted … … … … [root@bigboy tmp]# Search For All Instances Of A Word Here we discover that the search string ssh can be found in the TCL man pages and also in a variety of ssh related pages including ssh. without the –k. If you want to search all the man pages for a keyword. passwords and data are sent across the network unencrypted.manipulate Tcl objects . More secure forms such as SFTP (Secure FTP) and SCP (Secure Copy) are available as a part of the Secure Shell package that is normally installed by default on RedHat. ssh-add and ssh-agent.

manipulate Tcl objects Tcl_IsShared [Tcl_DecrRefCount] (3) .gather ssh public keys ssh-keysign (8) .OpenSSH SSH client configuration files sshd (8) .manipulate Tcl objects ssh (1) .adds RSA or DSA identities to the authentication agent ssh-agent (1) .manipulate Tcl objects Tcl_IsShared (3) .OpenSSH SSH daemon sshd_config (5) .Chapter 6 : Introduction To Networking 61 Tcl_DuplicateObj [Tcl_IsShared] (3) .OpenSSH SSH client (remote login program) ssh [slogin] (1) .OpenSSH SSH client (remote login program) ssh-add (1) . management and conversion ssh-keyscan (1) .manipulate Tcl objects Tcl_IsShared [Tcl_InvalidateStringRep] (3) .OpenSSH SSH daemon configuration file [root@bigboy tmp]# .manipulate Tcl objects Tcl_InvalidateStringRep [Tcl_IsShared] (3) .ssh helper program for hostbased authentication ssh_config (5) .manipulate Tcl objects Tcl_NewObj [Tcl_IsShared] (3) .manipulate Tcl objects Tcl_IsShared [Object] (3) .manipulate Tcl objects Tcl_IsShared [Tcl_IncrRefCount] (3) .authentication key generation.authentication agent ssh-keygen (1) .manipulate Tcl objects Tcl_IsShared [Tcl_NewObj] (3) .manipulate Tcl objects Tcl_IncrRefCount [Tcl_IsShared] (3) .manipulate Tcl objects Tcl_IsShared [Tcl_DuplicateObj] (3) .

com .62 www.linuxhomenetworking.

o The first describes the function (facility) of the application that generated it. applications such as mail and cron generate messages with easily identifiable facilities named "mail" and "cron". For example. The second describes the degree of severity of the message. Each system message sent to the syslog server has two descriptive labels associated with it that makes the message easier to handle. Syslog About syslog Syslog is a utility for tracking and logging all manner of system messages from the merely informational to the extremely critical. www.com =========================================== This chapter will show you how to troubleshoot problems not only on your Linux box but also on remote networking devices using syslog. There are eight in all and they are listed below: o .linuxhomenetworking.63 Chapter 7 Troubleshooting Linux With Syslog =========================================== In This Chapter Chapter 7 Troubleshooting Linux With Syslog Syslog Logrotate © Peter Harrison.

none.debug /var/log/messages Certain applications will additionally log to their own application specific log files and directories independent of the syslog. This may be more suitable for troubleshooting.authpriv. but none from the mail. This file consists of two columns.linuxhomenetworking.64 www.conf file is configured to put most of the messages the file /var/log/messages. By default.mail. RedHat's /etc/syslog.cron.info.com Syslog Facilities Severity Level 0 1 2 3 4 5 6 7 Keyword emergencies alerts critical errors warnings notifications informational debugging Description System unusable Immediate action required Critical condition Error conditions Warning conditions Normal but significant conditions Informational messages Debugging messages The files to which syslog will write each type of message received is set in the /etc/syslog.none. all messages of severity "info" and above are logged. cron or authentication facilities/subsystems.conf file. Here is a sample: .none /var/log/messages In this case. *.conf configuration file. Here are some common examples: Files: /var/log/maillog /var/log/httpd/access_log : Mail : Apache web server page access logs . You can make this logging even more sensitive by replacing the line above with one that captures all messages from debug severity and above in the /var/log/messages file. the first lists the facilities and severities of messages to expect and the second lists the files to which they should be logged.

. Only use tabs on lines that don't start with the "#" comment character. Here’s how to configure your Linux server to start listening for these messages. then you can use this command: [root@bigboy tmp]# tail -f /var/log/messages Similar commands can be applied to all log files. Activating Changes To The syslog Configuration File Changes to /etc/syslog.conf will not take effect until you restart syslog. Spaces in the file will cause unpredictable results. Issue this command to do so: [root@bigboy tmp]# /etc/init.conf file is very sensitive to spaces. Here is an example. [root@bigboy tmp]# grep string /var/log/messages | more You can also just use the plain old "more" command to see one screen at a time of the entire log file without filtering with "grep".d/syslog restart How To View New Log Entries As They Happen If you want to get new log entries to scroll on the screen as they occur. Here is an example: [root@bigboy tmp]# more /var/log/messages Logging Syslog Messages To A Remote Linux Server Configuring the Linux Syslog Server By default syslog doesn’t expect to receive messages from remote clients. you can pipe it through the "more" command so that you only get one screen at a time.Chapter 7: Configuring Syslog 65 Directories: /var/log /var/log/samba /var/log/mrtg /var/log/httpd : Samba messages : MRTG messages : Apache webserver messages NOTE: The /etc/syslog. Grep will help you search for all occurrences of a string in a log file. Another good command to use apart from "tail" is "grep". This is probably one of the best troubleshooting tools available in Linux.

100 bigboy. The server will now start to listen on UDP port 514 which you can verify using either one of the following netstat command variations. # -r enables logging from remote machines # -x disables DNS lookups on messages recieved with -r # See syslogd(8) for more details SYSLOGD_OPTIONS="-m 0 -r" # Options to klogd # -2 prints all kernel oops messages twice.0. syslog checks its /etc/syslog.conf file to determine the expected names and locations of the log files it should create.66 www. Syslog will not listen for remote messages unless the SYSLOGD_OPTIONS variable in this file has a “–r” included in it as shown below.my-site.com bigboy loghost fully-qualified-domain-name hostname "loghost" Server "bigboy" has now become the remote logging server as its /etc/hosts entry has an alias "loghost" which indicates to syslog that this is a remote syslog server.0.0:* [root@bigboy tmp]# Configuring the Linux Client The syslog server is now expecting to receive syslog messages.0.linuxhomenetworking. . [root@bigboy tmp]# netstat -a | grep syslog udp 0 0 *:syslog *:* [root@bigboy tmp]# netstat -an | grep 514 udp 0 0 0.0:514 0. once for klogd to decode.1. # Options to syslogd # -m 0 disables 'MARK' messages. Here are the steps: • • Determine the IP address and fully qualified hostname of your remote logging host Add an entry in the /etc/hosts file in the format IP-address Example: 192. It also checks the file /etc/sysconfig/syslog to determine the various modes in which it should operate. You now have to configure your remote Linux client to send messages to it. Remember to restart syslog to make these changes take effect. This is done by editing the /etc/hosts file on the Linux client named smallfry.0. and # once for processing with 'ksymoops' # -x disables all klogd processing of oops messages entirely # See klogd(8) for more details KLOGD_OPTIONS="-2" You will have to restart syslog on the server for the changes to take effect.168.com As we saw previously.

o You can specify either “weekly” or “daily” rotation parameter.. In the case below the weekly option is "commented out" with a "#". switches. .d/lpd restart Stopping lpd: [ OK ] Starting lpd: [ OK ] [root@smallfry tmp]# Linux Server [root@bigboy tmp]# tail /var/log/messages . PIX firewalls.. The chapter on Miscellaneous Topics has examples of how to configure syslog to do this with Cisco devices using separate log files for the routers. CSS arrowpoints and LocalDirectors.Chapter 7: Configuring Syslog 67 You can now test to make sure that the syslog server is receiving the messages with a simple test such as restarting the lpd printer daemon and making sure the remote server sees the messages. allowing for daily updates.conf File This is logrotate’s general configuration file in which you can specify the frequency with which the files are reused. Syslog and Firewalls Syslog listens by default on UDP port 514. Logrotate Logrotate is a Linux utility that renames and reuses system error log files on a periodic basis so that they don't occupy excessive disk space... Linux Client [root@smallfry tmp]# /etc/init. Routers.. [root@bigboy tmp]# Syslog Configuration and Cisco Network Devices Syslog reserves facilities "local0" through "local7" for log messages received from remote servers and network devices. you'll have to allow traffic on this port to pass through the security device. Apr 11 22:09:35 smallfry lpd: lpd shutdown succeeded Apr 11 22:09:39 smallfry lpd: lpd startup succeeded .. switches.. The /etc/logrotate. . firewalls and load balancers each logging with a different facility can each have their own log files for easy troubleshooting. If you are logging to a remote syslog server via a firewall. ..

3 logfile.0 logfile.5 logfile.linuxhomenetworking.d Directory Most Linux applications that use syslog will put an additional configuration file in this directory to specify the names of the log files to be rotated.4 logfile.conf # rotate log files weekly #weekly # rotate log files daily daily # keep 4 weeks worth of backlogs #rotate 4 # keep 7 days worth of backlogs rotate 7 # create new (empty) log files after rotating old ones create The /etc/logrotate.log /var/log/cron { sharedscripts postrotate /bin/kill -HUP `cat /var/run/syslogd. while allowing 7 copies. The files will have the following names with "logfile" being current active version: logfile logfile. Here are some sample files which define the specific files to be rotated for each application. The /etc/logrotate.pid 2> /dev/null` 2> /dev/null || true endscript } .6 Sample contents of /etc/logrotate.d/syslog File (For General System Logging) /var/log/cisco/* /var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.68 www.1 logfile. It is a good practice to verify that all new applications that you want to use the syslog log have configuration files in this directory. In the case below the 4 copy option is "commented out" with a "#".2 logfile.com o o The "rotate" parameter specifies the number of copies of log files logrotate will maintain. The "create" parameter creates a new log file after each rotation Therefore our sample configuration file will create daily archives of ALL the logfiles and store them for seven days.

d/samba File (for SAMBA) /var/log/samba/*.d/syslog . then issue the logrotate command with just that filename as the argument like this: [root@bigboy tmp]# logrotate -f /etc/logrotate.d/apache File (For Apache) /var/log/httpd/access_log /var/log/httpd/agent_log /var/log/httpd/error_log /var/log/httpd/referer_log { missingok sharedscripts postrotate /bin/kill -HUP `cat /var/run/httpd.pid 2> /dev/null` 2> /dev/null || true endscript } Activating logrotate The above logrotate settings will not take effect until you issue the following command to do so: [root@bigboy tmp]# logrotate –f If you want logrotate to reload only a specifc configuration file.pid 2>/dev/null` 2> /dev/null || true endscript } The /etc/logrotate.log { notifempty missingok sharedscripts copytruncate postrotate /bin/kill -HUP `cat /var/lock/samba/*. and not all of them.Chapter 7: Configuring Syslog 69 The /etc/logrotate.

70 www.com .linuxhomenetworking.

com =========================================== This chapter covers how to configure your Linux box’s networking features. You can determine the IP address of this device with the "ifconfig" command. this device is called "eth0". How To Configure Your NIC's IP Address Determining Your IP Address Most modern PCs come with an ethernet port.Chapter 7: Configuring Syslog 71 Chapter 8 Linux Networking =========================================== In This Chapter Chapter 8 Linux Networking How To Configure Your NIC's IP Address How To Change Your Default Gateway How Configure Two Gateways How To Delete A Route How To View Your Current Routing Table How To Convert Your Linux Server Into A Router Configuring Your /etc/hosts File © Peter Harrison. When Linux is installed.linuxhomenetworking. www. [root@bigboy tmp]# ifconfig -a eth0 Link encap:Ethernet HWaddr 00:08:C7:10:74:A8 BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 .

255.100 and a subnet mask of 255.255 Mask:255.0. To make this permanent each time you boot up you'll have to add this command in your /etc/rc.255.local file.1.255.255. This can also be found in less detail in the file /proc/interrupts Changing Your IP Address If you wanted.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:47379 errors:0 dropped:0 overruns:0 frame:0 TX packets:107900 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:4676853 (4.168.0.7 Kb) TX bytes:82644 (80.7 Kb) wlan0 Link encap:Ethernet HWaddr 00:06:25:09:6A:B5 inet addr:192.99 Bcast:192. Interface wlan0 has an IP address of 192.168.255.0..72 www.. Linux also makes life a little easier with interface configuration files located in the /etc/sysconfig/network-scripts directory.0 b) TX bytes:0 (0.168.100 Bcast:192.d/rc. one assumes the interface has a fixed IP address. Interface eth0 has a file called ifcfg-eth0.255.0 up The "up" at the end of the command activates the interface. you could give this eth0 interface an IP address using the ifconfig command.0.1. You can place your IP address information in these files which are then used to auto-configure your NICs when Linux boots.1. .0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:787 errors:0 dropped:0 overruns:0 frame:0 TX packets:787 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:82644 (80.2 Mb) Interrupt:11 Memory:c887a000-c887b000 wlan0:0 Link encap:Ethernet HWaddr 00:06:25:09:6A:B5 inet addr:192.com collisions:0 txqueuelen:100 RX bytes:0 (0.4 Mb) TX bytes:43209032 (41.1.0 You can see that this command gives good information on the interrupts used by each card.255 Mask:255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:11 Memory:c887a000-c887b000 [root@bigboy tmp]# In this example.1. [root@bigboy tmp]# ifconfig eth0 10.0 b) Interrupt:11 Base address:0x1820 lo Link encap:Local Loopback inet addr:127.1 Mask:255.1 netmask 255.linuxhomenetworking.0. the other assumes it requires an IP address assignment using DHCP.168.0. eth1 uses ifcfg-eth1 .255. etc.168. eth0 has no IP address as this box is using wireless interface wlan0 as it's main NIC.255. Here are two samples for interface eth0.

255 IPADDR=192. IP aliasing is one of the most common ways of creating multiple IP addresses associated with a single NIC. Once you change the values in the configuration files for the NIC you'll have to deactivate and activate it for the modifications to take effect.255.1. a virtual sub-interface also known as an "IP alias".168. [root@bigboy network-scripts]# ifdown eth0 [root@bigboy network-scripts]# ifup eth0 Multiple IP Addresses On A Single NIC In the previous "determining your IP address" section you may have noticed that there were two wireless interfaces.0 ONBOOT=no [root@bigboy network-scripts]# Getting the IP Address using DHCP [root@bigboy tmp]# cd /etc/sysconfig/network-scripts [root@bigboy network-scripts]# more ifcfg-eth0 DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes [root@bigboy network-scripts]# As you can see eth0 will be activated on booting as the parameter ONBOOT has the value "yes" and not "no".168. You can read more about netmasks and DHCP on the introduction to networking chapter.1.168.255. One's named wlan0 and the other wlan0:0.1. Interface wlan0:0 is actually a "child" of interface wlan0.Chapter 8: Linux Networking 73 network-scripts File Formats Fixed IP Address [root@bigboy tmp]# cd /etc/sysconfig/network-scripts [root@bigboy network-scripts]# more ifcfg-eth0 DEVICE=eth0 BROADCAST=192. where "X" is the sub-interface number of your choice. Aliases have the name format "parent-interface-name:X". The ifdown and ifup commands can be used to do this.100 NETMASK=255.0 NETWORK=192. .

as of version 8.0 is rp-pppoe-3.255.0. RedHat Linux installs the rp-pppoe RPM software package required to support this.255. The PPPOE configuration will create a software based virtual interface named ppp0 that will use the physical Internet interface eth0 for connectivity.linuxhomenetworking. In this we want to create interface wlan0:0 Create the virtual interface with the ifconfig command [root@bigboy tmp]# ifconfig wlan0:0 192. broadcast address and gateway information provided by your ISP and you should have connectivity once you restart your interface.4-7. ########################################### [100%] 1:rp-pppoe ########################################### [100%] [root@bigboy tmp]# You’ll then need to go through a number of steps to complete the connection.local file to ensure the IP address is assigned properly when you reboot. By default. subnet mask. Your ISP will provide you with a PPPoE “username” and “password” which will allow your computer to login transparently to the Internet each time it boots up.99 \ netmask 255.i386.168.. then the configuration steps are the same as those outlined above.d/rc.com The process for creating an IP alias is very similar to the steps outlined for the real interface in the previous "changing your IP address" section.i386.1. If you need a refresher. o o o IP Address Assignment For A Direct DSL Connection If you are using a DSL connection with fixed or “static” IP addresses. The latest version of the RPM for RedHat 8. Here’s what you need to do: . Downloading and installing RPMs isn’t hard. Install the package using the following command: [root@bigboy tmp]# rpm -Uvh rp-pppoe-3.74 www. You plug your ethernet interface into the DSL modem.rpm. configure it with the IP address..rpm Preparing.0 up o You then have the choice of creating a /etc/sysconfig/network-scripts/ifcfg-wlan0:0 file or adding the ifconfig command used above to your /etc/rc.4-7. the chapter on RPMs covers how to do this in detail. First ensure the "parent" real interface exists Verify that no other IP aliases with the same name exists with the name you plan to use. If you are using a DSL connection with a DHCP or “dynamic” IP address assignment. then the process is different. Remember that you may also need to configure your DNS server correctly.

You may have some problems with demand-activated links.ifcfg-eth0 o Edit your ifcfg-eth0 file to have no IP information and also to be deactivated on boot time. lower-case. or stay up continuously? If you want it to come up on demand. enter the idle time in seconds after which the link should be dropped. (default eth0): Do you want the link to come up on demand. Welcome to the ADSL client setup. First.. For Linux.) NOTE: Demand-activated links do not interact well with dynamic IP addresses. where 'X' is a number. [root@bigboy [root@bigboy [root@bigboy ifcfg-eth0 [root@bigboy tmp]# tmp]# cd /etc/sysconfig/network-scripts/ network-scripts]# ls ifcfg-eth0 network-scripts]# cp ifcfg-eth0 DISABLED. DEVICE=eth0 ONBOOT=no o Shutdown your eth0 interface. I will run some checks on your system to make sure the PPPoE client is installed properly. [root@bigboy network-scripts]# ifdown eth0 [root@bigboy network-scripts]# o Run the adsl-setup configuration script [root@bigboy network-scripts]# adsl-setup o It will prompt you for your ISP username. LOGIN NAME Enter your Login Name (default root): bigboy-login@isp INTERFACE Enter the Ethernet interface connected to the ADSL modem For Solaris.. the interface to be used (eth0) and whether you want to the connection to stay up indefinitely. it will be ethX. enter 'no' (two letters. Enter the demand value (default no): .Chapter 8: Linux Networking 75 o Make a backup copy of your ifcfg-eth0 file. We’ll use defaults wherever possible. this is likely to be something like /dev/hme0. If you want the link to stay up permanently.

I’d recommend selecting “none” and using a variant of the basic script samples in the firewall chapter. DNS Please enter the IP address of your ISP's primary DNS server. If you just press enter. lower-case.STANDALONE: Appropriate for a basic stand-alone web-surfing workstation 2 . e-mail. You are responsible for ensuring the security of your machine. Note that these rules are very basic. FIREWALLING Please choose the firewall rules to use.) if you want to allow normal user to start or stop DSL connection (default yes): o The rp-pppoe package has two sample ipchains firewall scripts located in the /etc/ppp directory named firewall-standalone and firewall-masq. the rules will block outgoing SSH connections which allocate a privileged source port. If your ISP claims that 'the server will provide dynamic DNS addresses'. the firewall rules will deny access to all standard servers like Web.com o It will then prompt you for your DNS server information. however.linuxhomenetworking. If you’re running BIND on your server in a caching DNS mode then you may want to leave this option blank. I will assume you know what you are doing and not modify your DNS setup. these will provide basic security. This step will edit your /etc/resolv. If you want your ISP to automatically provide the IP address of its DNS server then enter the word “server”. or the more comprehensive one found in the Appendix. They are very basic and don’t cover rules to make your Linux box a web server.76 www. If you are running any servers on your machine. If you are using SSH. The firewall choices are: 0 . DNS server nor mail server. 1 . You are strongly encouraged to use a more sophisticated firewall setup. ftp.NONE: This script will not set any firewall rules. you must choose 'NONE' and set up firewalling yourself. etc. enter 'server' (all lower-case) here. Enter the DNS information here: o The script will then prompt you for your ISP password PASSWORD Please enter your Password: Please re-enter your Password: o Then it will ask whether you want regular users (not superuser “root”) to be able to activate/deactivate the new ppp0 interface USERCTRL Please enter 'yes' (two letters. Otherwise.conf file.MASQUERADE: Appropriate for a machine acting as an Internet gateway for a LAN Choose a type of firewall (0-2): 0 . You are STRONGLY recommended to use some kind of firewall rules.

Congratulations. Start this connection at boot time Do you want to start this connection at boot time? Please enter no or yes (default no):yes o Just before exiting. Most people would say “yes”. The first is the ifcfgppp0 file with interface’s link layer connection parameters [root@bigboy network-scripts]# more ifcfg-ppp0 USERCTL=yes BOOTPROTO=dialup NAME=DSLppp0 DEVICE=ppp0 TYPE=xDSL ONBOOT=yes PIDFILE=/var/run/pppoe-adsl.pid FIREWALL=NONE . Type '/sbin/adsl-status /etc/sysconfig/network-scripts/ifcfg-ppp0' to see the link status. you’ll get a summary of the parameters you entered and the relevant configuration files will be updated to reflect your choices when you accept them. it should be all set up! Type '/sbin/ifup ppp0' to bring up your xDSL link and '/sbin/ifdown ppp0'to bring it down. This command defaults to show information for interface ppp0 and therefore listing the ifcfg-ppp0 filename won’t be necessary in most home enviornments. ** Summary of what you entered ** Ethernet Interface: eth0 User name: bigboy-login@isp Activate-on-demand: No DNS: Do not adjust Firewalling: NONE User Control: yes Accept these settings and adjust configuration files (y/n)? y Adjusting /etc/sysconfig/network-scripts/ifcfg-ppp0 Adjusting /etc/ppp/chap-secrets and /etc/ppp/pap-secrets (But first backing it up to /etc/ppp/chap-secrets. Some Important Files Created By adsl-setup • The adsl-setup script creates three files that will be of interest to you. The above example recommends using the adsl-status command with the name of the PPPoE interface configuration file.Chapter 8: Linux Networking 77 o You’ll then be asked whether you want the connection to be activated upon booting.bak) (But first backing it up to /etc/ppp/pap-secrets.bak) o At the very end it will tell you the commands to use to activate /deactivate your new ppp0 interface and to get a status of the interface’s condition.

In this case the package has been installed but the interface hasn’t been activated. [root@bigboy network-scripts]# more /etc/ppp/pap-secrets # Secrets for authentication using PAP # client server secret IP addresses "bigboy-login@isp" * "password" [root@bigboy network-scripts]# Simple Troubleshooting • You can run the adsl-status command to determine the condition of your connection. adsl-status: Link is attached to ppp0.RUNNING.roaringpenguin. .linuxhomenetworking. the interface appears to work correctly. [root@bigboy tmp]# adsl-status Note: You have enabled demand-connection. but ppp0 is down [root@bigboy tmp]# • After activation. PPPOE_TIMEOUT=20 LCP_FAILURE=3 LCP_INTERVAL=80 CLAMPMSS=1412 CONNECT_POLL=6 CONNECT_TIMEOUT=60 DEFROUTE=yes SYNCHRONOUS=no ETH=eth0 PROVIDER=DSLppp0 USER= bigboy-login@isp PEERDNS=no [root@bigboy network-scripts]# • The others are the duplicate /etc/ppp/pap-secrets and /etc/ppp/chap-secrets files with the username and password needed to login to your ISP. There are some good tips there on how to avoid problems with VPN clients. [root@bigboy tmp]# ifup ppp0 [root@bigboy tmp]# adsl-status adsl-status: Link is up and running on interface ppp0 ppp0: flags=8051<UP.com).POINTOPOINT.78 www. adsl-status may be inaccurate.com PING=.MULTICAST> mtu 1462 inet … … … [root@bigboy tmp]# • For further troubleshooting information you can visit the website of rp-ppoe at Roaring Penguin (www.

0. please adjust your steps accordingly. This example uses a newly installed wireless interface called wlan0. wlan0 net 10. Here is a sample. You may be most likely using interface eth0.0.168. Add the new route as follows: route add -net 10.255.1.1 is connected to the same network as interface wlan0 ! Once done.254 wlan0 The file etc/sysconfig/static-routes will also have to updated so that the route is reinstated when you reboot. [root@bigboy tmp]# route add default gw 192.168.254 The Linux box used in this example uses interface wlan0 for its Internet connectivity. A more complicated /etc/sysconfig/static-routes file is located in a following section.255.local How Configure Two Gateways Some networks may have multiple router / firewalls providing connectivity.0 netmask 255. make sure that the router / firewall with IP address 192.0.254 Some people don't bother with this step and just place the "route add" command in the file /etc/rc. .0.0 netmask 255.1.d/rc.168. Here's a typical scenario: • You have one router providing access to the Internet which you'd like to have as your default gateway (See the default gateway example above) • You also have another router providing access to your corporate network using addresses in the range 10.0 to 10.local.168.1.d/rc. This file is used to configure your default gateway each time Linux boots.1. NETWORKING=yes HOSTNAME=bigboy GATEWAY=192.168.1 wlan0 In this case.1.1 Some people don't bother with this step and just place the "route add" command in the file /etc/rc.0.1.0 gw 192.0.0.255.0.168.Chapter 8: Linux Networking 79 How To Change Your Default Gateway This can be done with a simple command.0 gw 192.0. Let's assume that this router has an IP address of 192.0. you'll need to update your /etc/sysconfig/network file to reflect the change. most PCs would be using the standard ethernet interface eth0.

[root@bigboy tmp]# netstat -nr Kernel IP routing table Destination Gateway Genmask 255.254 How To View Your Current Routing Table The netstat -nr command will provide the contents of the touting table.0.96 172.0.192 172.com How To Delete A Route Here's how to delete the routes added in the previous section.0.0 255.0 0.0.255.255.68.0.224 172. route del -net 10.0.1.69.131 255.0 172.0.255.0. the default and one to 255.67.0.240.255.0 [root@bigboy tmp]# Flags UH U U UG MSS 40 40 40 40 Window 0 0 0 0 irtt 0 0 0 0 Iface wlan0 wlan0 lo wlan0 • In this example.0 255.0.linuxhomenetworking.0.0.0.135 255.0.168.0.0 172.0.0.255.0.128 172.255.1.16.0.0 172.255.255 0. Networks with a gateway of 0.0 gw 192.16.67.168.11.0.255 which is usually added on DHCP servers.0.67.0 seems appropriate.0.0 255.32 172. [root@bigboy tmp]# netstat -nr Kernel IP routing table Destination Gateway Genmask 172.168.128 0.0. • In this example there are two gateways.1 0.0.135 255.0.0.255.168. Server bigboy is a DHCP server in this case.16.255.255.69.16.0 gw 192.255.16.64 172.16.0.0 0.0.80 www.255.224 172.0 172.192 0.0.193 255.16.193 255.0.0 255.0 netmask 255.254 wlan0 The file etc/sysconfig/static-routes will also have to be updated so that when you reboot the server will not reinsert the route.68.16.0.255. there are multiple gateways handling traffic destined for different networks on different interfaces.16.0 0.193 0. As no gateway is needed to reach your own directly connected interface then an address of 0.0.255.0 [root@bigboy tmp]# Flags UG UG UG UG U U UG UG U UG MSS 40 40 40 40 40 40 40 40 40 40 Window 0 0 0 0 0 0 0 0 0 0 irtt 0 0 0 0 0 0 0 0 0 0 Iface eth1 eth1 eth1 eth0 eth1 eth0 eth0 eth0 lo eth1 • Here is what the static routes file looks like for this multi-homed (Multiple NICs) server .1.0.16.0 255.255.16.0 0.0 are usually directly connected to the interface.16.0.193 255.0.0 0.0. Delete the line that reads: wlan0 net 10.255.0 172.67.255.69.0.255.0.160.16.224 172.255.0.69.0 127.16.255.69.67.0 netmask 255.255 192.0.1.0.224 172.0 192.0.255.0 255.0.0 127.

This example is for interfaces eth0 and wlan0.255.255.ipv4. Here is how it's done: [root@bigboy tmp] echo 1 > /proc/sys/net/ipv4/ip_forward The next step needed will be activating proxy ARP. The router will reply with its MAC address which the server will use when forwarding the packet to the router. To activate the feature immediately you have to create a single lined text file called /proc/sys/net/ipv4/ip_forward and it only contain the value "1".68.69. you have to enable packet forwarding.193 [root@bigboy tmp]# How To Convert Your Linux Server Into A Router For your Linux server to become a router.local file .16.16. The configuration parameter to activate this is found in the file /etc/sysctl. The best way to do this is put the commands above in your /etc/rc. Proxy ARP activation needs to be done for each ethernet interface on your Linux box.Chapter 8: Linux Networking 81 [root@bigboy tmp]# more /etc/sysconfig/static-routes eth0 net 172.255.conf.224 gw 172.16.16.69.16.68.255.ip_forward=1 After # Disables packet forwarding net.135 eth0 net 172.67. Proxy ARP has to be enabled for the Linux box to answer ARP requests.224 gw 172.16.193 eth1 net 172.0.67.193 eth1 net 172.69. In simple terms packet forwarding lets packets flow through the Linux box from one network to another.224 gw 172.240.67.11.0 gw 172.255.0 netmask 255.32 netmask 255.255.255.d/rc.0 netmask 255.ip_forward=1 This will only enable it when you reboot at which time Linux will create a file in one of the subdirectories of the special RAM memory based /proc filesystem.0.131 eth0 net 172. All computers that need to communicate with a computer on another network send out an ARP request to get the Ethernet MAC address (separate from the IP address) of the most desirable router in their routing table.0.0 netmask 255.0 gw 172.67. Before # Disables packet forwarding #net.16.160.ipv4.64 netmask 255.16.16.255.16.224 gw 172.255.16.96 netmask 255.135 eth1 net 172. [root@bigboy tmp] echo 1 > /proc/sys/net/ipv4/conf/eth1/proxy_arp [root@bigboy tmp] echo 1 > /proc/sys/net/ipv4/conf/wlan0/proxy_arp (You can determine your network interface names with the ifconfig -a command) There is no purpose built configuration file to force Linux to do proxy ARP on booting. Remove the "#" from the line related to packet forwarding.

• The /etc/hosts file has the following format: ip-address fully-qualified-domain-name alias1 alias2 alias3 etc • The very first line should always look like this with "localhost" being the only alias: 127. You may also want to convert your new Linux router into a firewall to protect your home network.my-site.linuxhomenetworking. you'll have to update file. For ease of management.com echo 1 > /proc/sys/net/ipv4/conf/eth1/proxy_arp echo 1 > /proc/sys/net/ipv4/conf/wlan0/proxy_arp Remember to configure a default route on your Linux box to point to your Internet gateway. Configuring Your /etc/hosts File The /etc/hosts lists the name and IP address of local hosts.0. The Netfilter iptables pages show how to do this. if the IP address for that host changes.0.localdomain localhost • If you have a NIC card in the server. Your server will typically check this file before referencing DNS. then you have to add another entry in this file.localdomain hostname Your machine's name is listed with a DNS server IP-address hostname. First determine what your true hostname is: [root@bigboy mail]# hostname bigboy [root@bigboy mail]# o Add the corresponding entry in the /etc/hosts file for the NIC's IP address o Your NIC's /etc/hosts File Format Your machine's name is NOT listed with a DNS server IP-address hostname. Unfortunately. and also the local host's name and use the centralized DNS server handle the rest.com hostname Here are some examples: .1 localhost. if the name is found with a corresponding IP address then DNS won't be queried.82 www. it is best to limit entries in this file to just the loopback interface.

then just put the two or three aliases that you feel are most important.100 isn't part of any DNS domain 192.Chapter 8: Linux Networking 83 • Host bigboy with an IP address of 192.1.100 is the mail and web server for domain my-site.1.1.com with corresponding entries in the DNS zone file for my-site.168.100 bigboy.168.com 192.100 bigboy. If you server has multiple names.my-site.1.localdomain bigboy • Host bigboy with an IP address of 192.168.168.com bigboy mail www Note: Only have one line per IP address in this file. .

84

www.linuxhomenetworking.com

Chapter 8: Linux Networking

85

Chapter 9

Simple Network Troubleshooting
===========================================

In This Chapter Chapter 9
Simple Network Troubleshooting
How To See Your ARP Table How To Use "Ping" To Test Network Connectivity Using "traceroute" To Test Connectivity Viewing Packet Flow With TCPdump © Peter Harrison, www.linuxhomenetworking.com ===========================================

You will eventually find yourself trying to fix a network related problem. Here are some troubleshooting
tips to help you discover what the problem could be.

How To See MAC Addresses
There are times when you lose connectivity with another server that is directly connected to your local network. Taking a look at the ARP table of the server from which you are troubleshooting will help determine whether or not the remote server’s NIC is responding to any type of traffic from your Linux box. Lack of communication at this level may mean: • Either server may be disconnected from the network • There may be bad network cabling • A NIC may be disabled or the remote server may be shut down Here is a description of the commands you may use to determine ARP values • The "ifconfig -a" command will show you both the NIC's MAC address and the associated IP addresses of the server which you are currently logged in to.

86

www.linuxhomenetworking.com

[root@bigboy tmp]# ifconfig -a wlan0 Link encap:Ethernet HWaddr 00:06:25:09:6A:B5 inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:47379 errors:0 dropped:0 overruns:0 frame:0 TX packets:107900 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:4676853 (4.4 Mb) TX bytes:43209032 (41.2 Mb) Interrupt:11 Memory:c887a000-c887b000 wlan0:0 Link encap:Ethernet HWaddr 00:06:25:09:6A:B5 inet addr:192.168.1.99 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:11 Memory:c887a000-c887b000 [root@bigboy tmp]# Here you can see the wlan0 interface has two IP addresses 192.168.1.100 and 192.168.1.99 tied to the NIC hardware MAC address of 00:06:25:09:6A:B5 • The "arp -a" command will show you the MAC addresses in your server's ARP table. Here we see we have some form of connectivity with the router at address 192.168.1.1 [root@bigboy root]# arp -a bigboypix (192.168.1.1) at 00:09:E8:9C:FD:AB [ether] on wlan0 ? (192.168.1.101) at 00:06:25:09:6A:D7 [ether] on wlan0 [root@bigboy root]# • You should also check the ARP table of the remote server to see whether it is populated with acceptable values too.

How To Use "Ping" To Test Network Connectivity
Whether or not your troublesome server is connected to your local network it is always a good practice to force a response from it. One of the most common methods used to test connectivity across multiple networks is the "ping" command. Ping sends ICMP “echo” type packets that request a corresponding ICMP “echo-reply” response from the device at the target address. As most servers will respond to a ping query it becomes a very handy tool. A lack of response could be due to: • A server with that IP address doesn't exist • The server has been configured not to respond to pings • A firewall or router along the network path is blocking ICMP traffic • You have incorrect routing. Check routes on the local, remote servers and all routers in between. A classic symptom of bad routes on a server is the ability to only ping servers on your local network and nowhere else. There are a variety of ICMP response codes which can help in further troubleshooting. See the appendix for a full listing of them.

Chapter 9: Simple Network Troubleshooting

87

The Linux ping command will send continuous pings, once a second, until stopped with a <Ctrl-C>. Here is an example of a successful ping to the server bigboy at 192.168.1.100 [root@smallfry tmp]# ping 192.168.1.101 PING 192.168.1.101 (192.168.1.101) from data. 64 bytes from 192.168.1.101: icmp_seq=1 64 bytes from 192.168.1.101: icmp_seq=2 64 bytes from 192.168.1.101: icmp_seq=3 64 bytes from 192.168.1.101: icmp_seq=4

192.168.1.100 : 56(84) bytes of ttl=128 ttl=128 ttl=128 ttl=128 time=3.95 time=7.07 time=4.46 time=4.31 ms ms ms ms

--- 192.168.1.101 ping statistics --4 packets transmitted, 4 received, 0% loss, time 3026ms rtt min/avg/max/mdev = 3.950/4.948/7.072/1.242 ms [root@smallfry tmp]# You may get a "Destination Host Unreachable" message if your router or server knows that the target IP address is part of a valid network, but is getting no response from the target server. The network device sends an ICMP reply type 3 which triggers the message. [root@smallfry tmp]# ping 192.168.1.105 PING 192.168.1.105 (192.168.1.105) from 192.168.1.100 : 56(84) bytes of data. From 192.168.1.100 icmp_seq=1 Destination Host Unreachable From 192.168.1.100 icmp_seq=2 Destination Host Unreachable From 192.168.1.100 icmp_seq=3 Destination Host Unreachable From 192.168.1.100 icmp_seq=4 Destination Host Unreachable From 192.168.1.100 icmp_seq=5 Destination Host Unreachable From 192.168.1.100 icmp_seq=6 Destination Host Unreachable --- 192.168.1.105 ping statistics --8 packets transmitted, 0 received, +6 errors, 100% loss, time 7021ms, pipe 3 [root@smallfry tmp]#

Using "traceroute" To Test Connectivity
Another tool for network troubleshooting is the traceroute command. It gives a listing of all the router hops between your server and the target server. This helps you verify that routing over the networks in between is correct. Traceroute works by sending a UDP packet destined to the target with a TTL of "0". The first router on the route recognizes that the TTL has already been exceeded and discards or “drops” the packet, but also sends an ICMP "time exceeded" message back to the source. The traceroute program records the IP address of the router that sent the message and knows that that is the first hop on the path to the final destination. The traceroute program tries again, with a TTL of "1". The first hop, sees nothing wrong with the packet, decrements the TTL to 0 as expected, and forwards the packet to the second hop on the path. Router 2, sees the TTL of "0", drops the packet and replies with an ICMP time exceeded message. Traceroute now knows the IP address of the second router. This continues around and around until the final destination is reached.

88

www.linuxhomenetworking.com

Here is a sample output for a query to 144.232.20.158: [root@bigboy root]# traceroute 144.232.20.158 traceroute to 144.232.20.158 (144.232.20.158), 30 hops max, 38 byte packets 1 adsl-67-120-221-110.dsl.sntc01.pacbell.net (67.120.221.110) 14.304 ms 14.019 ms 16.120 ms 2 dist3-vlan50.sntc01.pbi.net (63.203.35.67) 12.971 ms 14.000 ms 14.627 ms 3 bb1-g1-0.sntc01.pbi.net (63.203.35.17) 15.521 ms 12.860 ms 13.179 ms 4 bb2-p11-0.snfc21.pbi.net (64.161.124.246) 13.991 ms 15.842 ms 15.728 ms 5 bb1-p14-0.snfc21.pbi.net (64.161.124.53) 16.133 ms 15.510 ms 15.909 ms 6 sl-gw11-sj-3-0.sprintlink.net (144.228.44.49) 16.510 ms 17.469 ms 18.116 ms 7 sl-bb25-sj-6-1.sprintlink.net (144.232.3.133) 16.212 ms 14.274 ms 15.926 ms 8 * * * 9 * * [root@bigboy root]# If there is no response within a 5 second timeout interval a "*" is printed for that probe. Possible causes of this and other traceroute status messages are listed below:

Possible Traceroute Messages
Traceroute Symbol *** Description Time exceeded. Could be caused by: • A router on the path not sending back the ICMP "time exceeded" messages • A router or firewall in the path blocking the ICMP "time exceeded" messages • The target IP address not responding Host, network or protocol unreachable Communication administratively prohibited. A router Access Control List (ACL) or firewall is in the way Source route failed. Source routing attempts to force traceroute to use a certain path. Failure may be due to a router security setting

!H, !N, or !P !X or !A !S

Some devices will prevent traceroute packets directed at their interfaces, but will allow ICMP packets. Using traceroute with a “-I” flag forces traceroute to use ICMP packets that may go through. In this case the "* * *", status messages disappear. [root@bigboy root]# traceroute -I 144.232.20.158 traceroute to 144.232.20.158 (144.232.20.158), 30 hops max, 38 byte packets 1 adsl-67-120-221-110.dsl.sntc01.pacbell.net (67.120.221.110) 14.408 ms 14.064 ms 13.111 ms

Chapter 9: Simple Network Troubleshooting

89

2 dist3-vlan50.sntc01.pbi.net (63.203.35.67) 13.018 ms 12.887 ms 13.146 ms 3 bb1-g1-0.sntc01.pbi.net (63.203.35.17) 12.854 ms 13.035 ms 13.745 ms 4 bb2-p11-0.snfc21.pbi.net (64.161.124.246) 16.260 ms 15.618 ms 15.663 ms 5 bb1-p14-0.snfc21.pbi.net (64.161.124.53) 15.897 ms 15.785 ms 17.164 ms 6 sl-gw11-sj-3-0.sprintlink.net (144.228.44.49) 14.443 ms 16.279 ms 15.189 ms 7 sl-bb25-sj-6-1.sprintlink.net (144.232.3.133) 16.185 ms 15.857 ms 15.423 ms 8 sl-bb23-ana-6-0.sprintlink.net (144.232.20.158) 27.482 ms 26.306 ms 26.487 ms [root@bigboy root]#

Always Get A Bidirectional Traceroute
It is always best to get traceroutes from the source IP to the target IP and also from the target IP to the source IP. This is because the packet's return path from the target is sometimes not the same as the path taken to get there. A high traceroute time equates to the round trip time for both the initial traceroute query to each “hop” and the response of each “hop”. Here is an example of one such case, using disguised IP addresses and provider names. There was once a routing issue between telecommunications carriers FastNet and SlowNet. When a user at IP address 40.16.106.32 did a traceroute to 64.25.175.200, a problem seemed to appear at the 10th. hop with OtherNet. However, when a user at 64.25.175.200 did a traceroute to 40.16.106.32, latency showed up at hop 7 with the return path being very different. In this case, the real traffic congestion was occurring where FastNet handed traffic off to SlowNet in the second trace. The latency appeared to be caused at hop 10 on the first trace not because that hop was slow, but because that was the first hop at which the return packet traveled back to the source via the congested route. Remember, traceroute gives the packet round trip time. Trace route to 40.16.106.32 from 64.25.175.200 1 0 ms 0 ms 2 0 ms 0 ms 3 0 ms 0 ms [207.174.144.169] 4 0 ms 0 ms 5 0 ms 0 ms 6 0 ms 0 ms 7 0 ms 0 ms 8 30 ms 30 ms 9 30 ms 30 ms 10 1252 ms 1212 ms 11 1252 ms 1212 ms 12 1262 ms 1212 ms 13 1102 ms 1091 ms 0 0 0 0 0 0 0 30 30 1202 1192 1192 1092 [64.25.175.200] [64.25.175.253] border-from-40-tesser.boulder.co.coop.net [64.25.128.126] p3-0.dnvtco1-cr3.othernet.net [4.25.26.53] p2-1.dnvtco1-br1.othernet.net [4.24.11.25] p15-0.dnvtco1-br2.othernet.net [4.24.11.38] p15-0.snjpca1-br2.othernet.net [4.0.6.225] p1-0.snjpca1-cr4.othernet.net [4.24.9.150] h0.webhostinc2.othernet.net [4.24.236.38] [40.16.96.11] [40.16.96.162] [40.16.106.32]

Trace route to 64.25.175.200 from 40.16.106.32 1 2 3 4 1 1 2 1 ms ms ms ms 1 1 1 1 ms ms ms ms 1 1 1 1 ms ms ms ms [40.16.106.3] [40.16.96.161] [40.16.96.2] [40.16.96.65]

11.64.9.slownet.17.61] p9-0.cointcorp.30] p4-3.17.2.1 rtr-2.13] p6-0.200] Ping & Traceroute Troubleshooting Example In this example.29] svl-core-03.othernet.77] 6 2 ms 1 [216.22.6.linuxhomenetworking.paix-bi1.253] [64.93] [186.net [205.223.com 5 2 ms 2 [216. Each “bounce” causes the TTL to decrease by a count of one until the TTL reaches zero at which point you get the timeout.94 and 186.net [208. Approximate round trip times in milli-seconds: Minimum = 0ms.171.othernet.171.153 gave a “TTL timeout” message.64. Ping TTLs will usually only timeout if there is a routing loop in which the packet bounces between two routers on the way to the target.205.153] over a maximum of 30 hops: 1 2 3 4 5 6 <10 60 70 60 70 60 ms ms ms ms ms ms <10 70 71 70 70 70 ms ms ms ms ms ms <10 60 70 60 70 61 ms ms ms ms ms ms 186.snjpca1-br2. transit.0.130] p3-0.64. Received = 4.net rtr-1.confusion.webh02-1.net ms ms ms ms ms ms ms ms ms ms ms ms ms ms sjo-edge-03.64.64.40.153: Packets: Sent = 4.128.boulder.33.net [4.94: TTL TTL TTL TTL expired expired expired expired in in in in transit.52. Ping statistics for 186.153 with 32 bytes of data: Reply Reply Reply Reply from from from from 186.net [4.9.64.net [64.inet. Average = 0ms G:\>tracert 186.93.94] [186.slownet.175. The routing loop was confirmed by the traceroute in which the packet was proven to be bouncing between routers at 186.17.25.99] [64.171.24.inet.94: 186.33] sjo-core-01.26] p0-0.0.37] p1-0.17.9.othernet.17.slownet.94] [186.153 Tracing route to lostserver.40.fastnet.confusion.9.226] p15-0.confusion.64.ge0-1-net2.40.17.40. transit.25.93] [186.5.7.fastnet.49.net [4.40.90 www.net [4.net rtr-2.11.54] gw234.19.dnvtco1-cr3.dnvtco1-br2.p4-2.64.confusion. Maximum = 0ms.othernet.64.153 Pinging 186.net ms core1.net rtr-2.dnvtco1-br1.64.94: 186.40.52.94] .26.9. transit.net [205.confusion.97] [205.net [4. G:\>ping 186.175.25.65] 7 993 ms 961 8 1009 ms 1008 9 985 ms 947 10 1028 ms 1010 11 989 ms 988 12 1002 ms 1001 13 1031 ms 989 14 1031 ms 1017 15 1027 ms 1025 16 1045 ms 1037 17 1030 ms 1020 18 1038 ms 1031 19 1050 ms 1094 20 1050 ms 1094 ms 1 ms 1 ms ms ms ms ms ms ms ms ms ms ms ms ms ms 999 971 983 953 985 973 978 1017 1023 1050 1045 1045 1034 1034 ms border8.64.25.net [4. a ping to 186.othernet.40.94: 186.net [186.coop.40.46.24.net [4.inet.24.co.9.sfj.snjpca1-br1.othernet.confusion.9.sfj.24.othernet.40.net [186.40.net rtr-1.217.40. Lost = 0 (0% loss).

Chapter 9: Simple Network Troubleshooting 91 7 70 ms 70 ms 8 60 ms 70 ms 9 70 ms 70 ms .40.94] rtr-1... The constant activity eventually corrupted the routing tables of one of the routers.confusion. The problem was initially triggered by an unstable network link that caused frequent routing recalculations. Do a traceroute from this router to your intended target server. (!H or !N messages may be produced. The router immediately after the last visible one is the one at which the routing changes. Look at the routing table to determine what the next hop is to your intended traceroute target. The last visible hop being the last hop in which the packets return correctly.net [186. . Do a traceroute back to your source server. or turned off. If this works: Routing to the target server is OK.40.93] This problem was solved by resetting the routing process on both routers. these include: o Traceroute packets are being blocked or rejected by a router in the path. .) The network on which you expect the target host to reside doesn’t exist in the routing table of one of the routers in the path (!H or !N messages may be produced.93] rtr-2.net [186. If it doesn’t work: Test the routing table and/or other status of all the hops between it and your intended target. It could be disconnected.confusion. It’s usually good to: log on to the last visible router. then the last visible router of an incomplete trace is either the last good router on the path. Note: If there is nothing blocking your traceroute traffic. The target server doesn’t exist on the network... The router immediately after the last visible one is usually the culprit. Trace complete.. Possible Reasons For Failed Traceroutes Traceroutes can fail to reach their intended destination for a number of reasons.40.64. o o o o o . or the last router that has a valid return path to the server issuing the traceroute. 70 ms 60 ms 70 ms rtr-1.64.confusion. It’s usually good to check the routing table and/or other status of this next hop device.) You may have a typographical error in the IP address of the target server You may have a routing loop in which packets bounce between two routers and never get to the intended destination. The traceroute will probably fail at the bad router on the return path. Log on to this next hop router.net [186.. The packets don’t have a proper return path to your server.64.

then tcpdump will use the lowest numbered interface that is UP Don't print a timestamp at the beginning of each line You can also add expressions after all the command line switches. It is installed by default on RedHat linux and has very simple syntax. You can also use keywords such as "and" or "or" between expressions to further fine tune your selection criteria. interfaces of devices in the packet flow • The server not listening on the port because the software isn't installed or started Analyzing tcpdump in much greater detail is beyond the scope of this section. Listen on interface. Like most Linux commands. One of the most common uses of tcpdump is to determine whether you are getting basic two way communication. These act as filters to limit the volume of data presented on the screen.linuxhomenetworking. Some useful expressions include: . tcpdump uses command line switches to modify the output.com Viewing Packet Flow With TCPdump Tcpdump is one of the most popular packages for viewing the flow of packets through your Linux box's NIC card. If this is not specified. Some of the more useful command line switches would include: Possible TCPdump Messages tcpdump command switch -c -i -t Description Stop after viewing count packets.92 www. especially if you are doing simpler types of troubleshooting. Lack of communication could be due to: • Bad routing • Faulty cables.

my-site.962244 bigboy.927510 bigboy.my-site.com > smallfry: 21:48:58.928257 smallfry > bigboy.com: 21:48:58.my-site.com > smallfry: 21:48:58.my-site.my-site.my-site.com > smallfry: 21:48:58.my-site.968556 bigboy.944034 bigboy.928365 bigboy.com > smallfry: 21:48:58.com: 21:48:58.Chapter 9: Simple Network Troubleshooting 93 Useful TCPdump Expressions tcpdump command expression host host-address icmp tcp port port-number Description View packets from the IP address host-address View icmp packets View TCP packets with packets with either a source or destination TCP port of portnumber View UDP packets with either a source or destination UDP port of port-number udp port port-number Example: tcpdump used to view ICMP "ping" packets going through interface wlan0 [root@bigboy tmp]# tcpdump -i wlan0 icmp tcpdump: listening on wlan0 21:48:58.com > smallfry: 9 packets received by filter 0 packets dropped by kernel [root@bigboy tmp]# Explanation o o o o The first column of data is a packet time stamp.com: 21:48:58.my-site. The second column of data shows the packet source then destination IP address or server name of the packet The third column shows the packet type Two way communication is occurring as each echo gets an echo reply icmp: icmp: icmp: icmp: icmp: icmp: icmp: icmp: icmp: echo echo echo echo echo echo echo echo echo request (DF) reply request (DF) reply request (DF) reply reply reply reply .927091 smallfry > bigboy.943926 smallfry > bigboy.my-site.com > smallfry: 21:48:58.963966 bigboy.

nop.com.my-site.ssh > smallfry.ssh > smallfry.my-site.ssh: 5840 <mss 1460.32938: R 0:0(0) ack 1 win 0 (DF) [tos 0x10] 9 packets received by filter 0 packets dropped by kernel [root@bigboy root]# Explanation o o o o The first column of data shows the packet source then destination IP address or server name of the packet The second column shows the TCP flags within the packet The client named "bigboy" is using port 32938 to communicate with the server named "smallfry" on the TCP SSH port 22.my-site.nop.com.com.com Example: tcpdump used to view packets on interface wlan0 to/from host 192.wscale 0> (DF) [tos R 0:0(0) ack 2013297021 win 0 S 2013297020:2013297020(0) win 0.1.ssh > smallfry.wscale 0> (DF) [tos R 0:0(0) ack 1 win 0 (DF) [tos S 2013297020:2013297020(0) win 0.my-site.wscale 0> (DF) [tos R 0:0(0) ack 1 win 0 (DF) [tos R 0:0(0) ack 1 win 0 (DF) [tos bigboy.1.ssh: 5840 <mss 1460.linuxhomenetworking.32938: (DF) [tos 0x10] smallfry.ssh > smallfry.32938: 0x10] S 2013297020:2013297020(0) win 0.ssh: 5840 <mss 1460.timestamp 75227931 0x10] bigboy.com.com.32938: 0x10] smallfry.ssh > smallfry.my-site.timestamp 75227931 0x10] bigboy.32938 > bigboy. Two way communication is occuring .com.my-site.com.my-site.nop.sackOK.my-site.94 www.168.ssh > smallfry.168.32938: R 0:0(0) ack 1 win 0 (DF) [tos 0x10] bigboy.32938: 0x10] bigboy.my-site.102 on TCP port 22 with no timestamps in the output [root@bigboy root]# tcpdump -i wlan0 -t host 192.32938 > bigboy.com.32938 > bigboy.sackOK.com.102 and tcp port 22 tcpdump: listening on wlan0 smallfry.timestamp 75227931 0x10] bigboy.sackOK.

Chapter 9: Simple Network Troubleshooting 95 .

96 www.linuxhomenetworking.com .

or have upgraded your RedHat distribution’s kernel then you can refer to the sections on how to install WLAN from universally usable tar files.org for the latest hardware compatibility list. . www. As of version 8. RedHat did not ship with the Linux Wireless driver set (Linux-WLAN) installed. You have to download and install them after installing Linux.linux-wlan. Wireless Linux Compatible NICs Not all wireless NIC cards work with Linux-WLAN.97 Chapter 10 Linux Wireless Networking =========================================== In This Chapter Chapter 10 Linux Wireless Networking Wireless Linux Compatible NICs Linux-WLAN Preparation Installing The Linux-WLAN Drivers Post Installation Steps Linux-WLAN Encryption For Security Troubleshooting Your Wireless LAN © Peter Harrison.com =========================================== This chapter will show you how to configure wireless NIC cards on your Linux box. If you are not running RedHat Linux. For this reason it may be good to keep your regular Ethernet NIC installed in the machine to provide connectivity to the web until you get the wireless NIC to work.0. or you could ask someone to burn a CD with the files needed for installation.linuxhomenetworking. For this reason it is best to check the Linux-WLAN group’s website at www.

the original WMP won’t work without upgrading the firmware. but the newer version 2.o: insmod wlan0 failed .linuxhomenetworking.7 as being an incompatible device. Installing the WMP11 v2.org site's hardware compatibility page now lists the WMP v2.0 Network controller: BROADCOM Corporation: Unknown device 4301 (rev01) Subsystem: Unknown device 1737:4301 Flags: bus master.7” which is very clearly stamped on the front side of these cards. fast devsel. Be careful as this message can also be due to you using an SSID in your configuration files that doesn’t match the SSID of your WAP / wireless router.18-14/net/prism2_pci. frame dropped.18-14/net/prism2_pci. The linux-wlan.7 with the linux-WLAN tarball will give the following error in the log file /var/log/messages 00:0c. your Linux box may not detect your NIC card at all and you will get kernel error messages like this one in /var/log/messages after you finish installing the software. including invalid IO or IRQ parameters.com The Linksys WMP11 NIC and Linux You have to be especially carefull with Linksys WMP series of wireless PCI cards. You can determine whether you have this model by looking for the “V2.7 card using a Broadcom chipset will not. non-prefetchable) [size=3D8K] Capabilities: [40] Power Management version 2 Installing the WMP11 v2.o: init_module: No such device Dec 1 01:28:14 bigboy insmod: Hint: insmod errors can be caused by incorrect module parameters.7 WMP 11 Card This card uses the Linux-WLAN compatible Intersil chipset and doesn’t have any version number stamped on it. Pre Version 2.7 Card In September 2002. The older version of the card that uses the Intersil chipset works with Linux. latency 64. You’ll have to download and install the latest firmware for a card from the Linksys website. Linksys launched a Version 2.7 (or v2.7) model of the WMP11 card using a Broadcom chipset. Aug 25 21:07:06 hostname kernel: p80211knetdev_hard_start_xmit: Tx attempt prior to association. IRQ 5 Memory at f4000000 (32-bit.4.98 www. then install the card in a windows box and upgrade the firmware. You may find more information in syslog or the output from dmesg Dec 1 01:28:14 bigboy insmod: /lib/modules/2.4. Even so. If you don't. The WMP 11 Version 2.7 with the linux-WLAN tarball using RPMs will give the following error message on the screen: Dec 1 01:28:14 bigboy insmod: /lib/modules/2.

the RPM chapter covers how to do this in detail. always use the uname version.Chapter 10: Linux Wireless Networking 99 Linux-WLAN Preparation All devices on a wireless network must use the same “Network Identifier” or SSID in order to communicate with each other. Once configured.unixguru. Always use the most recent versions to reduce the installation mental stress. It’s a good idea to decide on a common SSID and stick with it. This step isn't necessary for true PCI cards such as the Linksys WMP11. Download the latest version of linux-wlan RPM. The latest version as of this writing was: kernel-pcmcia-cs-3. Linux-WLAN doesn’t identify the wireless NIC as an Ethernet “eth” device. According to the linux-wlan documentation. The Bigboy server discussed in the Topology chapter is running a i586 version of Linux. If you need a refresher. Installing The Linux-WLAN Drivers Linux-WLAN Installation . [root@bigboy tmp]# uname -p i586 [root@bigboy tmp]# . If you need a refresher. PCMCIA Type Card Specific Information Before installing the linux-wlan software for PCMCIA type cards such as the (Linksys WPC11) you will need to install the RedHat Linux "pcmcia-cs" RPM package.i386. Determining The Kernel Type Use the "uname -p" command. this will have to be done from a source RPM. Remember to download the files for the correct kernel type.1. You may get "device unknown" or "no such device" errors related to the wlan device in the /var/log/messages file if you use older unpatched versions of the Linux-WLAN software. the RPM chapter covers how to do this in detail. It is a good source of information.rpm Downloading and installing RPMs isn’t hard.31-9. The syslog chapter will also show you how to set up syslog error logging to be more sensitive to error types.nc. Downloading and installing RPMs isn’t hard. Always be prepared to check your syslog /var/log/messages file for errors if things don't work. This is good to know in order to avoid confusion when troubleshooting. The Linux version may not match the CPU you have installed. RPM versions of the driver files can be found at http://prism2.us.Using RPMs 2. The default SSID for Linux-WLAN is “linux-wlan”. but as a “wlan” device.raleigh. the default SSID for your windows NIC cards may be different. OS version and kernel version.

daily]# more /etc/issue Red Hat Linux release 8. I have seen the kernel-wlan-ng-pcmcia rpm installation give errors stating that the kernel-pcmcia-cs rpm hadn't been previously installed even when it had been. Installing the rpm with --force and --nodeps switches does the trick by forcing the installation while not checking for dependencies. /etc/wlan.rh80.opts files which you may have to restore from the automatically saved versions. However.4.0 [root@bigboy cron. module and interface packages.com Determining The OS Version One of the easiest ways is to view the /etc/issue file.1.18-14 [root@bigboy tmp]# uname -r 2. The combined Linux / Linux-WLAN upgrade will also create new versions of your /etc/sysconfig/network-scripts/ifcfg-wlan0. Always remember that under normal circumstances this wouldn’t be a good idea.rpm [root@bigboy tmp]# rpm -Uvh kernel-wlan-ng-pci-0.rpm If you get any error messages during the installation.155.rh80. 3.daily]# Determining The Kernel Version You can use the "uname -r" command to do this.conf and /etc/pcmcia/wlanng.4. Bigboy is running version 2. In this case.i586.0 [root@bigboy tmp]# rpm -Uvh kernel-wlan-ng-0.linuxhomenetworking.140. then you're doing something wrong. you'll have to do these steps all over again.18-14 [root@bigboy tmp]# If you upgrade the version of your Linux.rpm [root@bigboy tmp]# rpm -Uvh kernel-wlan-ng-modules-rh80. Once you have all this information. error messages are there for a reason.100 www.i586.155.i586.15-5. . Bigboy is running version 8.1.1.rh80. you’ll need to download and install the base. Here are examples for a i586 installation using a PCI card on Redhat 8.0 (Psyche) Kernel \r on an \m [root@bigboy cron.

If you are running standard RedHat Linux use the RPMs unless you have excess patience.14 linux-wlan-ng-0. Adjust accordingly.14]# make clean linux-wlan-ng-0.14]# make config .156.14-pre1.tar tmp]# cd linux-wlan-ng-0.1..15-6. ########################################### [100%] 1:kernel-wlan-ng-pcmcia ########################################### [100%] Adding prism2_cs alias to /etc/modules.. The default wlan0 network configuration is DHCP.1. ACHTUNG! ATTENTION! WARNING! YOU MUST configure /etc/pcmcia/wlan-ng.4. Starting PCMCIA services: modules cardmgr. [root@bigboy tmp]# rpm -Uvh kernel-source-2.14-pre1.org.Chapter 10: Linux Wireless Networking 101 [root@smallfry tmp]# rpm -Uvh kernel-wlan-ng-pcmcia-0.1.tar. It is therefore important to install your kernel sources files.linux-wlan.gz Unzip and install the Linux-WLAN files [root@bigboy [root@bigboy [root@bigboy [root@bigboy [root@bigboy tmp]# gunzip linux-wlan-ng-0.4.gz tmp]# tar -xvf linux-wlan-ng-0.1.rpm error: Failed dependencies: kernel-pcmcia-cs is needed by kernel-wlan-ng-pcmcia-0.1.1.opts to match WAP settings!!! [root@smallfry tmp]# Linux-WLAN Installation – Using TAR files If you are running a non standard version of your RedHat kernel or using a version of Linux that is incompatible with RPMs.rpm Download And Install The Linux-WLAN TAR File Download the latest version of Linux-WLAN from www.18-3. Shutting down PCMCIA services: cardmgr modules. Remember that if you upgrade your Linux version or kernel. then you’ll need to use the TAR file installation method.1. For RedHat version 7.i686.15-6 [root@smallfry tmp]# rpm -Uvh --force --nodeps kernel-wlan-ngpcmcia-0..1.14-pre1.18-3.i686. you'll probably have to do these steps all over again Install the Kernel Source Files Installing Linux-WLAN using TAR files involves compiling the software to make it match the particular flavor of the Linux kernel you are running..conf file.3 it was version 2.i386. The most recent version as of this writing was: linux-wlan-ng-0.tar.rpm Preparing.1.

1. Get a directory listing of /lib/modules/ beforehand to make sure you are providing the correct kernel directory that both matches your kernel version and that also actually has files in it. Select only a single module directory as using more than one can lead to future "make" problems. You can also test these commands from the command line to see if they work.1.d directory [root@bigboy tmp]# vi /etc/init. Create a startup driver configuration file called wmp11 (or whatever you NIC card is named) in the /etc/init.conf and insert the following line to load the driver on booting: alias wlan0 prism2_pci 2. The response should be: .14]# make all [root@bigboy linux-wlan-ng-0. #!/bin/bash modprobe prism2_pci wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable wlanctl-ng wlan0 lnxreq_autojoin ssid=linux_wlan authtype=opensystem exit 0 Remember to modify the SSID in the above commands to match that of your WAP. and usb driver questions When you are prompted for the "Module install directory" enter /lib/modules/”linux-kernelversion”. where “linux-kernel-version“ is the version of the kernel. plx. Add the following 4 lines to the file.14]# make install o Configure The New wlan0 Interface Driver (PCI Cards) 1.102 www. and usb driver questions (PCMCIA cards only) Say 'y' to pcmcia and 'n' to pci.linuxhomenetworking. Edit /etc/modules.d/wmp11 3. plx. Use other defaults =========================================== [root@bigboy linux-wlan-ng-0.com =========================================== Running “make config” command will prompt you for information: o o o (PCI cards only) Say 'y' to pci and 'n' to pcmcia.

This may not be a problem for many installations.local file instead and save yourself a lot of grief.d/rc.d tmp]# ls *network* (Verify the "network" tmp]# ln -s . may fail to start if the interface is down. and also it will cause the system to try to bring up wlan0 before the PCMCIA services.d/wmp11 be run before "S10network" during the boot process. which won't work. the "Link" LED on your NIC card will come on solid. then start over making sure you are using the latest versions of the Linux-WLAN software. If you don’t want to use the /etc/rc. DHCP server. but applications such as Samba./init. The next step is to create a link to this file in the startup directories. DNS (named) and SSH.local.d/rc. the system needs to load the drivers for the interface before it will activate the interface.d/wmp11 S09wmp11 Configure The New wlan0 Interface Driver (PCMCIA Cards) Open and edit the configuration options file. . /etc/pcmcia/wlan-ng.d tmp]# ln -s ..Chapter 10: Linux Wireless Networking 103 message=lnxreq_autojoin ssid=linksys authtype=opensystem resultcode=success If you get a resultcode=error or something else.d is named "S10network".d and /etc/rc5. Make the file executable so that it will be able to run on the next system reboot. as it has established a link with the WAP11 access point. [root@bigboy [root@bigboy filename) [root@bigboy [root@bigboy [root@bigboy tmp]# cd /etc/rc3..local file then you need to ensure that you run your custom driver script before the Linux "network" script starts up the wlan0 interface device you will create later./init. when configured to specifically run on the IP address of your interface.opts. At this time. Some web sites recommend putting the driver loading commands in /etc/rc.d/wmp11 5. You will need to create a symbolic link called "S09wmp11" to make /etc/init.conf. but this makes the driver load at the end of the booting process and the wlan0 interface will be inactive till then. If your applications are set to promiscuous listening.d/wmp11 S09wmp11 tmp]# cd /etc/rc5. which is the default setting for the applications above. as it is not neccessary. 4. Locate the lines containing "ssid=linux_wlan" and set the SSID to whatever value you’ve decided to use on your wireless LAN. When booting. In RedHat the default network startup script link in /etc/rc3. it may not matter and you could put these commands in your /etc/rc. NOTE: Never alias for the PCMCIA cards in /etc/modules. [root@bigboy tmp]# chmod 755 /etc/init.d/rc.

GATEWAY=192. netmask. eg.1. .255.255 IPADDR=192.1 o o Disable Your Existing Ethernet NIC You may want to disable your existing eth0 Ethernet interface after installing the drivers. network. This will disable the interface on reboot or when /etc/init.d/network is restarted.linuxhomenetworking.com Post Installation Steps Configure The New wlan0 Interface Edit /etc/sysconfig/network-scripts/ifcfg-wlan0 to include the following lines: DHCP Version ============ DEVICE=wlan0 USERCTL=yes ONBOOT=yes BOOTPROTO=dhcp Fixed IP Version ================= DEVICE=wlan0 BROADCAST=192.104 www.0 ONBOOT=yes In the fixed IP version you will also need to: Substitute your selected IP.168.168.1.opts file (PCMCIA type NICs) configuration file.255.1. Select the Wireless mode and SSID Edit your /etc/wlan.100 NETMASK=255.1. broadcast address with those above.168. Edit /etc/sysconfig/network-scripts/ifcfg-eth0 file to have an ONBOOT=no entry. Locate the lines containing "ssid=linux_wlan" and set the SSID to whatever value you’ve decided to use on your wireless LAN. Make sure you have correct gateway statement in your /etc/sysconfig/network file.168.conf file (PCI type NIC) or your /etc/pcmcia/wlan-ng. Also modify the IS_ADHOC option to make your NIC either support "adhoc" mode for peer to peer networks or "infrastructure" mode if you are using a WAP.0 NETWORK=192.

#=======SELECT STATION MODE=================== IS_ADHOC=n # y|n. Inspect your /var/log/messages file again: [root@bigboy tmp]# tail -300 /var/log/messages Look carefully for any signs that the card is interfering with existing card IRQs. If that is the case." message. or otherwise eliminate the conflict by disabling the conflicting device if you don’t really need it. . y . move the card to a different slot. or "IRQ also used by.d/wlan restart PCI Cards – Installed Using TAR Files [root@bigboy tmp]# /etc/init.d/wmp11 [root@bigboy tmp]# /etc/init.Chapter 10: Linux Wireless Networking 105 Here is a sample snippet. Insert the card in an empty slot in your Linux box and reboot.infrastructure #=======INFRASTRUCTURE STATION START=================== # SSID is all we have for now AuthType="opensystem" # opensystem | sharedkey (requires WEP) # Use DesiredSSID="" to associate with any AP in range DesiredSSID="linksys" Simulate a Reboot Run the following commands and test for errors in the file /var/log/messages: PCI Cards – Installed Using RPMs [root@bigboy tmp]# /etc/init.. If there is a conflict there will usually be a warning.adhoc. n .d/network restart Now check to see IP address of the wlan interface is OK [root@bigboy tmp]# ifconfig -a [root@bigboy tmp]# ping <gateway-address> Check For Interrupt Conflicts Before installing the software you should ensure that the wireless NIC card doesn’t have an interrupt that clashes with another device in your computer.d/network restart PCMCIA Cards [root@bigboy tmp]# /etc/rc.d/pcmcia restart [root@bigboy tmp]# /etc/init.d/init..

the base memory address which was used by Linux to communicate with the cards were different.0. newer PCI based systems generally handle conflicts better.linuxhomenetworking.100 Bcast:192.1 Mask:255.0 b) Interrupt:11 Base address:0x1820 lo Link encap:Local Loopback inet addr:127. you can also inspect your /proc/interrupts file for multiple devices having the same interrupt [root@bigboy tmp]# more /proc/interrupts 11: 4639 XT-PIC wlan0.5 Mb) TX bytes:126738425 (120.255.0.106 www.8 Mb) Interrupt:11 Memory:c887a000-c887b000 [root@bigboy tmp]# . You can check both the interrupts and base memory of your NIC cards after doing the software installation by using the "ifconfig -a" command: [root@bigboy tmp]# ifconfig -a eth0 Link encap:Ethernet HWaddr 00:08:C7:10:74:A8 BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:0 (0.com After you’ve installed the software. The above (bad) /proc/interrupts example came from a functioning PCI based Linux box.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:215233 errors:0 dropped:0 overruns:0 frame:0 TX packets:447594 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:39394014 (37. eth0 [root@bigboy tmp]# more /proc/interrupts 11: 4639 XT-PIC wlan0 (bad) (good) Interrupt conflicts are usually more problematic with old style PC-AT buses.1.1.0.255 Mask:255.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:88418 errors:0 dropped:0 overruns:0 frame:0 TX packets:88418 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:7678679 (7.255.168.0.3 Mb) TX bytes:7678679 (7.168. the reason why it worked was that though the interrupt was the same.3 Mb) wlan0 Link encap:Ethernet HWaddr 00:06:25:09:6A:B5 inet addr:192.0 b) TX bytes:0 (0.

Settings only matter if PrivacyInvoked is true lnxreq_hostWEPEncrypt=false # true|false lnxreq_hostWEPDecrypt=false # true|false dot11PrivacyInvoked=true dot11WEPDefaultKeyID=1 dot11ExcludeUnencrypted=true # true|false. Set genstr or keys. use PRIV_GENTSTR to generate # keys (just a convenience) PRIV_GENERATOR=/sbin/nwepgen # nwepgen.opts file (PCMCIA type NICs) file is also used to activate this feature. Only migrate to an encrypted design after you are satisfied that the unencrypted design works satisfactorily. Note: I must strongly recommend that you first set up your network without encryption. you have to set the "dot11PrivacyInvoked" parameter to "true" and state which of the keys will be used as the default starting key via the "dot11WEPDefaultKeyID" parameter. and intra-network communication will be impossible. 01:20:03:40:05 or dot11WEPDefaultKey3= # 01:02:03:04:05:06:07:08:09:0a:0b:0c:0d Not all devices on your network will use the same algorithm method to generate the encryption keys. Neesus compatible PRIV_KEY128=false # keylength to generate PRIV_GENSTR="ketchup" # or set them explicitly. You then have the option of either providing a key generating string (simple password) or all four of the keys. you can use the /sbin/nwepgen program to generate the keys once you provide your easy to remember key generator string. Here is how you can use nwepgen to create the keys with a generator string of "ketchup". "ketchup" is the password used to automatically generate the keys. To invoke encryption.opts) file and set the PRIV_GENSTR parameter to "". In the example below.conf file (PCI type NIC) or the /etc/pcmcia/wlanng. If this is the case. With encryption. You may find the same generator string will not create the same keys. the client must have a membership encryption password which can also be represented as a series of Wireless Encryption Protocol (WEP) keys. you'll have to add them them individually and in sequence to the /etc/wlan. #=======WEP=========================================== # [Dis/En]able WEP. [root@bigboy tmp]# /sbin/nwepgen ketchup 64:c1:a1:cc:db 2b:32:ed:37:16 b6:cc:9e:1b:37 d7:0e:51:3f:03 [root@bigboy tmp]# . dot11WEPDefaultKey0= # format: xx:xx:xx:xx:xx or dot11WEPDefaultKey1= # xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx dot11WEPDefaultKey2= # e. in AP this means WEP # is required for all STAs # If PRIV_GENSTR is not empty.conf (or /etc/pcmcia/wlan-ng. The /etc/wlan. Once you have the four sets of keys. not both.Chapter 10: Linux Wireless Networking 107 Linux-WLAN Encryption For Security One of the flaws of wireless networking is that all the wireless clients can detect the presence of all available network SSIDs and have the option of joining any of them.g.

not both. and remove the Linux-WLAN related entries using rmmod [root@bigboy tmp]# lsmod Module Size … … prism2_pci 66672 p80211 20328 … … Used by Not tainted 1 1 (autoclean) [prism2_pci] [root@bigboy tmp]# rmmod prism2_pci [root@bigboy tmp]# rmmod p80211 o Restart Linux-WLAN and reactivate the wlan0 interface and you should be functional again. Set genstr or keys.d/wlan start Starting WLAN Devices:message=lnxreq_hostwep resultcode=no_value decrypt=false encrypt=false [root@bigboy tmp]# ifup wlan0 . [root@bigboy tmp]# /etc/init.d/wlan stop Shutting Down WLAN Devices:message=lnxreq_ifstate ifstate=disable resultcode=success [root@bigboy tmp]# ifdown wlan0 o Even though you have done these two steps. The steps to reverse encryption are: o o Set the configuration file parameter "dot11PrivacyInvoked" to "false" Stop Linux-WLAN and disable the wireless wlan0 interface [root@bigboy tmp]# /etc/init.108 www. dot11WEPDefaultKey0= 64:c1:a1:cc:db dot11WEPDefaultKey1= 2b:32:ed:37:16 dot11WEPDefaultKey2= b6:cc:9e:1b:37 dot11WEPDefaultKey3= d7:0e:51:3f:03 Remember that all devices on your network will need to have the same keys and default key for this to work.com In this case your /etc/wlan. NIC cards without full Linux-WLAN compatibility will freeze up after a number of hours of working with encryption. the driver is still loaded in memory. This includes all wireless NICs and WAPs De-activating Encryption In some cases. though not active.linuxhomenetworking.conf file would look like this: PRIV_GENSTR="" # or set them explicitly. Your next steps will be to list all the active drivers in memory with the lsmod command.

Jan 2 18:11:18 bigboy kernel: hfa384x_drvr_start: Failed. result=110 Troubleshooting Your Wireless LAN Always check the /var/log/messages file for possible errors arising from the software installation.Chapter 10: Linux Wireless Networking 109 o If you fail to reload the driver modules you’ll get errors like these below in your /var/log/messages file. You can also check to see if your Linux box is out or range of the WAP.result=-110 Jan 2 18:11:18 bigboy kernel: hfa384x_docmd_wait: hfa384x_cmd timeout(1). . If there are no errors in /var/log/messages and you can’t ping your gateways or obtain an IP address. frame dropped. p80211 Kernel errors in /var/log/messages usually point to an incorrectly configured SSID Nov 13 22:24:54 bigboy kernel: p80211knetdev_hard_start_xmit: Tx attempt prior to association. Jan 2 18:11:18 bigboy kernel: hfa384x_drvr_start: Initialize command failed. then check your /etc/sysconfig/network-scripts/ifcfg-wlan0 file for a correct IP configuration and your routing table to make sure your routes are OK. Jan 2 18:11:12 bigboy kernel: prism2sta_ifstate: hfa384x_drvr_start() failed. The chapter on logging covers how to do this in more detail. reg=0x8021.

linuxhomenetworking.com .110 www.

www.111 Chapter 11 Linux Firewalls Using iptables =========================================== In This Chapter Chapter 11 Linux Firewalls Using iptables What Is iptables? Download And Install The Iptables Package How To Get iptables Started Packet Processing In iptables Iptables Packet Flow Diagram Processing For Packets Routed By The Firewall Packet Processing For Data Received By The Firewall Packet Processing For Data Sent By The Firewall Targets And Jumps Descriptions Of The Most Commonly Used Targets Important Iptables Command Switch Operations General Iptables Match Criteria Common TCP and UDP Match Criteria Common ICMP (Ping) Match Criteria Common Match Extensions Criteria Using User Defined Chains Sample iptables Scripts Basic Initialization Allowing DNS Access To Your Firewall Allowing WWW And SSH Access To Your Firewall Allowing Your Firewall To Access The Internet Allow Your Home Network To Access The Firewall Masquerading (Many to One NAT) Port Forwarding Type NAT Static NAT Logging & Troubleshooting © Peter Harrison.linuxhomenetworking. This page shows how to convert your Linux box into: .com =========================================== You can convert your Linux box into a firewall using the IPtables package.

. The latest version of the RPM for RedHat 8. It had a number of limitations.112 www.d/iptables start [root@bigboy tmp]# /etc/init.rpm Preparing. Each of these queue is dedicated to a particular type of packet activity and is controlled by an associated packet transformation / filtering chain. iptables has now become the default firewall package installed under RedHat Linux...linuxhomenetworking.d/iptables stop [root@bigboy tmp]# /etc/init. As a result of this.6a-2. the primary one being that it ran as a separate program and not as part of the kernel. Don’t worry if this all seems confusing. The Netfilter organization decided to create a new product called iptables in order to rectify this shortcoming. the chart and graphic below describe the steps taken by iptables when a packet traverses the firewall. web and DNS server. ########################################### [100%] 1:iptables ########################################### [100%] [root@bigboy tmp]# How To Get iptables Started You can start/stop/restart iptables after booting by using the following commands: [root@bigboy tmp]# /etc/init. Download And Install The Iptables Package Most RedHat Linux software products are available in the RPM format.d/iptables restart To get iptables configured to start at boot: [root@bigboy tmp]# chkconfig --level 345 iptables on Packet Processing In iptables All packets inspected by iptables pass through a sequence of built-in tables (queues) for processing.6a-2.com • A firewall while simultaneously being your home website's mail.rpm. • A router that will use NAT and port forwarding to both protect your home network and have another web server on your home network while sharing the public IP address of your firewall What Is iptables? Originally. iptables is considered a faster and more secure alternative.0 is iptables-ipv6-1.2.i386. the chapter on RPMs covers how to do this in detail. there’ll be tables and examples of how the concepts are all interlinked. If you need a refresher. Install the package using the following command: [root@bigboy tmp]# rpm -Uvh iptables-ipv6-1.2. Downloading and installing RPMs isn’t hard.i386. the most popular firewall / NAT package running on Linux was ipchains. For example.

Chapter 11: Linux Firewalls Using iptables 113 Iptables Packet Flow Diagram .

114 www. Source network address translation (SNAT) N/A Packet enters the NIC and is passed to iptables Mangle Nat PREROUTING Packet passed to the Linux routing engine N/A N/A Packet passed back to iptables Filter FORWARD Nat POSTROUTING Packet transmitted out the other NIC N/A N/A .linuxhomenetworking. (Rarely used) Destination network address translation (DNAT) N/A Determines whether the packet is destined to a local application or should be sent out another NIC interface Packet filtering: Packets destined for servers accessible by another NIC on the firewall.com Processing For Packets Routed By The Firewall Packet flow Intercepted by iptables chain (Queue) Packet transformation table associated with this queue PREROUTING Description of possible modifications by iptables using this transformation table Modification of the TCP packet quality of service bits.

The packet is intercepted by the iptables mangle. then nat queues mangle nat PREROUTING Destination network address translation (DNAT) Packet filtering: Packets destined for the firewall. The packet is then passed from iptables to the Linux routing engine. The routing engine passes the packet to the target application via the iptables filter queue filter INPUT The application receives the packet from iptables then processes it. .Chapter 11: Linux Firewalls Using iptables 115 Packet Processing For Data Received By The Firewall Packet flow Actions by Operating System Packet intercepted by iptables table (Queue) Packet transformation chain associated with this queue PREROUTING Description of possible modifications by iptables using this transformation table Modification of the TCP packet quality of service bits. (Rarely used) Packet destined for firewall Packet enters the NIC from remote server.

Source network address translation (SNAT) filter OUTPUT The packet is then passed to the Linux routing engine which forwards the packet out the correct NIC The packet is intercepted by the iptables nat table nat POSTROUTING Packet transmitted out a NIC .116 www. nat and filter tables mangle OUTPUT Modification of the TCP packet quality of service bits.linuxhomenetworking.com Packet Processing For Data Sent By The Firewall Packet flow Actions by Operating System Packet intercepted by iptables table (Queue) Packet transformation chain associated with this queue Description of possible modifications by iptables using this transformation table The application sends data to a remote server Packet originating from firewall The packet is intercepted by iptables which then processes it in the mangle. (Rarely used) nat OUTPUT Source network address translation (Rarely used) Packet filtering: Packets destined for other servers / devices.

the second will DROP it. you can create your own chains. These include: icmp-port-unreachable (default) icmp-net-unreachable icmp-host-unreachable icmp-proto-unreachable icmp-net-prohibited icmp-host-prohibited tcp-reset echo-reply DNAT • Used to do Destination Network Address Translation. Descriptions Of The Most Commonly Used Targets Target ACCEPT Description • iptables stops further processing. • The packet is blocked • The packet information is sent to the syslog daemon for logging • iptables continues processing with the next rule in the table • As you can't LOG and DROP at the same time. • The packet is handed over to the end application or the operating system for processing • iptables stops further processing. • Works like the DROP target. So in summary.Chapter 11: Linux Firewalls Using iptables 117 Targets And Jumps You don't have to rely solely on the built-in chains provided by iptables. it is common to have two similar rules in sequence. There are a number of built-in targets that most rules may use.rewriting the destination IP address of the --to-destination ipaddress Tells iptables what the destination IP . Frequently used to tell why the logged packet was dropped REJECT --reject-with qualifier The qualifier tells what type of reject message is returned. The first will LOG the packet. but will also return an error message to the host sending the packet that was blocked N/A Most common options DROP N/A LOG --log-prefix "string" Tells iptables to prefix all log messages with a user defined string. These can be accessed by making them the targets of "jumps" in the built-in chains. ie. the targets/jumps tell the rule what to do with a packet that matches the rule perfectly.

ie. .com Target packet SNAT Description Most common options address should be --to-source <address>[<address>][:<port>-<port>] Specifies the source IP address and ports to be used by SNAT.rewriting the source IP address of the packet • By default the source IP address is the same as that used by the firewall's interface MASQUERADE [--to-ports <port>[-<port>]] Specifies the range of source ports the original source port can be mapped to. ie.linuxhomenetworking.118 www.rewriting the source IP address of the packet • The source IP address is user defined • Used to do Source Network Address Translation. • Used to do Source Network Address Translation.

168.1 -p TCP -j ACCEPT In this example iptables is being configured to allow the firewall to accept TCP packets coming in on interface eth0 from any IP address destined for the firewall's IP address of 192.Chapter 11: Linux Firewalls Using iptables 119 Important Iptables Command Switch Operations We’ll now explore how to use iptables command switches used to create your firewall. all Match source IP address Match destination IP address Match "input" interface on which the packet enters. udp.1. As discussed before. icmp. General Iptables Match Criteria iptables command Switch -t <table> Description If you don't specify a table. tcp. then the filter table is assumed. Types include. Deletes all the rules in the selected table Match protocol. mangle Append rule to end of a chain Flush. nat.1 .1. the possible built-in tables include: filter. Match "output" interface on which the packet exits -A -F -p <protocol-type> -s <ip-address> -d <ip-address> -i <interface-name> -o <interface-name> Example: iptables -A INPUT -s 0/0 -i eth0 -d 192.168.

58 -o eth1 -p TCP \ -sport 1024:65535 -dport 80 -j ACCEPT In this example iptables is being configured to allow the firewall to accept TCP packets to be routed when they enter on interface eth0 from any IP address destined for IP address of 192.1.168.com Common TCP and UDP Match Criteria switches used with -p tcp --sport <port> TCP source port Can be a single value or a range in the format: start-portnumber:end-portnumber TCP destination port Can be a single value or a range in the format: starting-port:endingport Used to identify a new connection request ! --syn means. not a new connection request --sport <port> TCP source port Can be a single value or a range in the format: starting-port:endingport Description switches used with -p udp Description --dport <port> --dport <port> TCP destination port Can be a single value or a range in the format: starting-port:endingport --syn Example: iptables -A FORWARD -s 0/0 -i eth0 -d 192.58 that is reachable via interface eth1. The source port is in the range 1024 to 65535 and the destination port is port 80 (www/http) .linuxhomenetworking.120 www.1.168.

port> A variety of TCP/UDP source ports separated by commas A variety of TCP/UDP destination ports separated by commas A variety of TCP/UDP ports separated by commas. Common Match Extensions Criteria TCP/UDP match extensions used with -m multiport --sport <port. Source and destination ports are assumed to be the same. Description --dport <port. port> --dport <port. port> .Chapter 11: Linux Firewalls Using iptables 121 Common ICMP (Ping) Match Criteria Matches used with ---icmp-type --icmp-type <type> The most commonly used types are echo-reply and echo-request Description Example: iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT In this example iptables is being configured to allow the firewall send ICMP echo-requests (pings) and in turn. accept the expected ICMP echo-replies.

Example: iptables -A FORWARD -s 0/0 -i eth0 -d 192.58 to be accepted too.58 that is reachable via interface eth1.168. We are also allowing the return packets from 192.com Match extensions used with -m state --state <state> Description The most frequently tested states are: ESTABLISHED The packet is part of a connection which has seen packets in both directions NEW The packet is the start of a new connection RELATED The packet is starting a new secondary connection.linuxhomenetworking.58 -o eth1 -p TCP \ -sport 1024:65535 -m multiport -dport 80.1.443 -j ACCEPT iptables -A FORWARD -d 0/0 -o eth0 -s 192.58 -i eth1 -p TCP \ -m state --state ESTABLISHED -j ACCEPT This is an expansion on the previous example.168.1. The source port is in the range 1024 to 65535 and the destination ports are port 80 (www/http) and 443 (https).168. This is a common feature of protocols such as an FTP data transfer. . Here iptables is being configured to allow the firewall to accept TCP packets to be routed when they enter on interface eth0 from any IP address destined for IP address of 192.122 www. it is sufficient to allow packets related to established connections using the -m state and --state ESTABLISHED options.1. Instead of stating the source and destination ports.168.1. or an ICMP error.

110. For example. This feature is frequently used to help streamline the processing of packets. Example: iptables -A INPUT -i eth0 -d 206. it is possible to have a chain that determines the protocol type for the packet and then hands off the actual final processing to a protocol specific chain.2 -j fast-input-queue iptables -A OUTPUT -o eth0 -s 206. In other words.229.229.Chapter 11: Linux Firewalls Using iptables 123 Using User Defined Chains As stated in the introduction. iptables can be configured to have user-defined chains.110.2 -j fast-output-queue iptables -A fast-input-queue -p icmp -j icmp-queue-in iptables -A fast-output-queue -p icmp -j icmp-queue-out iptables -A icmp-queue-out -p icmp --icmp-type echo-request \ -m state --state NEW -j ACCEPT iptables -A icmp-queue-in -p icmp --icmp-type echo-reply -j ACCEPT In this example we have six queues with the following characteristics to help assist in processing speed: Chain INPUT Description The regular built-in INPUT chain in iptables The regular built-in OUTPUT chain in iptables Input chain dedicated to specific protocols Output chain dedicated to specific protocols Output queue dedicated to ICMP Intput queue dedicated to ICMP OUTPUT fast-input-queue fast-output-queue icmp-queue-out icmp-queue-in . you can replace a long chain with a main stubby chain pointing to multiple stubby chains thereby shortening the total length of all chains the packet has to pass through. instead of having a single chain for all protocols.

Additional ALLOW rules should be added to the end of this script snippet. • Outbound passive FTP access from the firewall There are also simpler code snippets in the Appendix for: • Inbound and outbound FTP connections to / from your firewall Basic Initialization It is a good policy. It shows you how to allow your firewall to: • Be used as a Linux Web / Mail / DNS server • Be the NAT router for your home network • Prevent various types of attacks using corrupted TCP. The "basic initialization" script snippet should also be included in all your scripts to ensure the correct initialization of your chains should you decide to restart your script after startup. FORWARD and OUTPUT chains should DROP packets by default for the best security. It is best to invoke these from your /etc/rc. The "filter" table's INPUT.linuxhomenetworking.com Sample iptables Scripts Here are some sample scripts you can use to get iptables working for you. #!/bin/bash #--------------------------------------------------------------# Load modules for FTP connection tracking and NAT – You may need # them later #--------------------------------------------------------------modprobe ip_conntrack_ftp modprobe iptable_nat #--------------------------------------------------------------# Initialize all the chains by removing all the rules # tied to them #--------------------------------------------------------------iptables --flush iptables -t nat --flush . it is not good policy to make your "nat" and "mangle" tables DROP packets by default. to initialize your chain and table settings with known values. Pay special attention to the logging example at the end. UDP and ICMP packets. then they will not reach the the INPUT. This chapter also includes other snippets that will help you get basic functionality. You then can use the Appendix to find a detailed script once you feel more confident.local file so that the firewall script is run every time you boot up. This is because these tables are queried before the "filter" table. FORWARD and OUTPUT chains and won't be processed. However. It should be a good guide to get you started. and if all packets that don't match the "nat" and "mangle" rules are DROP-ped.124 www. in any iptables script you write.d/rc.

the user defined # chains should be deleted.Chapter 11: Linux Firewalls Using iptables 125 iptables -t mangle --flush #--------------------------------------------------------------# Now that the chains have been initialized. We'll recreate them in the next step #--------------------------------------------------------------iptables --delete-chain iptables -t nat --delete-chain iptables -t mangle --delete-chain #--------------------------------------------------------------# If a packet doesn't match one of the built in chains.Interface eth0 is the internet interface # # Zone transfers use TCP and not UDP. Most home networks # / websites using a single DNS server won’t require TCP statements # #--------------------------------------------------------------iptables -A OUTPUT -p udp -o eth0 --dport 53 --sport 1024:65535 \ -j ACCEPT iptables -A INPUT -p udp -i eth0 --sport 53 --dport 1024:65535 \ -j ACCEPT . #--------------------------------------------------------------# Allow outbound DNS queries from the FW and the replies too # # . The following statements will apply not only for firewalls acting as DNS clients but also for firewalls working in a caching or regular DNS server role. then # The policy should be to drop it #--------------------------------------------------------------iptables --policy INPUT DROP iptables --policy OUTPUT DROP iptables --policy FORWARD DROP #--------------------------------------------------------------# The loopback interface should accept all traffic # Necessary for X-Windows and other socket based services #--------------------------------------------------------------iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT Allowing DNS Access To Your Firewall You’ll almost certainly want your firewall to make DNS queries to the Internet.

#--------------------------------------------------------------# Allow port 80 (www) and 443 (https) connections to the firewall #--------------------------------------------------------------iptables -A OUTPUT -j ACCEPT -m state --state NEW \ -o eth0 –p tcp -m multiport --dport 80. Inbound packets destined for ports 80 and 22 are allowed thereby making the first steps in establishing a connection.Interface eth0 is the internet interface #--------------------------------------------------------------iptables -A INPUT -j ACCEPT -m state --state ESTABLISHED. Connections initiated by persons logged into the webserver will be denied as outbound NEW connection packets aren't allowed. HTTPS is also used by RedHat Linux servers using up2date. It isn't necessary to specify these ports for the return leg as outbound packets for all established connections are allowed.Interface eth0 is the internet interface #--------------------------------------------------------------iptables -A OUTPUT -o eth0 -m state --state ESTABLISHED.126 www. TCP port 80 is used for HTTP traffic and port 443 is used for HTTPS (secure HTTP frequently used for credit card transactions).443 --sport 1024:65535 #--------------------------------------------------------------# Allow previously established connections # .RELATED \ -j ACCEPT #--------------------------------------------------------------# Allow port 80 (www) and 22 (SSH) connections to the firewall #--------------------------------------------------------------iptables -A INPUT -p tcp -i eth0 --dport 22 –sport 1024:65535 \ -m state –state NEW -j ACCEPT iptables -A INPUT -p tcp -i eth0 --dport 80 –sport 1024:65535 \ -m state –state NEW -j ACCEPT Allowing Your Firewall To Access The Internet The following iptables sample script allows a user on the firewall to use a web browser to surf the Internet. #--------------------------------------------------------------# Allow previously established connections # .RELATED -i eth0 –p tcp \ .com Allowing WWW And SSH Access To Your Firewall This sample snippet is for a web server that is managed remotely by its system administrator via secure shell (SSH) sessions.linuxhomenetworking.

while only packets related to ESTABLISHED connections will be allowed inbound. Once masquerading has been achieved using the POSTROUTING chain of the "nat" table.0 network. More specifically. eth1 is directly connected to a home network using IP addresses from the 192. #--------------------------------------------------------------# Allow all bidirectional traffic from your firewall to the # protected network # . This is done using the FORWARD chain of the "filter" table. traffic from all devices on one or more protected networks will appear as if it originated from a single IP address on the Internet side of the firewall. iptables will have to be configured to allow packets to flow between the two interfaces. All traffic between this network and the firewall is simplistically assumed to be trusted and allowed. In other words. This helps to protect the home network from persons trying to initiate connections from the Internet. types of connections and possibly even remote servers to have access to your firewall and home network. packets related to NEW and ESTABLISHED connections will be allowed outbound to the Internet. This is done by enabling "IP forwarding" or routing by giving the file /proc/sys/net/ipv4/ip_forward the value "1" as opposed to the default disabled value of "0".1.0/24 -i eth1 -j ACCEPT -p all -d 192.1.443 --sport 1024:65535 Allow Your Home Network To Access The Firewall In this example.168.Interface eth1 is the private network interface #--------------------------------------------------------------iptables -A INPUT iptables -A OUTPUT -j ACCEPT -p all -s 192.Chapter 11: Linux Firewalls Using iptables 127 If you want all TCP traffic originating from the firewall to be accepted then you can remove the following section from the snippet above: -m multiport --dport 80.0/24 -o eth1 Masquerading (Many to One NAT) As explained in the Introduction to Networking chapter. Further rules will be needed for the interface connected to the Internet to allow only specific ports. An example follows: .1. Masquerading also depends on the Linux operating system being configured to support routing between the internet and private network interfaces of the firewall.168. iptables requires the iptables_nat module to be loaded with the "modprobe" command for the masquerade feature to work. masquerading is another word for what many call "many to one" NAT.168.

RELATED state \ -j ACCEPT state \ -j ACCEPT Note: If you configure your firewall to do masquerading. Routing too will have to be allowed in iptables with the FORWARD chain. the remote server’s IP address and the source/destination port of the traffic can be used to uniquely identify a traffic flow. If their Linux firewall is their interface to the Internet and they want to host a website on one of the NAT protected home servers then they will have to use the “port forwarding” technique.com #--------------------------------------------------------------# Load the NAT module #--------------------------------------------------------------modprobe iptable_nat #--------------------------------------------------------------# Allow masquerading # Enable routing by modifying the ip_forward /proc filesystem file # .168. All traffic that matches a particular combination of these factors may then be forwarded to a single server on the private network.1. # Allowed outbound: New.0/24 -d 0/0 \ -j MASQUERADE echo 1 > /proc/sys/net/ipv4/ip_forward #--------------------------------------------------------------# Prior to masquerading. then if should be the used as the default gateway for all your servers on the network. Port forwarding is handled by the PREROUTING chain of the "nat" table. the packets are routed via the filter # table's FORWARD chain. An example follows: .linuxhomenetworking.Interface eth0 is the internet interface # . established and related connections # Allowed inbound : Established and related connections #--------------------------------------------------------------iptables -A FORWARD -t filter -i eth1 -m --state NEW. Here the combination of the firewall's single IP address.Interface eth1 is the private network interface #--------------------------------------------------------------iptables -A POSTROUTING -t nat -o eth0 -s 192.ESTABLISHED. Port Forwarding Type NAT (DHCP DSL) In many cases home users may get a single DHCP public IP address from their ISP.128 www. this would include all NEW inbound connections from the Internet matching the port forwarding port plus all future packets related to the ESTABLISHED connection in both directions. the iptables_nat module will have to be loaded and routing enabled for port forwarding to work.RELATED iptables -A FORWARD -t filter -i eth0 -m --state ESTABLISHED. As in masquerading.

1.200 # # Enable routing by modifying the ip_forward /proc filesystem file # .*://'`" #--------------------------------------------------------------# Allow port forwarding for traffic destined to port 80 of the # firewall’s IP address to be forwarded to port 8080 on server # 192.Chapter 11: Linux Firewalls Using iptables 129 #--------------------------------------------------------------# Load the NAT module #--------------------------------------------------------------modprobe iptable_nat #--------------------------------------------------------------# Get the IP address of the Internet interface eth0 (linux only) # # You'll have to use a different expression to get the IP address # for other operating systems which have a different ifconfig output # or enter the IP address manually in the PREROUTING statement # # This is best when your firewall gets its IP address using DHCP.200 \ --dport 8080 --sport 1024:65535 -m state --state NEW -j ACCEPT iptables -A FORWARD -t filter -i eth1 -m state \ --state NEW.Interface eth0 is the internet interface # .RELATED -j ACCEPT .168.168. the packets are routed via the filter table's # FORWARD chain. # Connections on port 80 to the target machine on the private # network must be allowed.RELATED -j ACCEPT iptables -A FORWARD -t filter -i eth0 -m state \ --state ESTABLISHED.1. # The external IP address could just be hard coded (“typed in # normally”) #--------------------------------------------------------------external_int="eth0" external_ip="`ifconfig $external_int | grep 'inet addr' | \ awk '{print $2}' | sed -e 's/.1.ESTABLISHED. #--------------------------------------------------------------iptables -A FORWARD -p tcp -i eth0 -o eth1 -d 192.168.Interface eth1 is the private network interface #--------------------------------------------------------------iptables -t nat -A PREROUTING -p tcp -i eth0 -d $external_ip \ --dport 80 --sport 1024:65535 -j DNAT --to 192.200:8080 echo 1 > /proc/sys/net/ipv4/ip_forward #--------------------------------------------------------------# After DNAT.

#--------------------------------------------------------------# Load the NAT module #--------------------------------------------------------------modprobe iptable_nat #--------------------------------------------------------------# Enable routing by modifying the ip_forward /proc filesystem file #--------------------------------------------------------------echo 1 > /proc/sys/net/ipv4/ip_forward #--------------------------------------------------------------# NAT ALL traffic: # # TO: FROM: MAP TO SERVER: # 97.253.168. As the firewall has more than one IP address.253.1.0/24 \ -j SNAT -o eth1 --to-source 97.1.100 nat -A PREROUTING -d 97.27 Anywhere 192.443 and 22 are allowed through by the FORWARD chain.168.168.158.29 iptables -A FORWARD -p tcp -i eth0 -o eth1 -d 192.158.27 -i eth0 \ DNAT --to-destination 192. Note that though the "nat" table NATs all traffic to the target servers (192.linuxhomenetworking.158.26 -i eth0 \ DNAT --to-destination 192.29 # # .100 to 102).101 # 97.168.28 -i eth0 \ DNAT --to-destination 192.26 Anywhere 192.1.1.102 iptables -A POSTROUTING -s 192.253.1.253. all traffic to a particular public IP address. is NAT-ted to a single server on the protected subnet.253.253.130 www.100 \ .1.1.158.101 nat -A PREROUTING -d 97.100 # 97.168. not just to a particular port.253.Interface eth1 is the private network interface #--------------------------------------------------------------iptables -t -j iptables -t -j iptables -t -j nat -A PREROUTING -d 97. SNAT is therefore used to specify the alias IP address to be used for connections initiated by all other servers in the protected net.168.com Static NAT In this example.158.1.158.102 # # SNAT is used to NAT all other outbound connections initiated # from the protected network to appear to come from # IP address 97. only connections on ports 80.168. MASQUERADE isn't recommended to be used as it will force masquerading as the IP address of the primary interface and not any of the alias IP addresses it may have.158.158.Interface eth0 is the internet interface # .253.168.28 Anywhere 192.168.1.

#--------------------------------------------------------------# Log and drop all other packets to file /var/log/messages # Without this we could be crawling around in the dark #--------------------------------------------------------------iptables -A OUTPUT -j LOG iptables -A OUTPUT -j LOG iptables -A FORWARD -j LOG iptables -A INPUT -j DROP iptables -A INPUT -j DROP iptables -A FORWARD -j DROP Here are some examples of the output of this file: Firewall denying replies to DNS queries (UDP port 53) destined to server 192.RELATED -j ACCEPT iptables -A FORWARD -t filter -i eth0 -m state \ --state ESTABLISHED.101 \ -m multiport --dport 80.1. Therefore if you want to log only unwanted traffic then you have to add a matching rule with a DROP target immediately after the LOG rule.RELATED -j ACCEPT Logging & Troubleshooting You track packets passing through the iptables list of rules using the LOG target.Chapter 11: Linux Firewalls Using iptables 131 -m multiport --dport 80.443. This example logs a summary of failed packets to the file /var/log/messages.443. you’ll find yourself logging both desired and unwanted traffic with no way of discerning between the two as by default iptables doesn’t state why the packet was logged in its log message. o .102 on the home network.1.168. You should be aware that the LOG target: o o will log all traffic that matches the iptables rule in which it is located.443.22 --sport 1024:65535 \ -m state --state NEW -j ACCEPT iptables -A FORWARD -t filter -i eth1 -m state \ --state NEW. You can use the contents of this file to determine what TCP/UDP ports you need to open to provide access to specific traffic that is currently stopped. automatically writes an entry to the /var/log/messages file and then executes the next rule. If you don’t.102 \ -m multiport --dport 80.1.ESTABLISHED.22 --sport 1024:65535 \ -m state --state NEW -j ACCEPT iptables -A FORWARD -p tcp -i eth0 -o eth1 -d 192.22 --sport 1024:65535 \ -m state --state NEW -j ACCEPT iptables -A FORWARD -p tcp -i eth0 -o eth1 -d 192.168.168.

Troubleshooting NAT: As a general rule.168. OUTPUT statements If nothing shows up in the logs.113 LEN=76 TOS=0x10 PREC=0x00 TTL=64 ID=0 DF PROTO=UDP SPT=123 DPT=123 LEN=56 Note: The traffic in all these examples isn’t destined for the firewall. then you should focus on the INPUT.linuxhomenetworking.81.168. FORWARD and NAT related statements.100 DST=192.1. You can then use the logging output in /var/log/messages to make sure that: o o the translations are occurring correctly and iptables isn’t dropping the packets after translation occurs .168. OUTPUT.168.1.42.102 LEN=220 TOS=0x00 PREC=0x00 TTL=54 ID=30485 PROTO=UDP SPT=53 DPT=32820 LEN=200 o Firewall denying Windows NetBIOS traffic (UDP port 138) Feb 23 20:43:08 bigboy kernel: IN=wlan0 OUT= MAC=ff:ff:ff:ff:ff:ff:00:06:25:09:6a:b5:08:00 SRC=192.1.255 LEN=241 TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=UDP SPT=138 DPT=138 LEN=221 o Firewall denying Network Time Protocol (NTP UDP port 123) Feb 23 20:58:48 bigboy kernel: IN= OUT=wlan0 SRC=192. If the firewall’s IP address is involved.com Feb 23 20:33:50 bigboy kernel: IN=wlan0 OUT= MAC=00:06:25:09:69:80:00:a0:c5:e1:3e:88:08:00 SRC=192.93.102 DST=207. the location your network that could be causing the problem.30 DST=192. Basic NAT testing will require you to ask a friend to try to connect to your home network from the Internet. then follow the steps in the Network Troubleshooting chapter to determine whether the data is reaching your firewall at all. Therefore you should check your INPUT.1.132 www.200. you won’t be able to access the public NAT IP addresses from servers on your home network. and if it is not.

need to be installed afterwards. . Xinetd is pre-installed in newer RedHat versions and is configured to startup automatically at boot time. [root@bigboy tmp]# /etc/init. such as Telnet. Some of these applications.d directory. are installed by default in RedHat Linux.133 Chapter 12 Telnet. TFTP and XINETD =========================================== In This Chapter Chapter 12 Telnet. www. others such as TFTP. If you are logged into your Linux box via Telnet and then restart xinetd you will disconnect your self from your Linux server as Telnet would be restarted too.com =========================================== Xinetd is a program used to start and stop a variety of Linux data communication applications. TFTP and XINETD Telnet TFTP © Peter Harrison. The configuration files for each of the network programs xinetd controls are located in the /etc/xinetd.d/xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] [root@bigboy tmp]# Remember that you will also be restarting all the other xinetd controlled processes. Once you have edited the configuration files you’ll have to restart xinetd to make the configurations take effect.linuxhomenetworking.

168.255.168... Here is an example of someone logging into a remote server named "smallfry" from server "bigboy".0.0 Gateway 0.255 192. You enter the word "telnet" and then the IP address or server name to which you want to connect.1. Connected to 192.1.0.1.255. The user looks at the routing table and then logs out.4.1.0. The command to do remote logins via telnet from the command line is simple.0.0 Flags UH U U UG MSS 40 40 40 40 Window 0 0 0 0 irtt 0 0 0 0 Iface wlan0 wlan0 lo wlan0 [peter@smallfry peter]$ exit logout Connection closed by foreign host. Linux 2.0.0. [peter@smallfry peter]$ [peter@smallfry peter]$ netstat -nr Kernel IP routing table Destination 255. [root@bigboy root]# .255. One of the disadvantages of Telnet is that the data is sent as clear text.1.168.0 0. This means that it is possible for someone to use a network analyzer to peek into your data packets and see your username and password.0.0 0.134 www.com) (10:35 on Sunday.0.168.0.105.0 0.105 Trying 192.0.1 Genmask 255.0 0. Escape character is '^]'.0. 05 January 2003) Login: peter Password: Last login: Fri Nov 22 23:29:44 on ttyS0 You have new mail. [root@bigboy root]# telnet 192.18-14 (smallfry.my-site.255 255.0 127.0.105.255. A more secure method for remote logins would be via Secure Shell (SSH) which uses varying degrees of encryption.0 192.255.0. Telnet is installed and enabled by default on RedHat Linux.linuxhomenetworking.168.com Telnet What is Telnet? Telnet is a program that allows users to log into your server and get a command prompt just as if they were logged into the VGA console.0 255.0.255.

[root@bigboy tmp]# /etc/init. TFTP and XINETD 135 Setting Up A Telnet Server By default Telnet is installed enabled on RedHat Linux.d/xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] [root@bigboy tmp]# TFTP What is TFTP? Cisco and other networking equipment manufacturers allow you to backup live configurations from routers and switches to workstations via the TFTP protocol.telnetd log_on_failure += USERID disable = yes } You'll then have to restart xinetd for the new settings to take effect.Chapter 12: Telnet. # default: on # description: The telnet server serves telnet sessions. . A remotely stored configuration file is always good to have. A common use of this reverse TFTP is the application of access control lists (ACLs) and even passwords from a centralized file. it uses \ # unencrypted username/password pairs for authentication. You can test whether the Telnet process is running with the following command which is used to check the TCP/UDP ports on which your server is listening: [root@bigboy root]# netstat -a | grep telnet tcp 0 0 *:telnet *:* [root@bigboy root]# LISTEN If you want to disable Telnet then edit the file /etc/xinetd. service telnet { flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.d/telnet and set the disable parameter to "yes". configurations can be loaded from the server to the network device. The reverse is also true.

\ # and to start the installation process for some operating systems. download configuration files to # network-aware printers.168.1.com Setting up a TFTP server Most RedHat Linux software products are available in the RPM format.1.29-3.rpm o Edit the file /etc/xinetd. # default: off # description: The tftp server serves files using the trivial # file transfer \ # protocol.d/tftp and set disable to "no". If you need a refresher. The tftp protocol is often used to boot diskless \ # workstations. You can extend this list with commas in between or just comment it out al together for global access. Here are the steps to setting up the software: Install the package using the following command: [root@bigboy tmp]# rpm -Uvh tftp-server-0.i386. Create a /tftpboot directory with global read write privileges [root@bigboy tmp]# chmod 777 /tftpboot o Restart xinetd [root@bigboy tmp]# /etc/init.0 is tftp-server0. Downloading and installing RPMs isn’t hard.1.1 server = /usr/sbin/in. the chapter on RPMs covers how to do this in detail. The latest TFTP server version of the RPM for RedHat 8. xinetd will only allow the TFTP server to accept connections from the router / switch / firewall with an address of 192.136 www. service tftp { socket_type = dgram protocol = udp wait = yes user = root only_from = 192.168.linuxhomenetworking.29-3.d/xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] [root@bigboy tmp]# o o .tftpd server_args = -s /tftpboot disable = no per_source = 11 cps = 100 2 } In this example.

Cryptochecksum: 3af43873 d35d6f06 51f8c999 180c2342 [OK] pixfw# • Save the configuration to the TFTP server pixfw# write network Building configuration.168.. get into enable mode and then enter the TFTP commands ciscoswitch> (enable) wr net This command shows non-default configurations only..1.1 [root@bigboy tmp]# touch /tftpboot/pixfw-config tmp]# chmod 666 /tftpboot/pixfw-config tmp]# ll /tftpboot/ root root 3011 Oct 29 14:09 pixfw-config tmp]# Configuring Cisco Devices for TFTP You'll now have to configure your Cisco router / firewall to use the TFTP server.1..Chapter 12: Telnet. TFTP and XINETD 137 o Each device must have a configuration file in the /tftpboot directory.168. The following examples assume that the TFTP server's IP address is 192.100 on interface 1 [OK] pixfw# Cisco Switch Running CATOS • Log onto the device. Use 'write network all' to show both default and non-default .168.100 /pixfw-config pixfw(config)# exit • Save the configuration to non volatile memory pixfw# write memory Building configuration. TFTP write '/pixfw-config' at 192. Here's an example of what to do for a SOHO firewall with the name "pixfw" and a configuration filename that matches cisco's standard naming scheme of "devicename"-config [root@bigboy [root@bigboy [root@bigboy total 1631 -rw-rw-rw..100 Cisco PIX firewall • Log onto the device. get into enable mode and then enter the TFTP commands pixfw> enable Password: ******** pixfw# configure terminal pixfw(config)# tftp-server inside 192.1.

138

www.linuxhomenetworking.com

configurations. IP address or name of remote host? [192.168.1.100] Name of configuration file?[ciscoswitch-config] Upload configuration to ciscoswitch-config on 192.168.1.100 (y/n) [n]? y ......... Finished network upload. (30907 bytes) ciscoswitch> (enable)

Cisco Router
• Log onto the device, get into enable mode, then configure mode and then enter the TFTP commands ciscorouter> enable ciscorouter#write net Remote host [192.168.1.100]? 192.168.1.100 Name of configuration file to write [ciscorouter-config]? ciscorouter-config Write file ciscorouter-config on host 192.168.1.100? [confirm] y ciscorouter# exit

Cisco CSS 111000 "Arrowpoints"

Log onto the device and then enter the tftp commands ciscocss# copy running-config tftp 192.168.1.100 ciscocss-config Working..(\) 100% Connecting (/) Completed successfully. ciscocss# exit

Cisco Local Director
• Log onto the device, get into enable mode, then configure mode and then enter the TFTP commands ciscold> ena Password: ciscold# write net 192.168.1.100 ciscold-config Building configuration... writing configuration to //ciscold-config on 192.168.1.100:69 ... [OK] ciscold# exit

Chapter 12: Telnet, TFTP and XINETD

139

Using TFTP To Restore Your Router Configuration
One of the benefits of having a TFTP server is that you can save your configuration files on a remote server's hard disk. This can be very useful in the event of a router failure after which you need to reconfigure the device from scratch. One of the simplest ways of doing this using TFTP is to: o o o o o Connect your router to the local network of the TFTP server Give your router the bare minimum configuration that allows it to ping your TFTP server. (No access controls or routing protocols) Use the copy command to copy the backup configuration from the TFTP server to your startup configuration in NVRAM. Disconnect the router from the network Reload the router without saving the live running configuration to overwrite the startup configuration. On rebooting, the router will copy the startup configuration stored in NVRAM into a clean running configuration environment Log into the router via the console and verify the configuration is OK Reconnect the router to the networks on which it was originally connected

o o

Here are the commands: ciscorouter> enable Password: ******** ciscorouter# write erase ciscorouter# copy tftp:file-name startup-config ciscorouter# reload Please be aware that the "write erase" command erases your NVRAM startup configuration and should always be used with great care.

140

www.linuxhomenetworking.com

141

Chapter 13

Linux FTP Server Setup
===========================================

In This Chapter Chapter 13
Linux FTP Server Setup
FTP Overview Problems With FTP And Firewalls How To Download And Install The VSFTP Package How To Get VSFTP Started Testing To See If VSFTP Is Running What Is Anonymous FTP? The /etc/vsftpd.conf File FTP Security Issues Example #1: © Peter Harrison, www.linuxhomenetworking.com ===========================================

This chapter will show you how to convert your Linux box into an FTP server using the VSFTP package.
The RedHat software download site runs on VSFTP.

FTP Overview
File Transfer Protocol (FTP) is a common method of copying files between computer systems. Two TCP ports are used to do this:

142

www.linuxhomenetworking.com

FTP Control Channel - TCP Port 21
All commands you send and the ftp server's responses to those commands will go over the control connection, but any data sent back (such as "ls" directory lists or actual file data in either direction) will go over the data connection.

FTP Data Channel - TCP Port 20
Used for all data sent between the client and server.

Active FTP
Active FTP works as follows: o o Your client connects to the FTP server by establishing an FTP control connection to port 21 of the server. Your commands such as 'ls' and 'get' are sent over this connection. Whenever the client requests data over the control connection, the server initiates data transfer connections back to the client. The source port of these data transfer connections is always port 20 on the server, and the destination port is a high port on the client. Thus the 'ls' listing that you asked for comes back over the "port 20 to high port connection", not the port 21 control connection. FTP active mode data transfer therefore does this in a counter intuitive way to the TCP standard as it selects port 20 as it's source port (not a random high port > 1024) and connects back to the client on a random high port that has been pre-negotiated on the port 21 control connection.

o o

Chapter 13: Linux FTP Server Setup

143

o

Active FTP may fail in cases where the client is protected from the Internet via many to one NAT (masquerading). This is because the firewall will not know which of the many servers behind it should receive the return connection.

Passive FTP
Passive FTP works as follows: o o Your client connects to the FTP server by establishing a FTP control connection to port 21 of the server. Your commands such as 'ls' and 'get' are sent over that connection. Whenever the client requests data over the control connection, the client initiates the data transfer connections to the server. The source port of these data transfer connections is always a high port on the client with a destination port of a high port on the server. Passive FTP should be viewed as the server never making an active attempt to connect to the client for FTP data transfers. Passive FTP works better for clients protected by a firewall as the client always initiates the required connections.

o o

Problems With FTP And Firewalls
FTP frequently fails when the data has to pass through a firewall as FTP uses a wide range of unpredictable TCP ports and firewalls are designed to limit data flows to predictable TCP ports. There are ways to overcome this as explained in the following sections. The Appendix has examples of how to configure the iptables Linux filewall to function with both active and passive FTP.

Client Protected By A Firewall Problem
Typically firewalls don't let any incoming connections at all, this will frequently cause active FTP not to function. This type of FTP failure has the following symptoms: o The active ftp connection appears to work when the client initiates an outbound connection to the server on port 21. The connection appears to hang as soon as you do an "ls" or a "dir" or a "get". This is because the firewall is blocking the return connection from the server to the client. (From port 20 on the server to a high port on the client)

Solutions
Here are the general firewall rules you'll need to allow FTP clients through a firewall:

com Client Protected by Firewall . FTP server failure due to firewalls in which the active ftp connection from the client doesn't appear to work at all Solutions Here are the general firewall rules you'll need to allow FTP severs through a firewall . This rule may not be necessary in all cases.144 www. you may want to allow all Internet users to have access. ** in some cases. Server Protected By A Firewall Problem o Typically firewalls don't let any connections come in at all.Required Rules for FTP Method Source Address Source Port Destination Address Destination Port Connection Type Allow outgoing control connections to server Control Channel FTP client/ network FTP server** High FTP server** 21 New 21 FTP client/ network High Established* Allow the client to establish data channels to remote server Active FTP FTP server** 20 FTP client /network FTP server** High New FTP client/ network Passive FTP FTP client/ network FTP server** High 20 Established* High FTP server** High New High FTP client/ network High Established* *Many home based firewall/routers automatically allow traffic for already established connections.linuxhomenetworking. not just a specific client server or network.

the VSFTP RPM file is named: vsftpd-1. ** in some cases.0 of the operating system.Chapter 13: Linux FTP Server Setup 145 Server Protected by Firewall . If you need a refresher. the RPM chapter covers how to do this in detail. RedHat software is installed using RPM packages. you may want to allow all Internet users to have access. How To Download And Install The VSFTP Package • As explained previously.i386.rpm Downloading and installing RPMs isn’t hard. This rule may not be necessary in all cases.0-1. In version 8. not just a specific client server or network.Required Rules for FTP Method Source Address Source Port Destination Address Destination Port Connection Type Allow incoming control connections to server Control Channel FTP client/ network** FTP server High FTP server 21 New 21 FTP client/ network** High Established* Allow server to establish data channel to remote client Active FTP FTP server 20 FTP client/network** FTP server High New FTP client/ network** Passive FTP FTP client/ network** FTP server High 20 Established* High FTP server High New High FTP client/ network** High Established* *Many home based firewall/routers automatically allow traffic for already established connections.1. • Now download the file to a directory such as /tmp and install it using the “rpm” command: .

Make sure the contents look like this. The disable feature must be set to "no" to accept connections. you’ll have to edit /etc/xinetd. there would be no output at all if VSFTP wasn’t running.d/xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] [root@aqua tmp]# Naturally. so you’ll have to edit this file to start the program. The example below shows the expected output.i386.d/vsftpd file.. [root@aqua tmp]# /etc/init.linuxhomenetworking.com [root@bigboy Preparing. [root@bigboy root]# netstat -a | grep ftp tcp 0 0 *:ftp [root@bigboy root]# *:* LISTEN . 1:vsftpd [root@bigboy tmp]# rpm -Uvh vsftpd-1.d/vsftpd. service ftp { disable = no socket_type = stream wait = no user = root server = /usr/sbin/vsftpd nice = 10 } You will then have to restart xinetd for these changes to take effect using the startup script in the /etc/init. Testing To See If VSFTP Is Running You can always test whether the VSFTP process is running by using the netstat –a command which lists all the TCP and UDP ports on which the server is listening for traffic.rpm ########################################### [100%] ########################################### [100%] tmp]# How To Get VSFTP Started The starting and stopping of VSFTP is controlled by xinetd via the /etc/xinetd..d directory.146 www.1. set “disable” to “yes” and restart xinetd.0-1. to disable VSFTP once again. VSFTP is deactivated by default.

you will # obviously need to create a directory writable by the FTP user. Also. Unless you want any remote user to log into to your default FTP directory. VSFTP runs as an anonymous FTP server. #anon_upload_enable=YES .Chapter 13: Linux FTP Server Setup 147 What Is Anonymous FTP? Anonymous FTP is used by web sites that need to exchange files with numerous unknown remote users. # Uncomment this to enable any form of FTP write command. Common uses include downloading software updates and MP3s to uploading diagnostic information for a technical support engineer’s attention.. The /etc/vsftpd. Remove/add the "#" at the beginning of the line to "activate/deactivate" the feature on each line. Also by default. not uploads from them.. VSFTP can be configured to support user based and or anonymous FTP in its configuration file.. Once logged in to a VSFTP server..log log file.conf configuration file when it starts. VSFTP doesn't allow remote users to create directories on your FTP server and it logs FTP access to the /var/log/vsftpd. . # Allow anonymous FTP? anonymous_enable=YES . using anonymous FTP as a remote user is fairly straight forward.. By default. # (Needed even if you want local users to be able to upload files) write_enable=YES . As seen in the chapter on RPMs. anonymous FTP only requires a username of "anonymous" and your email address for the password.. .. I would suggest turning this off.. # Uncomment this to allow local users to log in.. you’ll automatically have access to only the default anonymous FTP directory /var/ftp and all its subdirectories... . This file uses a number of default settings you need to know. . # Uncomment this if you want the anonymous FTP user to be able to create # new directories. The configuration file is fairly straight forward as you can see in the snippet below. .. This only # has an effect if global write enable is activated. By default VSFTP only allows anonymous FTP downloads to remote users. so you’ll have to restart xinetd each time you edit the file in order for the changes to take effect. local_enable=YES . Unlike regular FTP where you login with a userspecific username...conf File VSFTP only reads the contents of its /etc/vsftpd. # Uncomment to allow the anonymous FTP user to upload files. The configuration file’s anonymous_enable instruction can be commented out using a “#” to disable this feature...

This will allow your users to upload. xferlog_enable=YES .conf to make it harder for malicious users to determine the type of system you have. #xferlog_file=/var/log/vsftpd.com #anon_mkdir_write_enable=YES . # The default is shown# below. Anonymous Upload If you want remote users to write data to your FTP server then it is recommended you create a write-only directory within /var/ftp/pub. .148 www.linuxhomenetworking. Secure Copy (SCP) provides encryption and could be considered as an alternative to FTP for trusted users. Here are the commands to do this: [root@bigboy tmp]# mkdir /var/ftp/pub/upload [root@bigboy tmp]# chmod 733 /var/ftp/pub/upload FTP Greeting Banner Change the default greeting banner in /etc/vsftpd. . it is best to add.. Do not delete entries from the default list.log FTP Security Issues The /etc/vsftpd.. . but not access other files uploaded by other users. a feature that FTP does. This could make your user account vulnerable to an unauthorized attack from a person eavesdropping on the network connection.ftpusers File For added security you may restrict FTP access to certain users by adding them to the list of users in this file.. # You may override where the log file goes if you like.. ftpd_banner= New Banner Here Using SCP As Secure Alternative To FTP One of the disadvantages of FTP is that it does not encrypt your username and password. SCP however does not support anonymous services.... # Activate logging of uploads/downloads..

and make their default directory /home/ftp-docs [root@bigboy [root@bigboy [root@bigboy [root@bigboy [root@bigboy [root@bigboy [root@bigboy [root@bigboy o tmp]# tmp]# tmp]# tmp]# tmp]# tmp]# tmp]# tmp]# useradd -g ftp-users useradd -g ftp-users useradd -g ftp-users useradd -g ftp-users passwd user1 passwd user2 passwd user3 passwd user4 -d -d -d -d /home/ftp-docs /home/ftp-docs /home/ftp-docs /home/ftp-docs user1 user2 user3 user4 Copy files to be downloaded by your users into the /home/ftp-docs directory . Comment out the anonymous_enable line in the /etc/vsftpd.d/vsftp and set the disable value to "no". Edit the /etc/xinetd. local_enable=YES o Create a user group and shared directory. but a group of trusted users need to have read only access to a directory for downloading files. Disable anonymous FTP. [root@bigboy tmp]# groupadd ftp-users [root@bigboy tmp]# mkdir /home/ftp-docs o Make the directory accessible to the ftp-users group. Here are the steps: Enable FTP. anonymous FTP is not desired. In this case we’ll use "/home/ftp-users" and a user group name of "ftp-users” for the remote users.conf file like this: # Uncomment this to allow local users to log in.Chapter 13: Linux FTP Server Setup 149 Example #1: FTP Users With Only Read Access To A Shared Directory In this example.conf file like this: o o # Allow anonymous FTP? # anonymous_enable=YES o Enable individual logins by making sure you have the local_enable line uncommented in the /etc/vsftpd. [root@bigboy tmp]# chmod 750 /home/ftp-docs [root@bigboy tmp]# chown root:ftp-users /home/ftp-docs o Add users.

220 ready. ftp> o We can view and download a copy of the VSFTP RPM .1 root root 0 Jan 4 09:08 testfile [root@smallfry tmp]# o Connect to bigboy via FTP [root@smallfry tmp]# ftp 192.1.181. ftp> o As expected.1.100 Connected to 192.100:root): user1 331 Please specify the password.linuxhomenetworking.100.0: beat me.100). [root@smallfry tmp]# ll total 1 -rw-r--r-.100 (192. [root@bigboy tmp]# /etc/init. Have fun. Remote system type is UNIX.168.1. ftp> put testfile local: testfile remote: testfile 227 Entering Passive Mode (192.1. break me) Name (192. Password: 230 Login successful. If you absolutely don't want any FTP users to be able to write to any directory then you should comment out the write_enable line in your /etc/vsftpd. dude (vsFTPd 1.168.150 www.168.com o Change the permissions of the files in the /home/ftp-docs directory for read only access by the group [root@bigboy tmp]# chown root:ftp-users /home/ftp-docs/* [root@bigboy tmp]# chmod 740 /home/ftp-docs/* Users should now be able to log in via ftp to the server using their new user names and passwords.168.d/xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] [root@bigboy tmp]# Sample Login Session To Test Funtionality o Check for the presence of a test file on the ftp client server.1.1.conf file like this: #write_enable=YES o Restart vsftp for the configuration file changes to take effect.168. we can't do an upload transfer of "testfile" to bigboy.210) 553 Could not create file. Using binary mode to transfer files.

0: beat me.0-1.1.rpm 226 Directory send OK.1.Chapter 13: Linux FTP Server Setup 151 ftp> ls 227 Entering Passive Mode (192.1. 76288 bytes received in 0. 220 ready.44.168.168.i386. Login failed.1.rpm (76288 bytes).1.168. [root@smallfry tmp]# o As expected. ftp> get vsftpd-1.1.35.100:root): anonymous 331 Please specify the password.5e+02 Kbytes/sec) ftp> exit 221 Goodbye.100 Connected to 192. [root@smallfry tmp]# ftp 192.173) 150 Here comes the directory listing. break me) Name (192.1.1.0-1.1.1.i386.i386.168.156) 150 Opening BINARY mode data connection for vsftpd-1.168.0-1.0-1.100).1 0 502 76288 Jan 04 17:06 vsftpd-1.1. 226 File send OK. dude (vsFTPd 1. -rwxr----.rpm vsftpd-1. ftp> quit 221 Goodbye. [root@smallfry tmp]# .rpm.100 (192.i386.i386.0-1.rpm.0-1. we can't do anonymous ftp.rpm 227 Entering Passive Mode (192.100. Password: 530 Login incorrect.tmp remote: vsftpd-1.168.100.tmp local: vsftpd-1.i386.1.499 secs (1.1.

152 www.linuxhomenetworking.com .

Similar programs such as Telnet and FTP can be security hazards as they do not encrypt their passwords.153 Chapter 14 Secure Remote Logins And File Copying =========================================== In This Chapter Chapter 14 Secure Remote Logins And File Copying Using Secure Shell As A Replacement For Telnet Testing To See If SSH Is Running The etc/ssh/sshd_config File Using SSH To Login To A Remote Machine What You Should Expect To See When You Log In Deactivating Telnet once SSH is installed Using SCP as a more secure replacement for FTP © Peter Harrison. SSH and SCP could be the right choice for you. . www.linuxhomenetworking. H Using Secure Shell As A Replacement For Telnet When you use Telnet to remotely log into a Linux box you run the risk of people being able to eavesdrop on your network wire to see your username and password as unencrypted text. so all your activities can be monitored.com =========================================== ere is some information on how to both remotely log in and copy files using a secure encrypted connection with Secure Shell (SSH) and Secure Copy (SCP). None of the data flow in Telnet is encrypted.

When logging in from another Linux/UNIX machine you use the "ssh" command.0. You should get a response of plain old process ID numbers: [root@bigboy tmp]# pgrep sshd The etc/ssh/sshd_config File The SSH configuration file is called /etc/ssh/sshd_config.linuxhomenetworking.0 #ListenAddress :: If you are afraid of people trying to hack in on a well known TCP port. Testing To See If SSH Is Running You can test whether the SSH process is running with the following command.d/sshd stop [root@bigboy tmp]# /etc/init.d/sshd restart Remember to restart the SSH process every time you make a change to the configuration files for the changes to take effect on the running process. [root@bigboy tmp]# chkconfig --level 35 sshd on • You can also start/stop/restart SSH after booting by running the sshd initialization script.d/sshd start [root@bigboy tmp]# /etc/init. then you can change port 22 to something else that won't interfere with other applications on your system. This provides an encrypted data stream for you to use when you log in from one machine to another.com RedHat Linux comes standard with Secure Shell (SSH) installed. [root@bigboy tmp]# /etc/init. but leave them commented. There are GUI based SSH clients available for Windows. • You can get SSH configured to start at boot by using the chkconfig command. such as port 435 • First make sure your system isn't listening on port 435.0. Uncommented options change a default value.154 www. #Port 22 #Protocol 2. see the references in the bibliography. . By default SSH listens on all your NICs and uses TCP port 22. using the "netstat" command and using "grep" to filter out everything that doesn't have the string "435". See the configuration snippet below: # # # # The strategy used for options in the default sshd_config shipped with OpenSSH is to specify options with their default value where possible.1 #ListenAddress 0.

Something like this: .168.0. If you leave out the "-l". your username will not change.100:435 0. User “root” Logs In To smallfry As User “root” [root@bigboy tmp]# ssh smallfry User “root” Logs In To smallfry As User “peter” Using default port 22 [root@bigboy tmp]# ssh -l peter smallfry Using port 435 [root@bigboy tmp]# ssh -l peter -p 435 smallfry What You Should Expect To See When You Log In The first time you log in. Change the Port line in /etc/ssh/sshd_config to mention 435 and remove the "#" at the beginning of the line. If port 435 is being used.d/sshd restart • Check to ensure SSH is running on the new port [root@bigboy root]# netstat -an | grep 435 tcp 0 0 192. you will get a warning message saying that the remote host doesn't know about your machine. Here are some examples for a server named “smallfry” in your /etc/hosts file.Chapter 14: Secure Remote Logins And File Copying 155 [root@bigboy root]# netstat -an | grep 435 [root@bigboy root]# • No response.1. Port 435 • Restart SSH [root@bigboy tmp]# /etc/init.0:* [root@bigboy root]# LISTEN Using SSH To Login To A Remote Machine Using SSH is similar to Telnet. OK. To login from another Linux box use the "ssh" command with a "-l" to specify the username you wish to login as.0. pick another port and try again.

3 and newer. It is !! highly advisable to turn StrictHostKeyChecking to "yes" and !! manually copy host keys to known_hosts.156 www. Edit the file /etc/xinetd.98 No mail.linuxhomenetworking.telnetd log_on_failure += USERID disable = yes } Now restart xinetd. Are you sure you want to continue connecting (yes/no)? yes Host 'smallfry' added to the list of known hosts. [root@smallfry tmp]# Deactivating Telnet once SSH is installed Now you need to switch off Telnet. [root@bigboy tmp]# /etc/init.168. Xinetd is installed by default in RedHat 7. service telnet { flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in. root@smallfry's password: Last login: Thu Nov 14 10:18:45 2002 from 192. it uses \ # unencrypted username/password pairs for authentication. # default: on # description: The telnet server serves telnet sessions.com [root@bigboy tmp]# ssh smallfry Host key not found from the list of known hosts. which makes it relativily easy to !! hijack the connection without the attack being detected. !! If host key is new or changed.d/xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] [root@bigboy tmp]# . ssh1 protocol is vulnerable to an !! attack known as false-split.d directory.d/telnet and set the disable parameter to "yes". The Telnet server is controlled by the xinetd network security program.1. The configuration files for each of the network programs it controls is located in the /etc/xinetd.

rpm on the remote machine to the local directory /usr/rpm [root@bigboy tmp]# scp root@smallfry:/tmp/software. FTP isn't very secure as usernames.1. [root@bigboy tmp]# scp /etc/hosts root@192.cz/eng/ Secure Copy (SCP) is installed in parallel with SSH and they always run simultaneously on the same TCP port.vse. passwords and data are sent across the network unencrypted. Copying Files To The Local Linux Box Command Format: scp username@address:remotefile localdir Example: Copy file /tmp/software. There is a windows scp client called WinSCP which can be downloaded at: http://winscp.103:/tmp .168. More secure forms such as SFTP (Secure FTP) and SCP (Secure Copy) are available as a part of the Secure Shell package that is normally installed by default on RedHat. SCP doesn't support anonymous downloads like FTP.Chapter 14: Secure Remote Logins And File Copying 157 Using SCP as a more secure replacement for FTP From a networking perspective.rpm /usr/rpm Copying Files To The Remote Linux Box Command Format: scp filename username@address:remotedir Example: Copy file /etc/hosts on the local machine to directory /tmp on the remote server.

com .158 www.linuxhomenetworking.

. Linux And Samba =========================================== In This Chapter Chapter 15 Windows.linuxhomenetworking. This allows each user to have a universal username and password when logging in from all PCs on the network. www. but this simple explanation should be enough.159 Chapter 15 Windows. What’s the difference between a PDC and Windows Workgroup member? A detailed description is beyond the scope of this chapter. • A PDC stores the login information in a central database on its hard drive. each PC stores the usernames and passwords locally so that they are unique for each PC. This chapter describes how you can make your Linux box into a Windows Primary Domain Controller (PDC) or a server for a Windows Workgroup. Linux And Samba Download and Install Packages How To Get SAMBA Started Configuring SWAT Samba and PC Firewall Software How To Create A Samba PDC Administrator User How to Configure a Samba PDC How To Add Users To Your Samba Domain Domain Groups And Samba How To Delete Users From Your Samba Domain © Peter Harrison. Either configuration will allow everyone at home to have: • their own logins on all the home windows boxes while having their files on the Linux box appear to be located on a new Windows drive • shared access to printers on the Linux box • shared files accessible only to members of their Linux user group. • In a Windows Workgroup.com =========================================== Samba is a suite of utilities that allows your Linux box to share files and other resources such as printers with Windows boxes.

When Samba starts up it reads the configuration file /etc/samba/smb.5-10.5-10.d/smb stop [root@bigboy tmp]# /etc/init.5-10. you should get a response of plain old process ID numbers: [root@bigboy tmp]# pgrep smb .i386. Samba mimics a Windows PDC in almost every way needed for simple file sharing.2.conf using a text editor or using the easier web based SWAT utility.rpm samba-common-2. How To Get SAMBA Started • You can configure Samba to start at boot time using the chkconfig command: [root@bigboy tmp]# chkconfig --level 35 smb on • You can start/stop/restart Samba after boot time using the smb initialization script as in the examples below: [root@bigboy tmp]# /etc/init. By default.d/smb restart • Remember to restart the smb process every time you make a change to the conf file for the changes to take effect on the running process. For added security you can make your Samba and Linux passwords different.0 was version 2. the RPM chapter covers how to do this in detail. Install all the packages in this order: [root@bigboy [root@bigboy [root@bigboy [root@bigboy tmp]# tmp]# tmp]# tmp]# rpm rpm rpm rpm -Uvh -Uvh -Uvh -Uvh samba-2. Samba Domains and Linux share the same usernames so you can log into the Samba based Windows domain using your and immediately gain access to files in your Linux user’s home directory.5-10.5-10. the latest version of the Samba suite for RedHat 8.i386.2. If you need a refresher.conf with a text editor if you subsequently use SWAT to edit it. Keep in mind that you will lose all your comments inserted in /etc/samba/smb.rpm samba-swat-2.2.d/smb start [root@bigboy tmp]# /etc/init.i386. Download and Install Packages Samba is comprised of a suite of RPMs that come on the RedHat CDs. You can create your own smb.rpm Downloading and installing RPMs isn’t hard. As of this writing.rpm samba-client-2. Explanations of how to use both SWAT and a text editor to configure Samba are given in this chapter. Linux functionality doesn’t disappear when you do this.linuxhomenetworking.i386.conf to determine its various modes of operation.160 www.2.com This chapter will only cover the much more popular PDC methodology used at home. • You can test whether the smb process is running with the following command.2.

you may want to create a Samba administrator user that has no root privileges whatsoever or do your configuration using the configuration files. • The disable parameter must be set to "no" to accept connections.168.3 Therefore in this case you can also configure Samba on your Linux server "Bigboy" IP with address 192.168. starting and stopping of SWAT is controlled by xinetd via a configuration file named /etc/xinetd. You can make SWAT accessible from other servers by adding IP address entries separated to the only_from parameter. especially as there are only two entries of interest.3 and localhost: only_from = localhost. Here is a sample.100 from PC 192. you can only log into SWAT from the VGA console as user "root".1.168. 192. Here are some ways to solve the problem with two popular packages.0:901) as defined by the only_from and port parameters.1.168.d/swat.0.Chapter 15 : Windows. The enabling/disabling.1. This may be a security concern in a corporate environment.0.1. Because of this. Unfortunately it doesn't encrypt your login password. The URL must point to your localhost IP address on port 901 (http://127.100:901 Samba and PC Firewall Software Firewall software installed on Windows PCs may cause Samba to not function. Here’s an example of an entry to allow connections only from 192.3 using the URL http://192. service swat { port socket_type protocol wait user server log_on_failure disable only_from } = 901 = stream = tcp = no = root = /usr/sbin/swat += USERID = no = localhost The formatting of the file is fairly easy to understand.1.168. . • By default. Linux And Samba 161 Configuring SWAT SWAT is a very intuitive web based Samba configuration tool that allows you to configure Samba without all the memorization of the keywords needed for text based configuration.

Right click your on your LAN connection icon and select Properties Click on the Advanced tab.255. instead of an Internet network and ZoneAlarm should cease to interfere with Samba.162 www. Uncheck the Internet Connection Firewall box and it will be turned on. This can be done by clicking on the firewall tab and editing the settings for your home network that will most likely have a 192. Here is how it's done: Create The Administrator’s User Group and Directories o First create a Linux group for administrators: [root@bigboy tmp]# /usr/sbin/groupadd sysadmin o Then create a Linux directory to house all the administrator directories: [root@bigboy tmp]# mkdir /home/sysadmin [root@bigboy tmp]# chgrp sysadmin /home/sysadmin [root@bigboy tmp]# chmod 0770 /home/sysadmin . The easiest way around this is to configure Zone Alarm to consider your home network as a trusted network too.168.0 type entry.255.com Zone Alarm The default installation of Zone Alarm assumes that your PC is directly connected to the Internet. This means that the software will deny all inbound connections that attempt to connect with your PC. Once you get SAMBA to work. Make this network a trusted network. you may want to experiment with the firewall software settings to optimize your security with the need to maintain a valid relationship with the SAMBA server How To Create A Samba PDC Administrator User To do both SWAT and user administration with Samba you'll need to create an Administrator account on the Samba PDC Linux box.linuxhomenetworking.x/255.x. The NetBIOS traffic that Samba uses to communicate with the PCs on the network will therefore be considered as hostile traffic. The Windows XP Built In Firewall You may also need to disable the firewall feature of Windows XP by doing the following: o o o o o Bring up Control Panel Go through the Network and Internet Connections and then Network Connections menus.

we won’t assign a real Linux password. Linux And Samba 163 Create The Administrator User Under Linux o For each administrator user. The table below explains what each of the adduser command switches used. especially if you’re using SWAT.smb -n . Usually default login scripts. Tells RedHat NOT to create a default group with the same name as the user. (Redundant in this case) -m -d dir_path -k /etc/skel.smb -n administrator o As this user may not need a real Linux login. Adduser’s Command Switches useradd command switch -g group Description Sets the group to which the user should be added. create a Linux user with the adduser command: [root@bigboy tmp]# /usr/sbin/adduser -d \ /home/sysadmin/administrator \ -g sysdmin -m -k /etc/skel.smb to the users new home directory.Chapter 15 : Windows. In this case the administrator user has been made a member of the sysadmin group. This provides an added level of security. Forces linux to create the directory specified with the -d switch Home directory for the new user Tells adduser to copy the contents of the directory /etc/skel.

[global] admin users = @sysadmin This can also be set via SWAT in the expanded “global settings” section. Log into SWAT and click on the “globals” section and make sure the key highlighted parameters below are set correctly.168.conf file and add the sysadmin group to the list of Samba system administrator users. Use a generic password then have users change it immediately from their workstation the usual way. # Samba config file created using SWAT # from 192.101) # Date: 2002/11/10 19:54:45 # Global parameters [global] ## ## The name I want to give my DOMAIN ## workgroup = HOMENET .com Create An Administrator Domain Password The Linux Administrator now needs a Samba password to log into the Windows domain. You’ll need to restart Samba for this to take effect. This is done with the smbpasswd command.164 www. Note: If you want user "administrator" to be able to log into the Linux box as a regular user via Telnet or SSH. Make The Administrator One Of The Samba Admin Users Edit /etc/samba/smb.1.168. [root@bigboy tmp]# /usr/bin/smbpasswd -a administrator password The -a adds the user administrator to the /etc/smbpasswd file. How to Configure a Samba PDC Create A Samba PDC By far the easiest way to configure a Samba PDC is by using SWAT.1. then you'll have to use the Linux passwd command to give this user a Linux (not a Samba domain) password.101 (192. Samba domain logins use the smbpasswd password.linuxhomenetworking.

cmd ## ## My user’s Linux login directory will always appear ## to be Windows drive H: ## logon drive = h: ## ## Activate domain type logins and make ## Linux box be the master Windows server ## in all domain type functions ## domain logons = Yes os level = 99 preferred master = True domain master = True local master = True dns proxy = No .Chapter 15 : Windows. You can also have local administrator accounts on PCs to do software installation.cmd in the Linux user’s home directory ## will be run whenever the user logs in. but they wont be PDC administrators to do things like adding new PCs to the domain domain admin group = @sysadmin ## ## The script logon. Ie administer the PDC and do activities on the local PC like software installation. Linux And Samba 165 ## ## The name of my Linux Box ## server string = BigBoy ## ## Make sure passwords are always encrypted ## encrypt passwords = Yes ## ## Samba will log errors via syslog to ## directory /var/log/samba ## log file = /var/log/samba/%m. (Usually blank) ## logon script = logon.log max log size = 0 ## ## The command Samba uses to add new printers ## directory /var/log/samba ## addprinter command = /usr/bin/addprinter ## ## ## ## ## ## ## ## ## Only domain users in the sysadmin group can act as universal administrators.

Here you will use the drop down menu to edit the netlogon and profiles shares [netlogon] ## ## Store all Samba PDC overhead data in the directory ## /home/netlogon (or whatever you desire) ## path = /home/netlogon write list = administrator guest ok = Yes [profiles] ## ## Store user profiles in this directory ## path = /home/ntprofile read only = No create mask = 0600 directory mask = 0700 guest ok = Yes browseable = No Click on the “Status” button at the top of the screen and restart Samba to make your settings take effect. Samba can create these “Machine Trusts” in two ways. [root@bigboy nickname" -s [root@bigboy [root@bigboy tmp]# /usr/sbin/useradd -g 100 -d /dev/null -c "machine /bin/false machine_name$ tmp]# passwd -l machine_name$ tmp]# smbpasswd -a -m machine_name .com ## ## Only users in the sysadmin group can use SWAT ## to modify Samba and ## admin users = @sysadmin printer admin = @sysadmin printing = lprng Next you will have to use SWAT to click on the “shares” button. Create Your PC Machine Trusts PDCs will only accept user logins from trusted PCs that have been placed in its PC client database. either manually or automatically.166 www.linuxhomenetworking. Pay careful attention to the "$" at the end and replace machine_name with the name of the Windows client machine. Manual Creation Of Machine Trust Accounts (NT Only) When manually creating a machine trust account you need to manually create the corresponding Unix account in /etc/passwd and /etc/smbpasswd files.

but suffice it to say that the directory must be created on the Linux box for Samba to operate correctly. Windows 95/98/ME Windows 9x machines do not implement full domain membership and therefore don't require machine trust accounts • • • • • • Navigate to the Network section of the Control Panel (Start ->Settings->Control Panel>Network) Select the Configuration tab Highlight "Client for Microsoft Networks" Click the Properties button.. [root@bigboy tmp]# mkdir /home/netlogon [root@bigboy tmp]# chmod 0755 /home/netlogon You’ll then have to log into each PC client and do the following steps depending on their operating system.. This information is stored in the netlogon directory. defining your wall paper and setting the way dates are formatted..remainder of parameters.conf to automatically add the required users.. Linux And Samba 167 This is the only way to configure machine trusts using Windows NT. Check "Log onto Windows NT Domain". and enter the domain name. [global] # <. This method is also referred to as making a machine account "on the fly".> add user script = /usr/sbin/useradd -d /dev/null -g 100 -s /bin/false -M %u This is probably easier to do if you use SWAT in the “Global” menu Make Your PC Clients Aware Of Your Samba PDC When you log into the domain. Dynamic Creation Of Machine Trust Accounts The second (and recommended) way of creating machine trust accounts is simply to allow the Samba server to create them as needed when the client joins the domain. How to configure the netlogon directory is beyond the scope of this chapter. This can be done by editing /etc/samba/smb. Click all the OK buttons and reboot! .Chapter 15 : Windows. These include things like suppressing the splash screen. the PDC will send your new client PC a list of universal “look and feel” related features that may have been previously set by the Administrator.

do not check the box "Create a Computer Account in the Domain. This should be your Samba administrator. • • • Windows XP Create a dynamic SAMBA machine trust account as explained above. Reboot. Click "OK" You should then get a confirmation that you’ve been added with a "Welcome to <DOMAIN>" message. Log in using any account in the /etc/smbpasswd file with your domain as the domain name." In this case.linuxhomenetworking. then go through the following steps: • Press Windows-key Break-key simultaneously to get the System Properties dialogue box .) You should then get a confirmation that you’ve been added with a "Welcome to <DOMAIN>" message.168 www. • • • • Windows 2000 Create a dynamic SAMBA machine trust account as explained above. Log in using any account in the /etc/smbpasswd file with your domain as the domain name. In our case that would be user "administrator" with the corresponding smbpasswd password. then go through the following steps: • • • • Navigate to the Network section of the Control Panel (Start ->Settings->Control Panel>Network ) Select the “identification” tab Click the "change" button Enter the domain name and computer name. Reboot. the existing machine trust account is used to join the machine to the domain. (See this note before proceeding.com Windows NT Create a manual SAMBA machine trust account as explained above. then go through the following steps: • • • • • • Press Windows-key Break-key simultaneously to get the System Properties dialogue box Click on the 'Network Indentification' tab on the top Click the "Properties" button Click on the “Member of Domain” button Also enter your domain name and computer name and then click "OK" You will now be prompted for a user account and password with rights to join a machine to the domain.

Samba will automatically give each user logged into the domain an H: drive that really maps to the /home/username directory on the Linux box.Chapter 15 : Windows. Map The Linux Users To An smbpassword Next you need to create Samba domain login passwords for all users [root@bigboy tmp]# /usr/bin/smbpasswd -a username password The -a adds the user to the /etc/smbpasswd file. Reboot. Passwords won’t be necessary unless you want the users to log in to the Samba server via Telnet or SSH. Linux And Samba 169 • • • • • Click on the 'Computer Name' tab on the top Click on the 'Change' button Click on the “Member of Domain” button Also enter your domain name and computer name and then click "OK" You will now be prompted for a user account and password with rights to join a machine to the domain. • • How To Add Users To Your Samba Domain Add The Users In Linux First go through the process of adding users in Linux just like you would normally do. Map A Drive Share By default. Use a generic password then have users change it immediately from their workstation the usual way. In our case that would be user "administrator" with the corresponding smbpasswd password. Log in using any account in the /etc/smbpasswd file with your domain as the domain name. Mapping Using “My Computer” If the auto-mapping doesn't work then do the following: • • • • Let the user log into the domain Right click on the "My Computer" icon on the desktop Click on "Map Network Drive" Select a drive letter . This should be your Samba administrator.

The domain admin group parameter specifies users who will have domain admin rights.net ) [root@bigboy tmp]# todos /home/samba/netlogon/administrator.170 www. but will be interpreted bay a Windows machine. This will allow them to do such things as add software and configure network settings.bat • Add the following contents to mount the user's share as drive P: (for 'private'). We will add the contents of this file to all administrator's logon scripts. [root@bigboy tmp]# vi /home/netlogon/administrator. The argument is a space-separated list of user names or group names (group names must have an @ sign prefixed). As the file resides on a Linux box. Click on the check box "Reconnect at Logon".bat • The next page will show you how to add regular users to your new SAMBA domain Domain Groups And Samba Samba supports domain groups which will allow users who are members of the group to be able to have Administrator rights on each PC in the domain. Domain Groups also have the ability to join machines to the domain.rpmfind. then the user’s home directory. • Create a master logon batch file for administrator users.com • • Browse to the HOMENET domain. then the Samba server. then you can do the following and possibly make it into a script. to make the change permanent Mapping From The Command Line If you find the "My Computer" method too time consuming for dozens of users or if the PC doesn't have the feature available.linuxhomenetworking. but this is not currently supported in Samba. you’ll have to convert the file to the Windows format. In Windows. For example: domain admin group = <USER1> <USER2> @<GROUP> . (You can get this package from http://speakeasy.bat • Linux and Windows format text files slightly differently. This requires the 'todos' program to be installed. REM administrator net use P: \\bigboy\administrator • Make the file world readable: [root@bigboy tmp]# chmod +r /home/samba/netlogon/administrator.

Chapter 15 : Windows. Linux And Samba 171 How To Delete Users From Your Samba Domain Delete The Users In Linux First go through the process of deleting users in Linux just like you would normally do. [root@bigboy root]# . Here we are deleting the user zmeekins and all zmeekin’s files from the Linux server: [root@bigboy tmp]# userdel -r zmeekins Delete The Users Using smbpasswd Next. use the smbpasswd command with the "-x" switch [root@bigboy tmp]# smbpasswd -x zmeekins Deleted user zmeekins.

com .172 www.linuxhomenetworking.

www. We’ll assume the printer is locally attached to the parallel port. you may want to allow users to share resources such as floppy drives. This makes your Samba PDC a print server too! The method explained here requires the Windows printer driver to be loaded on every client machine. Adding The Printer To Linux By far the easiest way to add a printer in Linux is to use the GUI from the VGA console. This may be OK for a small home network but may be impractical for a huge corporate network. Here’s how to connect your printer directly to your PDC and make it available to all your windows workstations. Here are the menus to use: o o o o Click on the RedHat icon in the bottom left hand corner of the screen Click on System Settings Click on Printing Click on New . The way to get a GUI on the console is outlined in the runlevels chapter. N Adding A Printer To A Samba PDC Sharing printers amongst all your PCs is one of the advantages of creating a home network. directories and printers via the Samba server.173 Chapter 16 Sharing Resources With Samba =========================================== In This Chapter Chapter 16 Sharing Resources With Samba Adding A Printer To A Samba PDC Creating Group Shares in SAMBA Windows Drive Sharing With Your SAMBA Server © Peter Harrison. Here’s how to do it all.linuxhomenetworking.com =========================================== ow that you have Samba up and running.

Once you are in SWAT: o o o Select the "Printers" button Find your printer in the drag down menu If the printer name has a [*] beside it. restart Samba and go to the next section. but may not be visible on your network because Samba hasn't been restarted since creating the printer. Click on the “Status” tab at the top of the screen and restart smbd and nmbd to restart Samba. If this is the case.com o You'll now get the "Add a New Print Queue" menu Click "forward" You'll get the "Set the Print Queue name and Type" menu Give the printer an easy to remember name. edit/create the printer Click on the “Commit Changes” button to create an updated /etc/samba/smb. If this isn't the case. I called the printer queue EpsonC60) Click the local printer button Click "forward" You'll get the "Configure a Local Printer" menu Select /dev/lp0 as I assume the printer is on the parallel port (not USB) You'll get the "Select Print Driver" menu Scroll to the printer Double click on the name Select the driver Click "forward" You'll get the "Finish and Create the New Print Queue" menu Click finished Click "Apply" Do a test print to make sure all is OK o o o o o Make Samba Aware Of The Printer The easiest way to do this is using the Samba SWAT web interface. then it has been auto configured by Samba.linuxhomenetworking. o o o .174 www.conf file. (My printer is an Epson Stylus C60.

Go to the Add printer menu Click the "Next" button Select the "Network Printer" button to get the "Local or Network Printer" menu Click the "Next" button You should be on the "Locate Your Printer" menu Don't enter a name. you pre installed the driver Click the "OK" button The "Add Printer Wizard" will appear Select the manufacturer of your printer Select the printer model Click the "OK" button The "Add Printer Wizard" will prompt you whether you want to use this new printer as the default printer. click OK". Fortunately. Click next so you can browse for your printer You should be on the "Browse for Printer" menu Double Click on the name of your Linux Samba Box You should see the new printer Click on the printer name Click the "Next" button You may get a message stating "The server on which the printer resides does not have the correct printer driver installed. If you want to install the driver on your local computer. Select "Yes" or "No" depending on your preference Click the "Next" button The "Completing the Add Printer Wizard" menu will appear Click the "Finish" button o o o o o o o o .Chapter 16: Sharing Resources With Samba 175 Configure The Printer Driver On The Workstations o Download the Windows printer driver from the manufacturer and install it.

linuxhomenetworking. For instance. If one user is designated as the leader. Create The Directory And User Group o Create a new Linux group parents: [root@bigboy tmp]# /usr/sbin/groupadd parents o Create a new directory for the group's files. Click on the “Create Share” button. let’s say “onlyparents”. For example. create the share in Samba using SWAT. .com o The new printer should now show up on the Windows Printers menu in "Control Panel" Send a test print. Click on the “Status” tab at the top of the screen and restart smbd and nmbd to restart Samba. Here’s how it’s done. let's add user "father" to the group. Click on the shares button then enter the name of the share you want to create. parents working in a home office environment may need a place where they can share.conf file. subgroups of a family need a share that is fully accessible by all members of the group. you might want to change the chown statement to make them owner [root@bigboy tmp]# mkdir /home/parent-files [root@bigboy tmp]# chown parents /home/parent-files [root@bigboy tmp]# chmod 0770 /home/parent-files o Next we add the group members to the new group. o Creating Group Shares in SAMBA On occasion. where parents is the name of the Linux user group. Make sure the path maps to “/home/parent-files” and make the valid users be @parents.176 www. Click on the “Commit Changes” button to create a new /etc/samba/smb. [root@bigboy tmp]# /usr/sbin/usermod -G parents father Configure The Share In SWAT o o o o o Finally. distribute or collaboratively work on documents.

DVD. Windows Setup The Windows client box should first be setup as a member of a Samba domain or workgroup. to make the change permanent Windows Drive Sharing With Your SAMBA Server You can also access a CD. ZIP. In this section we’ll attempt to share a ZIP drive. Windows 98/ME • • • • Double click 'My Computer' Right click on the ZIP drive and choose 'Sharing' Set the Share Name as 'zip' with the appropriate access control Restart windows Windows 2000 • • • • Double click 'My Computer' Right click on the ZIP drive and choose 'Sharing' Set the Share Name as 'zip' and the appropriate access control Logout and login again as normal using your current login .conf file should have an entry like this at the end: # Parents Shared Area [only-parents] path = /home/parent-files valid users = @parents Map The Directory Using “My Computer” o o o o o o Let the user log into the domain from a remote PC Right click on the "My Computer" icon on the desktop Click on "Map Network Drive" Select a drive letter Browse to the HOMENET domain. The next step is to make the ZIP drive shared. floppy or hard drive installed on a Windows Client from the Samba server. then the share named only-parents Click on the check box "Reconnect at Logon". then the Samba server.Chapter 16: Sharing Resources With Samba 177 Your /etc/samba/smb.

0.255.1.178 www.0. Here’s how to do it.100 bcast=192.255.1.253 ) Password: Domain=[HOMENET] OS=[Windows 5.255 nmask=255.1.255.linuxhomenetworking.253 ( 192.---.1 bcast=127.1] Server=[Windows 2000 LAN Manager] Sharename Type Comment --------.168.------Note: You could have got the same result using the following command. .0 added interface ip=127.0.255 nmask=255.1.------IPC$ IPC Remote IPC D$ Disk Default share print$ Disk Printer Drivers SharedDocs Disk zip Disk Printer2 Printer Acrobat PDFWriter ADMIN$ Disk Remote Admin C$ Disk Default share Server Comment --------. though it is less secure: [root@bigboy tmp]# smbclient -L WinClient -U username%password Create A ZIP Drive Mount Point On Your Samba Server You’ll need to create the mount point on the Linux server in order to mount and access the ZIP floppy.255. You should get output like this when using the username's corresponding password: [root@bigboy tmp]# smbclient -L WinClient -U username added interface ip=192.0.0 Got a positive name query response from 192.com Windows XP • • • • Double click 'My Computer' Right click on the ZIP drive and choose 'Sharing and Properties' Set the Share Name as 'zip' and the appropriate access control Logout and login again as normal using your current login Test Your Windows Client Configuration Use the smbclient command to test your share. You should substitute "WinClient" with the name of your widows client PC and "username" with a valid workgroup/domain username that normally has access to the Windows client.168.168.168.------Workgroup Master --------.

Incompatible versions will give errors like this: [root@bigboy tmp]# smbmount //winclient/zip /mnt/zip -o username=username Password: 27875: session setup failed: ERRDOS .) SMB connection failed .password=password //winclient/zip /mnt/zip Using The smbmount Command Method Some versions of Linux support the smbmount command to mount the remote drive.Chapter 16: Sharing Resources With Samba 179 Prompted For Password Method [root@bigboy tmp]# mkdir /mnt/zip [root@bigboy tmp]# mount -t smbfs -o username=username //winclient/zip /mnt/zip Not Prompted For Password Method [root@bigboy tmp]# mkdir /mnt/zip [root@bigboy tmp]# mount -t smbfs -o username=username.ERRnoaccess (Access denied.

linuxhomenetworking.com .180 www.

linuxhomenetworking.181 Chapter 17 Configuring DNS =========================================== In This Chapter Chapter 17 Configuring DNS What Is DNS? What Is BIND? When To Use A DNS Caching Nameserver When To Use A Regular DNS Server When To Use Dynamic DNS How To Download and Install The BIND Packages How To Get BIND Started The /etc/resolv.linuxhomenetworking. .conf File Configuring A Caching Nameserver Configuring A Regular Nameserver How To Migrate Your Website In-House DHCP Considerations For DNS © Peter Harrison.com =========================================== You can make your Linux box into your home network's DNS nameserver. the Domain Name System (DNS) is the way in which a URL or domain like www. the daemon that responds to DNS queries from remote machines. What Is DNS? As explained on the introduction to networking concepts chapter.com is converted to an IP address. here’s how. What Is BIND? BIND is an acronym for the "Berkeley Internet Name Domain" project which maintains the DNS related software suite that runs under Linux. The most well known program in BIND is "named". www.

2. then a regular DNS server is what you require.1-9.rpm How To Get BIND Started • You can use the chkconfig command to get BIND configured to start at boot: . In this case a separate DNS server is unnecessary. If your router/firewall is getting its Internet IP address using DHCP then you must consider dynamic DNS. Off the shelf router/firewall appliances used in most home networks will usually act as both the caching DNS and DHCP server. the most frequently requested information to reduce the lookup overhead of subsequent queries.0 was version 9. As of this writing the latest version of the BIND suite for RedHat 8.com When To Use A DNS Caching Nameserver DNS caching servers should be used by the machines on your network to provide DNS information that it has learned from the authoritative DNS servers of the Internet. Setting up a caching DNS server is fairly straightforward and will work whether or not your ISP provides you with a static or dynamic Internet IP address. regular nameservers are used as the authoritative source of information. [root@bigboy tmp]# rpm -Uvh bind-9. This chapter assumes that you are using “static” Internet IP addresses. the chapter on RPMs covers how to do this in detail. Caching DNS servers then store (or cache). How To Download and Install The BIND Packages Most RedHat Linux software products are available in the RPM format.i386. If you need a refresher. If your home PCs get their IP addresses using DHCP. Once you have set up your caching DNS server you will then have to configure each of your home network PCs to use it as their DNS server. A caching DNS nameserver is only used as a reference. then a regular DNS server would be the way to go. “fixed” or “static” IP address or via a changing “DHCP” method. When To Use A Regular DNS Server If you host your own website at home with full control of all the web domains and your ISP provides you with a “fixed” or “static” IP address. When To Use Dynamic DNS Your DSL ISP will assign IP addresses to your home either with an unchanging. If you want to advertise your website www. It comes standard with the RedHat installation CDs. then you will have to configure your DHCP server to make it aware of the IP address of your new DNS server.com to the rest of the world.my-site. Downloading and installing RPMs isn’t hard.1-9.182 www.linuxhomenetworking.2. Note: Regular nameservers are also caching nameservers by default.

Chapter 17: Configuring DNS 183 [root@bigboy tmp]# chkconfig --level 35 named on • To start/stop/restart BIND after booting [root@bigboy tmp]# /etc/init.1.d/named restart • Remember to restart the BIND process every time you make a change to the conf file for the changes to take effect on the running process. If there is more than one nameserver.com.com net my-site.102 provide DNS name resolution.168. 192.net my-site.100 nameserver 192.102 .d/named stop [root@bigboy tmp]# /etc/init.d/named start [root@bigboy tmp]# /etc/init.com If you refer to another server just by its name without the domain added on. The domains in this list must separated by spaces.com. The /etc/resolv.168.org nameserver 192.net and my-site.conf File This file is used by DNS clients (servers not running BIND) to determine both the location of their DNS server and the domains to which they belong.1. If the server is bigboy. DNS on your client will append the server name to each domain in this list and do an nslookup on each to get the remote servers’ IP address. Domain • Search • Here is a sample configuration in which: • The client server’s main domain is my-site. you’ll need to have multiple “nameserver” lines. the first contains a keyword and the second contains the desired value(s) separated by commas.1. It generally has two columns.168.org which should be searched for short hand references to other servers. There should be only one entry per “nameserver” keyword.my-site.100 and 192. domain my-site. • Two nameservers.168. This is a handy time saving feature to have so that you can refer to servers in the same domain by only their servername without having to specify the domain. Here is a list of keywords: Keyword Nameserver • Value IP address of your DNS nameserver. then the entry would just be my-site.com search my-site.1. The local domain name to be used by default. but it also is a member of domains my-site.

Configuring named.158. o .0.184 www.253.1 New Entry # nameserver 192.0. though not explicitly stated. the file my-site. The zone file is named my-site. Configuring A Regular Nameserver For the purposes of this tutorial.168. the subnet that has been assigned to you by your ISP is 97.my-site.255.com" { type master.linuxhomenetworking.24 with a subnet mask of 255.com Configuring A Caching Nameserver The RedHat default installation of BIND is configured to convert your Linux box into a caching nameserver.conf o The main DNS configuration is kept in the file /etc/named.255.0.168. The only file you have to edit is /etc/resolv. zone "my-site. There are usually two zone areas in this file: Forward zone file definitions which list files to map domains to IP addresses Reverse zone file definitions which list files to map IP addresses to domains In this example the forward zone for www.0.com is being set up by placing the following entries at the bottom of the /etc/named.1 Old Entry nameserver 192.conf file.1 The next step is to make all the other machines on your network point to the caching DNS server as their primary DNS server.conf which is used to tell BIND where to find the configuration files for each domain you own.zone and.248 (/29).conf in which you’ll have to comment out the reference to your previous DNS server (most likely your router) with a "#" or make it point to the server itself using the universal localhost IP address of 127.1 or: nameserver 127.1.1. notify no.zone should be located in the default directory of /var/named.

in-addr.zone". allow-query { any.zone.x IP address and get back the true name of the server assigned that IP address.zone".arpa" { type master. file "253. notify no. file "my-other-site. MX. your zone files are located in the directory /var/named. zone "my-other-site. }. . A and CNAME) which govern different areas of BIND.com using a zone file named myother-site. }. zone "253. NS. notify no. the rest of the records are relatively straight forward. This is rarely done for home based sites. By default.com" { type master.” character then typing in the text of your comment. It is the most counter-intuitive of them all. you can place a comment at the end of any line by inserting a semi-colon “.Chapter 17: Configuring DNS 185 allow-query { any. SOA. You can also insert additional entries in the /etc/named. Though you would normally think a record would be a single line. It is especially difficult to do this with your DSL ISP if you have less than 256 static IP addresses (also known as a "Class C" block of addresses). }. }. Here is an example for my-other-site. o The reverse zone definition below is optional for a home / SOHO DSL based web site. }.158. The SOA Record The very first record is the Start of Authority (SOA) record which contains general administrative and control information about the domain. I’ll explain of them below and then follow it all up with an example.158. the SOA format spans several. file "my-site.253. Configuring The Zone Files o o o In all zone files.158.97. Note: the reverse order of the IP address in the zone section is important. It just makes you able to do an nslookup query on the 97. Each zone file contains a variety of records (eg.conf file to reference other web domains you host.97".

Usually in the date format YYYYMMDD with single digit incremented number tagged to the end." The email address of the nameserver administrator. As of BIND version 9 this value is overridden by the $TTL command at the very top of the configuration file. 2. Slaves aren't really used in home / SOHO environments. The email address must also be followed by a ". Slaves aren't really used in home / SOHO environments. The amount of time external caching DNS servers should keep your DNS information before flushing the data from the cache. The slave's retry interval to connect the master in the event of a connection failure." Signifies that we’re about to define some performance related variables. Tells the slave DNS server how often it should check the master DNS server.186 www. Total amount of time a slave will retry to contact the master before expiring the data it contains. The regular "@" in the e-mail address must be replaced with a ". 3 4 5 Name @ IN SOA Nameserver Email • • • • • • 6 2 1 “(“ Serial • • • 3 1 Refresh • Description Signifies that the SOA record is about to begin Fully qualified name of your primary nameserver. Signifies that we’re all finished with the variables. A serial number for the current configuration. Must be followed by a ". Slaves aren't really used in home / SOHO environments.com SOA Record Format Line # 1 Column # 1. 4 1 Retry • 5 1 Expire • 6 1 Minimum TTL • • 2 “)“ • ." instead.linuxhomenetworking.

Server name "A" IP address of server CNAME "alias" or "nickname" for server "CNAME" "A" record name for server N/A **The Fully Qualified Domain Name (FQDN) is the full DNS name of the server such as mail." at the end of a host name in a SOA.Chapter 17: Configuring DNS 187 NS.com. and you will find your mail server only accepting mail for the domain my-site. BIND will attach the my-site. So an "A" record with "www" will be assumed to refer to www. the NS." N/A A Maps an IP address to each server in your domain. NS. BIND will automatically tack on the domain name.mysite." after the domain in the MX record for my-site." "MX" CNAME of mail server or the mailserver's FQDN** followed by a ".1 Provides additional alternate "alias" names for servers listed in the "A" records.0. A or CNAME record.com at the end. There must always be an entry for localhost 127. NS.com. MX.0. A and CNAME Record Formats Record Description First Column Second Column Third Column IP address or CNAME of the nameserver Mail server priority Fourth Column NS Lists the name of the nameserver for the domain Lists the mail servers for your domain such as mysite.com o Note: If you don't put a ". but if you forget to put the ".my-site.my-site.com.com Blank "NS" N/A MX Domain. MX. This may be OK in most cases. MX. A And CNAME Records Unlike the SOA record.com. followed by a ". . A and CNAME records each occupy a single line and the records each have a very similar layout.

NS www .253.26 www Notice that in this example: o Server www.1 97. ( 200211152 . refresh. mail server and web server being the same machine.com.com. Zone file for my-site.253. . .0. The minimum TTL is set to 3600 seconds. The full zone file .253.158. . The MX record for my-site.my-site. Primary nameservers are more commonly called “ns1” and secondary nameservers “ns2”. You MUST increment it after editing the file or else BIND will not apply the changes you made when you restart "named".26 97. then you’d have an "A" record entry for each like the example below. minimum.134 97.188 www. Primary Mail Exchanger A A CNAME 127. .com "mail" is actually a CNAME or "alias" for the web server "www". seconds 3600 .com Sample Forward Zone File Here is a working example of the zone file for my-site. serial# 3600 . www mail ns o A A A 97. seconds 3600 ) . hostmaster.linuxhomenetworking.com. localhost www mail MX 10 mail .my-site. seconds .com points to the server named mail. In corporate environments there may be a separate nameserver for this purpose. but the overriding $TTL value is 3 days.125 o o o The serial number is extremely important. So here we have an example of the nameserver.com .158. . If they were all different machines.com. Inet Address of nameserver my-site.0.com is nameserver for my-site. $TTL 3D @ IN SOA www.158.my-site.com.158.253. expire. retry.my-site. So remote DNS caching servers will store learned DNS information from your zone for 3 days before flushing it out of their caches. but in the home / SOHO environment it is not necessary to differentiate. seconds 3600 .

You may also want to create a reverse zone file for the public NAT IP addresses for your home network. .253. .my-site. dhcp-32.168.my-site.1. What do the PCs on your home network need to see? They need to see DNS references to the real IP address of the webserver. .my-site. serial number refresh.168. . 100 103 102 105 32 33 34 35 36 PTR PTR PTR PTR PTR PTR PTR PTR PTR bigboy.com. SMTP mail relay wouldn’t work for PCs that get their IP addresses via DHCP if these lines weren’t included. . seconds minimum.com.my-site.168. Unfortunately ISP’s won’t usually delegate this ability for anyone with less than a “Class C” block of 256 IP addresses.com. seconds . 200303301 8H 2H 4W 1D ) hostmaster. www . .my-site. This is because NAT won’t work properly if a PC on your home network attempts to connect to the external 97.158. reggae.com.26 NAT IP address of your webserver.26 address of the webserver.my-site.my-site. dhcp-33.com.158. smallfry. seconds expire.com. 192. seconds retry. dhcp-34.my-site.my-site.com.com. Most home DSL sites wouldn’t qualify.100.253. . Zone file for 192.Chapter 17: Configuring DNS 189 Sample Reverse Zone File Now we need to make sure that we can do an nslookup query on all our home network’s PCs and get their correct IP addresses.com. .my-site.32 to 192. . NS . Filename: 192-168-1. ochorios. $TTL 3D @ IN SOA ( www. This is very important if you are running a mail server on your network as sendmail typically will only relay mail from hosts whose IP addresses resolve correctly in DNS. dhcp-35.zone .1.36 which are the addresses our DHCP server issues.1.com.com. dhcp-36. Here is a sample reverse zone file for our network.my-site. Nameserver Address Note: I have included entries for addresses 192.168.1.x . What You Need To Know About NAT And DNS The above examples assume that the queries will be coming from the Internet with the zone files returning information related to the external 97.

conf file I use for my home network.253.linuxhomenetworking.zone for lookups related to the 97. localhost. This is done by first defining access control lists (ACLs) and then referring to these lists within each view section with the match-clients statement. You could also have a file called my-site-home.168. For example. }. The creation of the my-site-home.X network which Internet users would see. This /etc/named." IN { type hint.190 www. view "internal" { // What the home network will see match-clients { localnets.zone file is fairly easy. }.158.zone".127. The first section will be called “internal” and will list the zone files to be used by your internal network.arpa" IN { type master.0. // ACL statement acl "trusted-subnet" { 192. }.conf entry would be inserted in the “external” section.0. file "localhost.0 network.zone for lookups by home users on the 192. This entry would be inserted in the “internal” section. "trusted-subnet".158. BIND has a way around this called “views”.17/24. file "named.127. The views feature allows you to force BIND to use pre-defined zone files for queries from certain subnets. }. Just copy it form the my-site. file "named. “any” which is self explanatory. The second view called “external” will list the zone files to used for Internet users.com Don’t worry.in-addr.168. There are some built-in ACLs: “localhost” which refers to the DNS server itself. Note: You must place your “localhost”. allow-update { none.zone file and replace all references to 97.1. All the statements below were inserted after the “options” and “controls” sections in the file. Here’s a summary of how it’s done: o Place your zone statements in the /etc/named. zone ". This means it’s possible to use one set of zone files for queries from the Internet and another set for queries from your home network. }. “localnets” which refers to all the networks to which the DNS server is directly connected.arpa” and ". .ca".conf file in one of two “views” sections.in-addr.1. you could have a reference to a zone file called my-site. }.253. Remember to increment your serial numbers! Here is a sample configuration snippet for the /etc/named. “0.X o You must also tell the DNS server which addresses you feel are “internal” and “external”. zone "localhost" IN { type master. }. allow-update { none.168.X with references to 192.local"." zone statements in the “internal” views section. zone "0.

com" { type master. }. zone "my-other-site. notify no. allow-update { none. }. . So in this case the local network (192. file "my-other-site-home. }. file "my-site. file "my-site-home. }.168.zone".192. Note: In the above example I included an ACL for network 192. Our network won’t need the “trustedsubnet” section in the match-clients line either.arpa" IN { type master. allow-query { any. allow-query { any. The home network we have been using doesn’t need to have the ACL statement at all as the built in ACLs “localnets” and “localhost” are sufficient. }. file "my-other-site. notify no. }. zone "my-site. }.168.zone".com" { type master.zone". zone "my-other-site. }. Once the ACL was defined.0 /24).1.com" { type master. zone "my-site. notify no.zone".168.17.17. view "external" { // What the Internet will see match-clients { any. Remember. I then inserted a reference to the “trusted-subnet” in the match-clients statement in the “internal” view.0) and localhost will get DNS data from the zone files in the “internal” view. }.in-addr. }. the other trusted network (192. allow-query { any.com" { type master.0 /24 called “trusted-subnet” to help clarify the use of ACLs in more complex environments. }. }. recursion no. this is purely an example. allow-query { any. file "192-168-1. }.zone".Chapter 17: Configuring DNS 191 zone "1. notify no.168.

1 [root@bigboy o tmp]# cd /var/named named]# ll named named 195 Jul 3 named named 2769 Jul 3 named named 433 Jul 3 root root 763 Oct 2 named]# chown named * named]# chgrp named * named]# ll named named named named named named named named named]# 195 2769 433 763 Jul Jul Jul Oct 3 3 3 2 2001 2001 2001 16:23 localhost.168.253.zone The configuration files above will not be loaded until you issue the following command to restart the named process that controls DNS (Make sure to increment your configuration file serial number before doing this): [root@bigboy tmp]# /etc/init.ca named.d/named restart Make Sure Your /etc/hosts File Is Correctly Updated The chapter covering Linux networking topics explains how to do this.26.1 -rw-r--r-.zone named.linuxhomenetworking.158. The actual IP address of the server is 192.1 [root@bigboy [root@bigboy [root@bigboy total 6 -rw-r--r-.1 -rw-r--r-.local my-site.local my-site. Configure Your Firewall The sample network we're using assumes that the BIND nameserver and Apache web server software run on the same machine protected by a router/firewall.1 -rw-r--r-.1 -rw-r--r-.192 www.com Loading Your New Configuration Files o Make sure your file permissions and ownership are OK in /var/named [root@bigboy [root@bigboy total 6 -rw-r--r-. Some programs such as sendmail require a correctly configured /etc/hosts file even though DNS is correctly configured. If your firewall is a Linux box. you may want to consider taking a look on the iptables chapter on how to do the NAT and allow DNS traffic trough to your nameserver. You'll have to employ NAT in order for Internet users to be able to gain access to the server via the Public IP address we chose.ca named. namely 97. which is a private IP address.zone named.zone 2001 2001 2001 16:23 localhost.1.1 -rw-r--r-. .1 -rw-r--r-.100.

You’ll therefore have to wait about this amount of time before you’ll start noticing people hitting your new website site. so that at least one of the nameservers is your new nameserver.com in the DNS zone file to a very low value.com. You'll have to do the following two steps: o First.com and my-site-test. you can then revert to the old configuration. Now your server will be a part of both my-site.com • Once testing is completed.my-site. for example www. it will take at least 3-5 days for all remote DNS servers to recognize the change.com or www.my-site. If you only have one. (This screen will prompt you for the server name only) o Sometimes.my-site.26 to map to ns. then you could either: o o Create a second nameserver record entry with the same IP address.Chapter 17: Configuring DNS 193 Fix Your Domain Registration Remember to edit your domain registration for "my-site.com • Test web traffic to www.158. but different name. it will take only 1 minute to see the results of the final DNS configuration switch to your new server. Domain registrars such as Verisign and RegisterFree usually provide a web interface to help you manage your domain. Your best alternative will be to request your existing service provider to set the TTL on my-site.com. • Test your applications using server. It normally takes about 3-4 days for your updated DNS information to be propagated to all 13 of the world’s root (“super duper”) nameservers.my-site-test. • Ask your existing web hosting provider to add a DNS entry for your new server in the my-site. create a second NAT entry on your firewall and then create the second nameserver record entry with the new IP address. As the TTL is usually set to 3 days.com Restart all the relevant applications. Once the propagation is complete. knowing it will rapidly recover within minutes rather than days. At the very least it should include the following steps: • There is no magic bullet which will allow you to tell all the caching DNS servers in the world to flush their caches of your zone file entries.com to handle your domain.my-site. or whatever it is. . say 1 minute.my-site-test. and different name.com or whatever your nameserver is called. you've logged in with the registrar's username and password. convert all the server configuration files to reference my-site.253.com". (This screen will prompt you for both the server's IP address and name) Then you'll have to assign ns. Give your web server a second IP address using an IP alias. Once. you'll have to create a new nameserver record entry for the IP address 97. If anything goes wrong.158. the registrar will require at least two registered nameservers per domain.com • Test mail to users @my-site-test.com and not my-site-test. How To Migrate Your Website In-House It is important to have a detailed migration plan if you currently use an external company to host your website and wish to move the site to a server at home or in your office. ( 97.com domain.26 in this case ). • Set up your server in house using a different domain.253. Also set the TTL on this domain to 1 minute.

then you may need to refer to the DHCP server chapter. you'll need to make it assign the IP address of the Linux box as the DNS server it tells the DHCP clients to use. you'll be able to see results of the migration within minutes. if you have concerns that your service provider won’t co-operate then you could explain to them that you want to test their failover capabilities to a duplicate server that you host in-house.linuxhomenetworking. • As both TTLs were set to 1 minute previously. If your Linux box is the DHCP server. . You can then decide whether the change will be permanent once you have failed over back and forth a few times. you don't have to host DNS or mail in-house.194 www.com • Coordinate with your web hosting provider to simultaneously update you domain registration’s DNS records to point to your new DNS server. you can set the TTL back to 3 days to help reduce the volume of DNS query traffic hitting your DNS server. • Once complete. this could be left in the hands of your service provider. DHCP Considerations For DNS If you have a DHCP server on your network. You can migrate these services in-house later as your confidence in hosting becomes greater. Remember. Finally.

Chapter 17: Configuring DNS 195 .

linuxhomenetworking.196 www.com .

.com domain.linuxhomenetworking.linuxhomenetworking. You will have to use the services of a third party DNS provider to provide DNS information for your my-site.com domain. Dynamic DNS: Used when you get a changing “dynamic” Internet IP addresses via DHCP from your ISP.com is converted to an IP address. DNS is the way in which a URL or domain like www. www. Your DNS server acts as the authoritative source of information for your my-site. If you want to host a website at home you have two DNS options: Static DNS: This is used when your ISP provides you with unchanging “fixed” or “static” Internet IP addresses.com =========================================== What Is DNS? As explained on the introduction to networking chapter. You can consider static DNS as the “traditional” or “regular” form of DNS.197 Chapter 18 Dynamic DNS =========================================== In This Chapter Chapter 18 Dynamic DNS What Is DNS? What Is Dynamic DNS? Dynamic DNS And NAT Router/Firewalls Dynamic DNS Prerequisites Installing And Using ez-ipupdate Installing And Using DDclient Testing Your Dynamic DNS © Peter Harrison.

com What Is Dynamic DNS? In many home networking environments. • register your domain name and read your DDNS provider's instructions on how to use their name servers. DDNS works by having webmasters register their DDNS sites on the DDNS provider's servers. Before considering using a dynamic DNS solution for hosting a website at home with dynamic IPs: • you must make sure your DSL provider will allow inbound connections. In these cases. An example of port forwarding with a Cisco PIX firewall is given in both the Cisco PIX firewall chapter and Net-Filter chapters. The webserver itself then has a DDNS client program running that updates the DDNS providers name servers with the most current DHCP IP address of the site. .my-site. This chapter describes how to configure the most popular Linux based DDNS software ez-ipupdate and DDclient in the following two configurations: • on a Linux box directly connected to the Internet • on a Linux box when protected by a NAT router / firewall Remember that unlike DSL. The reported value is therefore invalid.198 www.com in which the IP address is dynamically assigned. in order to conserve the limited number of IP addresses available for internet purposes. Dynamic DNS And NAT Router/Firewalls As discussed in the introduction to networking chapter. or else it will not work • be prepared for slower response times for your home based site than if you were using a static IP and a regular DNS service. the software can only report the true IP address of the Linux box's NIC interface.linuxhomenetworking. you'll have to also configure your router / firewall to do port forwarding to make all HTTP traffic destined for the IP address of the router / firewall to be exclusively NAT-ed and forwarded to a single server on your home network. dynDDS. NAT can fool the operation of some DDNS client software. Dynamic DNS (DDNS) allows you to host a website such as www. Some DDNS providers use more intelligent clients such as DDclient which can be configured to let the DDNS provider record the public IP address from which the data stream is originating. Once this is done.org offers a service to overcome this limitation. The web masters then register their domains with companies such as Verisign and RegisterFree and tells these registrars to direct queries to www.com to the servers of the DDNS provider. the DSL IP address is provided by DHCP and therefore changes from time to time. specifically HTTP. If the Linux box is being protected behind a NAT router / firewall then the NIC will report in its data stream to the DDNS provider a private IP address which no one can reach directly via the Internet.mysite. most cable modem providers may not allow you to host sites at home. most home router / firewalls will use Network Address translation (NAT) to map a single public DHCP obtained IP addresses to the many private IP addresses within your network.

For example miniDNS.minidns. You'll have to register your domain with a DNS registrar such as www. This chapter focuses on the services of miniDNS and DynDNS. You can give your machine's name or you can name the machine "www" to create a combined domainsubdomain of www. The ez-ipupdate installation will put the executable file in /usr/local/bin and all the files in the /tmp/filename directory will become extraneous.com will eventually query RegisterFree or Verisign which will then refer the query to your DDNS providers name servers which will have the most current IP address of your site because of the DDNS client software you are running at your home site. Use the following commands to extract the contents into a new subdirectory.registerfree. DNS queries for my-site.verisign. The cost is about US$20 per year.net will default to a domain such as machine-name.com or www. The miniDNS registration for your own domain requires you to use the "add DNS Record" link on the registration page to create your own domain.com.org you'll have to go with their paid service to get a customized domain name. you'll need DDclient in this case. Most DDNS providers assume you are going to create a sub domain of their main domain. [root@bigboy]tmp]# gunzip zip-tar-filename [root@bigboy]tmp]# tar –xvf tar-filename [root@bigboy]tmp]# cd /tmp/filename Follow the install instructions for doing the “make” or program compilation. With dynDNS.com.com or www.org.com and update the nameserver entries for your domain to point to the name servers of your DDNS provider.verisign. If you want to create your own domain such as my-site. First you add your domain such as my-site. you'll have to do a little extra work. some of which are listed on the Bibliography. Installing And Using ez-ipupdate Download the tar/gzip file to your server’s /tmp directory from the ez-ipupdate site listed in the Bibliography. .net. Then you must add a host record.com.Chapter 18: Dynamic DNS 199 Dynamic DNS Prerequisites Sign Up With A DDNS Provider First you'll have to register with a DDNS provider.my-site. They call it Custom DNS and it doesn't support ez-ipupdate.registerfree. o o Update Your DNS Registration If you have your own domain. you'll have to return to www.com which would be more intuitive to use.

6. In most Home / SOHO environments this will be the same as that of the firewalls external NAT IP address.linuxhomenetworking.conf in which you must specify: o o o Your registration username and password The host name you have selected for your Linux box The NIC interface which is connected to your DSL line.tar ddclient-3. If your Linux server is protected behind a firewall using NAT then the IP address of the NIC won't match that of the public IP address of the firewall and DDNS won't work properly.conf File ez-ipupdate uses a configuration file named /etc/ez-ipupdate. DDclient claims to offers support for a wide variety of routers from different manufacturers.2/COPYRIGHT ddclient-3. [root@bigboy tmp]# gunzip ddclient. DDclient has a simple "web" update mode which tells your DDNS provider to use the source IP address of the data stream used to update your DDNS record. the DDclient script can also log in and parse out the external IP address of the router. read the README file to give you an idea of what to do. ez-ipupdate And NAT The ez-ipupdate software runs as a daemon in memory continuously checking the IP address of your NIC. Remember.conf file for you to use. Installing And Using DDclient Another highly used solution is DDclient. Here is a sample: service-type=justlinux user=registration-username:registration-password host=servername.2/ ddclient-3. Before installing DDclient.6. Here is an example of the steps used to install it. some routers such as the netgear line may provide automatic DDNS service and you may not have to download the software.6. It then communicates this information to your dynamic DNS provider.my-site.200 www.gz [root@bigboy tmp]# tar -xvf ddclient.com interface=eth0 Note: The service-type line is specific to your dynamic DNS provider which will often provide a customized /etc/ez-ipupdate. In cases where "web" mode doesn't work.com The /etc/ez-ipupdate. Check the Bibliography for the DDclient URL. The developer of DDclient has recognized the limitations of using ez-ipupdate with NAT. you’ll have to use a client like DDclient which doesn’t have this limitation.2/COPYING … .tar.

d/init.top-level.redhat /etc/rc. The NIC interface which is connected to your DSL line.dyndns.2]# /sbin/chkconfig --add ddclient [root@bigboy ddclient-3.1 use=if. web=dyndns address is 97.6.d_ddclient.2]# ll -rw-r--r-.2]# In this case.158.your-other-domain. This is referenced on the line labeled “server”.conf file to use "web" #use=if.2]# cp sample-etc_rc.conf in which you must specify: o o o Your registration username and password The host name you have selected for your Linux box. Here is an example.2]# ddclient -daemon=0 -query use=if.mx. if=eth0 # via interfaces .253.6.0.top-level # Your domains here Before updating the file you can use DDclient with the "-query" option to tell you which is the best mode to use. You can then configure your /etc/ddclient.d/ddclient [root@bigboy ddclient-3.d_init. the simple web mode provides an acceptable value for your external IP address.2]# cp ddclient /usr/sbin/ The /etc/ddclient.conf File DDclient uses a configuration file named /etc/ddclient.26 [root@bigboy ddclient-3. if=wlan0 address is 192.168.backupmx) ## use=if. if=eth0 # via interfaces login=your-login # default login password=your-password # default password custom=yes \ server=members. \ protocol=dyndns2 \ your-domain.6.6. if=lo address is 127.6.1 root root 18007 Jan 3 2002 COPYING -rw-r--r-.0.org custom addresses ## ## (supports variables: wildcard.1 root root 869 Jan 3 2002 COPYRIGHT … … … [root@bigboy ddclient-3. [root@bigboy ddclient-3.Chapter 18: Dynamic DNS 201 … … [root@bigboy tmp]# cd dd* [root@bigboy ddclient-3.org.1.6. Here is a sample using interface eth0: ## dyndns.100 use=web.

com Server: 127.com command from your Linux command prompt and see whether you are getting a valid response.com use=web # via web Testing Your Dynamic DNS You can test your dynamic DNS by: • Looking at the status page of your DNS provider and making sure the IP address that matches your "www" site is the same as your router / firewall's public IP address.194.214#53 > www.com: NXDOMAIN Note: This error could also be due to the fact that your domain hasn't propagated fully throughout the Internet. .214#53 Name: www. You can test to make sure everything is OK by forcing NS lookup to query the nameservers directly.com Address: 12.my-site.minidns. Test it by asking a friend to access your web server by pointing their browser to the external IP address of your router / firewall.com Server: ns1.net Default server: ns1.my-site. you will get an error message like this: [root@bigboy tmp]# nslookup www.my-site.64.linuxhomenetworking.0.51.235. The example below queries the miniDNS name server: [root@bigboy tmp]# nslookup > server ns1. If you failed to add your host record.minidns.0. • Using the nslookup www.0.96 > Testing Port Forwarding Remember to read the configuration manual of your router / firewall to activate port forwarding.my-site.64.1 Address: 127.0.minidns.net Address: 202.my-site.1#53 ** server can't find www.51.202 www.net Address: 202.

the RedHat 8. the chapter on RPMs covers how to do this in detail. If you need a refresher.0.linuxhomenetworking.40-8. The Apache online documentation gets a little complicated.rpm .0 RPM as of this writing was: httpd-2. Downloading and installing RPMs isn’t hard. www.0 © Peter Harrison.com =========================================== This is page outlines how to create multiple websites using a single IP address for a basic home configuration. • For example.203 Chapter 19 The Apache Web Server =========================================== In This Chapter Chapter 19 The Apache Web Server Download and Install The Apache Package How To Get Apache Started Configuring DNS For Apache General Configuration Steps Configuration – Multiple Sites And IP Addresses Using Data Compression On Web Pages Apache Running On A Server Behind A Firewall File Permissions And Apache How To Protect Web Page Directories With Passwords Issues When Upgrading To Apache 2. It is best to use the latest version of Apache. Download and Install The Apache Package Most RedHat Linux software products are available in the RPM format.i386.

com • Install the package using the rpm command [root@bigboy tmp]# rpm -Uvh httpd-2.204 www.linuxhomenetworking.d/httpd restart • You can test whether the Apache process is running with the following command. See either the Static DNS or Dynamic DNS pages on how to do this.d/httpd stop [root@bigboy tmp]# /etc/init.40-8.d directory to start/stop/restart Apache after booting [root@bigboy tmp]# /etc/init. . Examples of this will follow. General Configuration Steps The configuration file used by Apache is /etc/httpd/conf/httpd.0.d/httpd start [root@bigboy tmp]# /etc/init. you should get a response of plain old process ID numbers: [root@bigboy tmp]# pgrep httpd Configuring DNS For Apache Remember that you will never receive the correct traffic unless you have configured DNS for your domain to make your new Linux box web server the target of the DNS domain's www entry. Apache expects its HTML files to be located in the /var/www/html directory How To Get Apache Started • Use the chkconfig configure Apache to start at boot: [root@bigboy tmp]# chkconfig --level 35 httpd on • Use the httpd init script in the /etc/init.conf.rpm By default.i386.

158. The Apache SSL module demands at least one explicit <VirtualHost> directive for IP based virtual hosting. which is used frequently in credit card and shopping cart web pages.conf file is used to tell Apache the IP addresses which will participate in this feature.Chapter 19: The Apache Webserver 205 Named Virtual Hosting You can make your web server host more than one site per IP address by using Apache's "named virtual hosting" feature. This makes configuration easier.26 The <VirtualHost> sections in the file then tell Apache where it should look for the web pages used on each web site. When you use wild cards. then it uses the configuration for that server. Here is the format: <VirtualHost 97. Here is the format: NameVirtualHost 97.158. You can also list secondary domain names which will serve the same content as the primary ServerName using the ServerAlias directive. You must specify the IP address for which each <VirtualHost> section applies. In this case you will not have a NameVirtualHost directive for the IP address." IP Based Virtual Hosting The other virtual hosting option is to have one IP address per website which is also known as IP based virtual hosting. then wild cards won’t work.253. If it finds one. If no matching virtual host is found.158. As explained on the apache website: "When a request arrives. A Note On Virtual Hosting And SSL It is common for system administrators to replace the IP address in the <VirtualHost> and NameVirtualHost directives with the “*” (all IP addresses) wildcard character.26> Directives for site #2 </VirtualHost> Within each <VirtualHost> section you then specify the primary website domain name for that IP address with the ServerName directive. If it is. then it will look at each <VirtualHost> section with a matching IP address and try to find one where the ServerName or ServerAlias matches the requested hostname. The NameVirtualHost directive in the /etc/httpd/conf/httpd.253.26> Directives for site #1 </VirtualHost> <VirtualHost 97. Apache interprets it as an overlap of name based and IP based <VirtualHost> directives and will give errors like this because it can’t make up its mind about which method to use: . If you installed Apache with support for secure HTTPS / SSL. then the first listed virtual host that matches the IP address will be used. The directory where the index page for that site is located is defined with the DocumentRoot directive. the server will first check if it is using an IP address that matches the NameVirtualHost. and you must only have a single <VirtualHost> section per IP address.253.

If you think this is a server error.conf file: Include conf.d/*.d/perl.d/php.conf file you'll need to edit. Include conf. This can be done by not loading all the modules from the /etc/httpd/conf.206 www. By default. The only exception would be the very first <VirtualHost> directive which defines the web pages to be displayed when matches to the other <VirtualHost> directives cannot be found. Configuration – Multiple Sites And IP Addresses What follows are snippets of the section of the /etc/httpd/conf/httpd. o o Continue using wildcards and disable SSL.conf Include conf. please contact the webmaster You have two options to overcome this problem.mixing * ports and non-* ports with a NameVirtualHost address is not supported.linuxhomenetworking. Use Wild Cards Sparingly The other choice is not to use virtual hosting statements with wild cards.conf You can therefore do a listing of all the files in this directory and specifically load all except ssl. all the modules in this directory are loaded with the following directive in the /etc/httpd/conf/httpd.conf You will then have to restart Apache for the changes to take effect. proceeding with undefined results If you try to load any webpage on your web server you’ll also notice an error like this: Bad request! Your browser (or proxy) sent a request that this server could not understand. In this case we load only the php and perl modules.com Starting httpd: [Sat Oct 12 21:21:49 2002] [error] VirtualHost _default_:443 -.d directory. In this scenario: . Run Apache with more careful use of wildcards Disabling SSL – (Not Recommended) If you wish to host a basic home SOHO website in which secure connections for credit card payments are unnecessary then you have the option of disabling SSL altogether.

com All other domains www.158.com. In this case is directory site1. • Traffic going to www.my-cool-site.253.com my-site.26 # # Match a webpage directory with each website # <VirtualHost *> DocumentRoot /var/www/html/site1 .158.my-other-site.default-site.26 is therefore required.com www.com and so traffic going to this domain • All other domains pointing to this server that don’t have a matching ServerName directive will get web pages from the directory defined in the very first <VirtualHost> section.com was also configured to point to alias IP address 97.253. The statements listed would normally be found at the very bottom of the file where virtual hosting statements normally reside.Chapter 19: The Apache Webserver 207 • The systems administrator for the server has previously created DNS entries for www. The domain www.253. www.default-site.26 Site1 Name Based 97.my-cool-site.com 97.253.26 97.test-site. Hitting these URLs will cause Apache to display the contents of file index.com falls in this category. A NameVirtualHost directive for 97.158.com. The last section of this configuration snippet has some additional statements to ensure read-only access to your web pages with the exception of web based forms using POSTs (pages with “submit” buttons).my-other-site.com must get content from subdirectory site2.26 on this web server.com.158. • There is no ServerName directive for www.158.253.158. • Traffic to www.test-site. www. Site www. www.html in this directory.158.com to map to an IP address 97.253.158.default-site. my-site.default-site.my-other-site. ServerName localhost NameVirtualHost 97.27. • Traffic to www. my-site.conf file is listed below. Web Hosting Scenario Summary Domain www.253.253.com.27 Site3 Site1 Name Based IP Based IP address 97. • Named virtual hosting will be required for 97.com www.253.26 as in this case we have a single IP address serving different content for a variety of domains.com www.com will get content from directory site4.my-site.my-site.com must get content from sub-directory site3.158.26 Directory Site2 Type of Virtual Hosting Name Based A sample snippet or a working httpd.com.test-site.com and www. Remember to restart Apache every time you update the conf file for the changes to take effect on the running process.my-site.my-cool-site.

208

www.linuxhomenetworking.com

</VirtualHost> <VirtualHost 97.158.253.26> DocumentRoot /var/www/html/site2 ServerName www.my-site.com ServerAlias my-site.com, www.my-cool-site.com </VirtualHost> <VirtualHost 97.158.253.26> DocumentRoot /var/www/html/site3 ServerName www.test-site.com </VirtualHost> <VirtualHost 97.158.253.27> DocumentRoot /var/www/html/site4 ServerName www.my-other-site.com </VirtualHost>

# # Make sure the directories specified above # have restricted access to read-only. # <Directory "/var/www/html/*"> Order allow,deny Allow from all AllowOverride FileInfo AuthConfig Limit Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory>

A Note On Virtual Hosting And DNS
You will have to configure your DNS server to point to the correct IP address used for each of the websites you host. The chapter on static DNS shows you how to configure multiple domains such as my-site.com and my-other-site.com on your DNS server.

Using Data Compression On Web Pages
Apache also has the ability to dynamically compress static web pages into gzip format and then send the result to the remote web surfers’ web browser. Most current web browsers support this format and will transparently uncompress the data and present it on the screen. This can significantly reduce bandwidth charges if you are paying for internet access by the megabyte.

Chapter 19: The Apache Webserver

209

First you need to load Apache version 2’s deflate module in your httpd.conf file and then use Location directives to specify what type of files to compress. After making these modifications and restarting Apache you will be able to verify from your /var/log/httpd/access_log file that the sizes of the transmitted HTML pages has shrunk. Here is a comparison of the file sizes in the Apache logs and the document directory, 78,350 bytes shrunk to 15,190 bytes, almost 80% compression. Log File

67.119.25.115 - - [15/Feb/2003:23:06:51 -0800] "GET /dns-static.htm HTTP/1.1" 200 15190 "http://www.siliconvalleyccie.com/sendmail.htm" "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 4.0; AT&T CSM6.0; YComp 5.0.2.6)" Corresponding Directory Listing [root@ bigboy tmp]# ll /web-dir/dns-static.htm -rw-r--r-1 user group 78350 Feb 15 00:53 /home/www/ccie/dns-static.htm [root@bigboy tmp]#

Compression Configuration Example
You can insert these statements just before your virtual hosting section of your httpd.conf file to activate the compression of static pages. Remember to restart Apache when you do.

LoadModule deflate_module modules/mod_deflate.so <Location /> # Insert filter SetOutputFilter DEFLATE # Netscape 4.x has some problems... BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.06-4.08 have some more problems BrowserMatch ^Mozilla/4\.0[678] no-gzip # MSIE masquerades as Netscape, but it is fine BrowserMatch \bMSIE !no-gzip !gzip-only-text/html # Don't compress images SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content Header append Vary User-Agent env=!dont-vary

210

www.linuxhomenetworking.com

</Location>

Apache Running On A Server Behind A Firewall
If your webserver is behind a firewall, and you are logged on a machine behind the firewall as well, then you may find problems when trying to access www.mysite.com of www.my-other-site.com. The reason for this is that due to NAT (Network Address translation), firewalls frequently won't allow access from their protected network to IP addresses that they masquerade on the outside. For example, in this case, Linux web server bigboy has an internal IP address of 192.168.1.100, but the firewall presents it to the world with an external IP address of 97.158.253.26 via NAT/masquerading. If you are on the inside, 192.168.1.X network, you may find it impossible to hit URLs that resolve in DNS to 97.158.253.26. The solution to this can also be solved with virtual hosting. You can configure Apache to serve the correct content when accessing www.mysite.com or www.my-other-site.com from the outside, and also when accessing the specific IP address 192.168.1.100 from the inside. Fortunately Apache allows you to specify multiple IP addresses in the <VirtualHost> statements to help you overcome this problem. Here is an example:

NameVirtualHost 192.168.1.100 NameVirtualHost 97.158.253.26 <VirtualHost 192.168.1.100 97.158.253.26> DocumentRoot /www/server1 ServerName www.my-site.com ServerAlias bigboy, www.my-site-192-168-1-100.com </VirtualHost>

File Permissions And Apache
Remember that if you get a "permissions" error in your web browser after trying to browse your newly configured website, then you need to ensure that you allow "others" to have read access to the directory all the way from the root directory "/" to the target sub-directory. The appendix has a short script that you can use to recursively set the file permissions in a directory to match those expected by Apache. You may also have to use the "Directory" directive to make Apache serve the pages once the file permissions have been correctly set. If you have your files in the default /var/www/html directory then this second step becomes unnecessary.

How To Protect Web Page Directories With Passwords
You can password protect content in both the main and sub-directories of your DocumentRoot fairly easily. I know of cases where persons will allow normal access to their regular web pages, but require passwords for directories / pages that show MRTG or Webalizer data. In this example we'll show how to password protect the /var/www/html directory.

Chapter 19: The Apache Webserver

211

• Apache has a password utility called "htpasswd" which can create "username password" combinations independent of your system login password for web page access. You have to specify the location of the password file, and if it doesn't yet exist, you'll have to include a "-c" or "create" switch on the command line. I recommend placing the file in your /etc/httpd/conf directory, away from the DocumentRoot tree where web users could possibly view it. Here is an example for a first user named "peter" and a second named "paul": [root@bigboy tmp]# htpasswd -c /etc/httpd/conf/.htpasswd peter New password: Re-type new password: Adding password for user peter [root@bigboy tmp]# [root@bigboy tmp]# htpasswd /etc/httpd/conf/.htpasswd paul New password: Re-type new password: Adding password for user paul [root@bigboy tmp]# • Make the .htpasswd file readable by all users. [root@bigboy tmp]# chmod 644 /etc/httpd/conf/.htpasswd • Create a .htaccess file in the directory to which you want password control with the following entries. Remember this will password protect this directory and all its sub directories. AuthUserFile /etc/httpd/conf/.htpasswd AuthGroupFile /dev/null AuthName EnterPassword AuthType Basic require user peter • • The AuthUserFile tells Apache to use the “.htpasswd” file The "require user" tells Apache that only user "peter" in the “.htpasswd” file should have access. If you wanted all “.htpasswd” users to have access then you'd replace this line with require valid-user "AuthType Basic" instructs Apache to accept basic unencrypted passwords from the remote users web browser.

• Set the correct file protections on your new .htaccess file in the directory /var/www/html. [root@bigboy tmp]# chmod 644 /var/www/html/.htaccess • Make sure your /etc/httpd/conf/http.conf file has an AllowOverride statement in a <Directory> directive for any directory in the tree above /var/www/html. In the example below, we want all directories below /var/www/ to require password authorization.

212

www.linuxhomenetworking.com

<Directory /var/www/html/*> AllowOverride AuthConfig </Directory> • You must also ensure that you have a <VirtualHost> directive that defines access to /var/www/html or another directory higher up in the tree. <VirtualHost *> ServerName 97.158.253.26 DocumentRoot /var/www/html </VirtualHost> • Restart Apache. Try accessing the web site and you'll be prompted for a password.

Issues When Upgrading To Apache 2.0
Incompatible /etc/httpd/conf/http.conf files
Your old configuration files will be incompatible when upgrading from Apache version 1.3 to Apache 2.X. The new version 2.X default configuration file is stored in /etc/httpd/conf/httpd.conf.rpmnew. For the simple virtual hosting example above, it would be easiest to: Save the old httpd.conf file with another name, httpd.conf-version-1.x for example. Copy the ServerName, NameVirtualHost, and VirtualHost sections from the old file and place them in the new file httpd.conf.rpmnew Copy the httpd.conf.rpmnew file an name it httpd.conf Restart Apache

o

o o

213

Chapter 20

Monitoring Server Performance
===========================================

In This Chapter Chapter 20
Monitoring Server Performance
SNMP MRTG Webalizer © Peter Harrison, www.linuxhomenetworking.com =========================================== Monitoring your system’s web performance can be done quite easily with a number of graphical tools available for Linux. These include MRTG for raw network traffic which is based on SNMP and Webalizer that monitors web site hits.

SNMP
What is SNMP?
Most routers and firewalls keep their operational statistics in Management Information Blocks (MIBs). Each statistic has an Object Identifier (OID) and can be remotely retrieved from the MIB via the Simple Network Management Protocol (SNMP). However, as a security measure, you need to know the SNMP password or "community string" to do so. There are a number of types of community strings, the most commonly used ones are the "Read Only" community string that only provides access for viewing statistics and system parameters. In many cases the "Read Only" community string or password is set to "public". There is also a "Read Write" community string for not only viewing statistics and system parameters but also for updating the parameters too.

SNMP on a Linux Server
By default, RedHat Linux has the NetSNMP package installed to provide SNMP services. NetSNMP uses a configuration file /etc/snmp/snmpd.conf in which the community strings may be set. The version of the configuration file that comes with Net-SNMP is quite complicated. I suggest

1 = INTEGER: 1 IF-MIB::ifIndex.2 = STRING: wlan0 IF-MIB::ifDescr.. .0 = INTEGER: 3 IF-MIB::ifIndex.0 = STRING: root@localhost SNMPv2-MIB::sysName.d/snmpd start Starting snmpd: [ OK ] [root@bigboy root]# • Test whether SNMP can read the "system" and "interface" information MIB [root@bigboy snmp]# snmpwalk -v 1 -c craz33guy localhost system SNMPv2-MIB::sysDescr.214 www.. [root@bigboy snmp]# snmpwalk -v 1 -c craz33guy localhost interface IF-MIB::ifNumber...18-14 #1 Wed Sep 4 11:57:57 EDT 2002 i586 SNMPv2-MIB::sysObjectID.com archiving it and using a much simpler version with only a single line containing the keyword "rocommunity" followed by the community string..0 = Timeticks: (425) 0:00:04.conf • Enter the following line in the new configuration file to set the Read Only community string to "craz33guy" rocommunity craz33guy • Configure Linux to start SNMP services on each reboot with the chkconfig command: [root@bigboy root]# chkconfig --level 345 snmpd on [root@bigboy root]# • You can then start SNMP to load the current configuration file.0 = STRING: bigboy . [root@bigboy root]# /etc/init.old [root@bigboy snmp]# vi snmpd. . .linuxhomenetworking.3 = STRING: eth0 . • Save the old configuration file [root@bigboy snmp]# cd /etc/snmp/ [root@bigboy snmp]# mv snmpd...... ...0 = STRING: Linux bigboy 2.1 = STRING: lo IF-MIB::ifDescr.conf. [root@bigboy snmp]# .10 SNMPv2-MIB::sysUpTime.25 SNMPv2-MIB::sysContact.3 = INTEGER: 3 IF-MIB::ifDescr.conf snmpd.2 = INTEGER: 2 IF-MIB::ifIndex.4. Here is an example of how to do that.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.

Now that we know SNMP is working correctly on your Linux server.d/httpd stop [root@bigboy tmp]# /etc/init.i386.0 is: mrtg-2.rpm o You can install the package like this: [root@bigboy tmp]# rpm -Uvh mrtg-2. You can easily create graphs of traffic flow statistics through your home network's firewall / router or even your Linux box's NIC cards using MRTG. The most current version as of this writing was apache 1.9.3.X. but you’ll need to configure Apache to start at boot using the chkconfig command: [root@bigboy tmp]# chkconfig --level 35 httpd on o Here’s how to start/stop/restart Apache after booting: [root@bigboy tmp]# /etc/init.9.11. Download and Install The MRTG Packages Most RedHat Linux software products are available in the RPM format.23 . The latest version of the RPM for RedHat 8. we can configure a SNMP statistics gathering software package such as MRTG to create online graphs of your traffic flows. This is available from the RedHat website or your installation CDs.d/httpd start [root@bigboy tmp]# /etc/init.d/httpd restart .Chapter 20: Monitoring Server Performance 215 Note: In this case we were polling localhost.17-8. [root@bigboy tmp]# rpm -Uvh apache-1. MRTG What is MRTG? MRTG (Multi Router Traffic Grapher) is a public domain package for producing graphs of various types of router statistics via a web page.i386. the chapter on RPMs covers how to do this in detail.23-14. You can poll any SNMP aware network device with SNMP enabled. All you need is the IP address and SNMP read only string and you’ll be able to get similar results. The RedHat RPM version seems to work with Apache 1. Install apache using the following command.rpm o MRTG runs automatically upon startup.rpm o You will also need to have a webserver package installed for MRTG to work. If you need a refresher. Downloading and installing RPMs isn’t hard.17-8.i386. The product is available from the MRTG website and also on your distribution CDs.3.

When the MRTG RPM is installed it creates a directory called /etc/mrtg in which all future configuration files are stored. Configuring MRTG By default.cfg [root@bigboy tmp]# o Next create the /var/www/html/mrtg/stats directory and copy all of MRTG’s standard “.0.1 --> 1 --snpo: confcache craz33guy@localhost: Ip 192.0 --> 3 --snpo: confcache craz33guy@localhost: Ip 127. In this example we'll use MRTG’s cfgmaker command to create a configuration file named localhost.cfg for the server "bigboy" using a read only community string of craz33guy. There are ways to specify other OIDs such as CPU and memory usage. All data files will be placed in the directory /var/www/html/mrtg/stats.1. We’ll be discussing the default configuration.0.png” image files into it.cfg \ -ifref=ip --global "workdir: /var/www/html/mrtg/stats" \ craz33guy@localhost o --base: Get Device Info on craz33guy@localhost: --base: Vendor Id: --base: Populating confcache --snpo: confcache craz33guy@localhost: Descr lo --> 1 --snpo: confcache craz33guy@localhost: Descr wlan0 --> 2 --snpo: confcache craz33guy@localhost: Descr eth0 --> 3 --snpo: confcache craz33guy@localhost: Ip 0. [root@bigboy tmp]# cfgmaker --output=/etc/mrtg/localhost.com By default Apache expects the HTML files for your website to be located in /var/www/html. Here are the steps you need to go through to create new configuration files.168.100 --> 2 --snpo: confcache craz33guy@localhost: Type 24 --> 1 --snpo: confcache craz33guy@localhost: Type 6 --> 2 --snpo: confcache craz33guy@localhost: Type 6 --> 3 (duplicate) --snpo: confcache craz33guy@localhost: Eth --> 1 --snpo: confcache craz33guy@localhost: Eth 00-06-25-09-6a-b5 --> 2 --snpo: confcache craz33guy@localhost: Eth 00-08-c7-10-74-a8 --> 3 --base: Get Interface Info --base: Walking ifIndex --base: Walking ifType --base: Walking ifSpeed --base: Walking ifAdminStatus --base: Walking ifOperStatus --base: Writing /etc/mrtg/localhost.0.0.linuxhomenetworking. MRTG will place its HTML files in /var/www/html/mrtg.216 www. [root@bigboy mrtg]# mkdir /var/www/html/mrtg/stats . MRTG will map the inbound and outbound data throughput rates on the device it is polling. but this is beyond the scope of this book.

168.cfg and remove the sections related to interfaces you don't need to monitor. [root@bigboy mrtg]# mrtg /etc/mrtg/localhost.old updating log file [root@bigboy mrtg]# mrtg /etc/mrtg/localhost.1. You'll get an error the two times as MRTG tries to rename old data files.cfg Can't locate package $VERSION for @MRTG_lib::ISA at /usr/bin/indexmaker line 49 .cfg as your argument three times.100.cfg Rateup WARNING: /usr/bin/rateup Can't remove localhost_192.1. you will find your devices at the very bottom.log to localhost_192.100. the first time it is run.1.100.cfg Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_192.168.cfg and comment out the one pointing to mrtg.png /var/www/html/mrtg/stats [root@bigboy mrtg]# o Edit /etc/mrtg/localhost.cfg device2.old updating log file [root@bigboy mrtg]# mrtg /etc/mrtg/localhost.cfg o Run MRTG using /etc/mrtg/localhost.1. and naturally.168.168. [root@bigboy mrtg]# indexmaker --output=index. Once this is done.100 was invalid as well Rateup WARNING: /usr/bin/rateup Can't remove localhost_192. This would most likely include the loopback interface L0: with the IP address of 127. The format of the command is: indexmaker --output=filename device1.0.html /etc/mrtg/localhost.cfg 0-59/5 * * * * root /usr/bin/mrtg /etc/mrtg/localhost.1 When the MRTG RPM is installed it places an entry in the /etc/crontab file to make MRTG run every 5 minutes using the default /etc/mrtg/mrtg.1. MRTG has no data files to move.cfg” files in your /etc/mrtg directory. don’t be fooled. you can point your browser to http://ip-address/mrtg/ to get a graphical listing of all the monitored interfaces.1. Add a new line referring to /etc/mrtg/localhost.cfg.0 and Indexmaker RedHat version 8 gives an error like this when running indexmaker.100 Rateup WARNING: /usr/bin/rateup The backup log file for localhost_192.100.0.Chapter 20: Monitoring Server Performance 217 [root@bigboy mrtg]# cp /var/www/html/mrtg/*.cfg [root@bigboy mrtg]# o You'll then want to use MRTG’s indexmaker command to create a combined index page to see all the graphs defined in all the various “. # 0-59/5 * * * * root /usr/bin/mrtg /etc/mrtg/mrtg.168.168. Note: The indexmaker command creates a very generic index page which is very similar to the MRTG home page.cfg configuration file.old updating log file Rateup WARNING: /usr/bin/rateup Can't rename localhost_192.cfg etc RedHat Version 8.

pm line 49 eval {.218 www./lib/mrtg2/MRTG_lib. By default MRTG provides only network interface statistics. Error: Unable to open DNS cache file /var/lib/webalizer/dns_cache.com/usage The Webalizer Configuration File Webalizer stores its configuration in the file /etc/webalizer. so if you have a default Apache installation you’ll be able to view your data by visiting http://www.. Webalizer reads your Apache log files and creates a set of web pages that allow you to view websurfer statistics for your site. This can be adjusted with the OutputDir directive in the file.daily/00webalizer script file and adding the –Q (Quiet) switch to the webalizer command like this: .mrtg.pm line 49 [root@bigboy mrtg]# You have a couple choices here: • • Run a version of indexmaker from an older version of RedHat Create your own custom index page to replace the default one in /var/www/html/mrtg. Make Webalizer run in Quiet Mode Webalizer has a tendency to create this message in your logs which according to the Webalizer site’s documentation is non-critical.conf. You can then add links to all the html files in the /var/www/html/mrtg/stats directory.. The information provided includes a list of your web site’s most popular pages sorted by “hits” along with traffic graphs showing the times of day when your site is most popular.com main::BEGIN() called at /usr/bin/. How To View Your Webalizer Statistics By default webalizer places its index page in the directory /var/www/html/usage. but you may want to adjust the directory in which Webalizer places your graphic statistics.. monthly and yearly statistics for your interfaces.. Webalizer What Is Webalizer? Webalizer is a web server log file analysis tool that comes installed by default on RedHat Linux.db You can make the software run in quite mode by editing the /etc/cron. The MRTG website www. Each night. The default settings should be sufficient for your web server.org has links to other sites that show you how to monitor other sub-systems on a variety of devices and operating systems./lib/mrtg2/MRTG_lib.my-site.linuxhomenetworking. weekly.} called at /usr/bin/. Using MRTG To Monitor Other Subsystems MRTG will generate HTML pages with daily.

. then /usr/bin/webalizer -Q fi exit 0 Once you’ve done this. Webalizer will function with few annoyances.Chapter 20: Monitoring Server Performance 219 #! /bin/bash # update access statistics for the web site if [ -s /var/log/httpd/access_log ] . however be aware that running in quiet mode could hide deeper problems that could occur in future.

linuxhomenetworking.220 www.com .

Windows users can use an email client such as "Outlook" or "Outlook Express" to download the mail to their local PC via POP. One of The process is different when sending mail via the mail server: o o . Once the mail arrives on the mail server it can be read in a number of ways: o o Linux users logged into the mail server can read their mail directly using a text based client such as "mail" or a GUI client such as Evolution. If the mail isn't destined for the mailbox of a local user.com =========================================== This chapter will help to show you how to set up a mail server for your home network.221 Chapter 21 Configuring Linux Mail Servers =========================================== In This Chapter Chapter 21 Configuring Linux Mail Servers Configuring Sendmail Configuring Your POP Mail Server © Peter Harrison. Configuring Sendmail An Overview Of How Sendmail Works Sendmail is the most popular Linux program for processing mail.linuxhomenetworking. If the mail is destined for a local user then sendmail will place the message in that person’s mailbox so that they can retrieve it using one of the methods above. Windows users also have the option of either keeping or deleting the mail on the mail server after it has been downloaded. It covers Sendmail which is responsible for relaying your mail to a remote user’s mailbox and also POP mail which is used to retrieve the mail from the mail box to your local PC via a mail client such as outlook Express. www. then sendmail will attempt to relay it to the appropriate destination mail server via the Simple Mail Transport Protocol or SMTP.

the PC of user "A" can delegate the SMTP processing to the mail server.rpm [root@bigboy tmp]# rpm -Uvh sendmail-8. Downloading and installing RPMs isn’t hard. Note:If mail relaying is not configured properly then your mail server could end up relaying SPAM. You can also test whether the sendmail process is running with the pgrep command.rpm [root@bigboy tmp]# rpm -Uvh sendmail-devel-8. Install all the packages in this order: [root@bigboy tmp]# rpm -Uvh sendmail-cf-8. See either the Static DNS or Dynamic DNS pages on how to do this. As of this writing the latest version of the sendmail suite was version 8. If you need a refresher. you should get a response of plain old process ID numbers: [root@bigboy tmp]# pgrep sendmail .222 www. the chapter on RPMs covers how to do this in detail.12.rpm o You can use the chkconfig command to get Sendmail configured to start at boot: [root@bigboy tmp]# chkconfig --level 35 sendmail on o To start/stop/restart sendmail after booting [root@bigboy tmp]# /etc/init.i386.5-7 .5-7.i386.12.d/sendmail restart o Remember to restart the sendmail process every time you make a change to the configuration files for the changes to take effect on the running process.d/sendmail start [root@bigboy tmp]# /etc/init.12. o It is best to use the latest version of sendmail as older versions have had a number of security holes. Simple sendmail security is outlined on this page.d/sendmail stop [root@bigboy tmp]# /etc/init.5-7 . Configuring DNS Remember that you will never receive mail unless you have configured DNS for your domain to make your new Linux box mail server the target of the DNS domain's MX record.12.5-7 .linuxhomenetworking.i386. Installing And Starting Sendmail Most RedHat Linux software products are available in the RPM format.com the main advantages of mail relaying is that when a PC user "A" sends mail to another user "B" on the Internet.

you'll get errors like this when running the script: # RH Ver 7.3# RH Ver 8. #!/bin/bash cd /etc/mail make m4 /etc/mail/sendmail. This must be installed. Both the newaliases and m4 commands depend on the sendmail-cf RPM package.mc:8: m4: Cannot open /usr/share/sendmailcf/m4/cf. This little script encapsulates all the required post configuration steps. if not. chmod 700 filename You’ll need to run the script each time you change any of the sendmail configuration files described in the sections to follow.d/sendmail restart Use this command to make the script executable.cf newaliases /etc/init. .mc > /etc/mail/sendmail.mc file.m4: No such file or directory [root@bigboy mail]# .0+ Errors With The Newaliases Command [root@bigboy mail]# newaliases Warning: .mc > /etc/mail/sendmail.Chapter 21: Configuring Linux Mail 223 Restart Sendmail After Editing Your Configuration Files In this chapter we’ll see that Sendmail uses a variety of configuration files which require different treatments in order for their commands to take effect. This may not be a good idea in a production system. The line in the script that restarts sendmail is only needed if you have made changes to the /etc/mail/sendmail.cf file is out of date: sendmail 8. but it has been included so that you don’t forget.cf /etc/mail/sendmail.12. Delete the appropriate "m4" line depending on your version of RedHat.5 supports version 10.cf m4 /etc/mail/sendmail.mc > /etc/sendmail.cf file is version 0 No local mailer defined QueueDirectory (Q) option must be set [root@bigboy mail]# Errors With The m4 Command [root@bigboy mail]# m4 /etc/mail/sendmail.

Why Sendmail Only Listens On The Loopback Interface By Default All Linux systems have a virtual loopback interface that only lives in memory with an IP address 127. It is often viewed as an intimidating file with its series of structured "directive" statements that get the job done.d/sendmail restart Shutting down sendmail: [ OK ] Shutting down sm-client: [FAILED] Starting sendmail: 554 5.com Errors When Restarting sendmail [root@bigboy mail]# /etc/init.0. and not a client. Sendmail needs to be also configured to listen for messages on the NIC interface. then the return value will be blank. We can verify that sendmail is running by first using the pgrep command which will return the sendmail process ID number once sendmail is running. Work in one of them and monitor the sendmail status output in the other using the command [root@bigboy tmp]# tail -f /var/log/maillog The /etc/mail/sendmail. Sendmail therefore uses the loopback address to send mail to users on the local box. SSH or console windows.1.0 QueueDirectory (Q) option must be set [FAILED] Starting sm-client: [ OK ] [root@bigboy mail]# The /var/log/maillog File Sendmail throws all its status messages in the /var/log/maillog file. Open two telnet.0 No local mailer defined 554 5.linuxhomenetworking.0. If it isn't running.mc File Most of sendmail's configuration parameters are set in this file with the exception of mailing list and mail relay security features.224 www.0. . The two most basic steps in configuring a Sendmail server are to modify this file to enable Sendmail to listen on the NIC interface and to make Sendmail to accept mail from valid web domains. As mail must be sent to a target IP address even when there is no NIC in the box.0. To become a server. Fortunately in most cases you won't have to edit this file very often. It is always good to monitor this file whenever you are doing changes.

the laptop and users on computers that do dnl not have 24x7 DNS do need this. The sendmail.0. bigboy the mail server will not accept email relayed from any of the other PCs on your network if they are not in DNS. Note: When sendmail starts. [root@bigboy tmp]# netstat -an | grep :25 | grep tcp tcp 0 0 127.0. Name=MTA') dnl NOTE: binding both IPv4 and IPv6 daemon to the same port requires dnl a kernel patch dnl DAEMON_OPTIONS(`port=smtp. so we use "netstat" and "grep" for "25" to see a default configuration listening only on IP address 127. Sendmail listens on TCP port 25. .0. It is also good practice to take precautions against SPAM by not accepting mail from domains that don't exist by commenting out the "accept_unresolvable_domains" feature too.mc To Make Sendmail Listen On NICs Too To correct this you'll have to comment out the daemon_options line in the /etc/mail/sendmail.0. dnl FEATURE(`accept_unresolvable_domains')dnl dnl FEATURE(`relay_based_on_MX')dnl You need to be careful with the accept_unresolvable_names feature. Family=inet6') dnl We strongly recommend to comment this one out if you want to protect dnl yourself from spam. However.0 and higher.cf for versions 8. dnl This changes sendmail to only listen on the loopback device 127.cf file and restart sendmail.Addr=127. it reads the file sendmail.0:* LISTEN [root@bigboy tmp]# Edit /etc/mail/sendmail.cf for its configuration. we have to regenerate a new sendmail.mc file with "dnl" statements.0.0.cf for versions up to 7.1. sendmail.cf file is located in different directories dependent on the version of RedHat you use.1:25 0.1 (loopback). /etc/sendmail.mc is a more user friendly configuration file and really is much easier to fool around with without getting burned.1 dnl and not on any other network devices.Chapter 21: Configuring Linux Mail 225 [root@bigboy tmp]# pgrep sendmail 22131 [root@bigboy tmp]# We can also see the interfaces on which Sendmail is listening with the “netstat” command. In our sample network. dnl DAEMON_OPTIONS(`Port=smtp. The chapter on DNS shows how to create your own internal domain just for this purpose. Regenerate The sendmail.0. Comment this out if you want dnl to accept email over the network. See the italicized lines in the example below. and /etc/mail/sendmail. Name=MTA-v6.0.3.Addr=::1.0.0.cf File Once finished editing the file.

226 www. The first section is near the top where the FEATURE statements usually are.0.mc file can seem jumbled.0:* LISTEN [root@bigboy tmp]# A General Guide To Using The sendmail.0.0.cf Restart sendmail to load the new configuration [root@bigboy tmp]# /etc/init.0.mc > /etc/mail/sendmail.0) [root@bigboy tmp]# netstat -an | grep :25 | grep tcp tcp 0 0 0. Here is a sample: dnl ***** Customised section 1 start ***** dnl dnl FEATURE(delay_checks)dnl FEATURE(masquerade_envelope)dnl FEATURE(allmasquerade)dnl FEATURE(masquerade_entire_domain)dnl dnl dnl dnl ***** Customised section 1 end ***** .3 [root@bigboy tmp]# m4 /etc/mail/sendmail.0.linuxhomenetworking.d/sendmail restart Shutting down sendmail: [ OK ] Starting sendmail: [ OK ] [root@bigboy tmp]# Now Make Sure Sendmail Is Listening On All Interfaces Sendmail should start listening on all interfaces (0.cf Redhat versions 8. and the second section is at the very bottom.0.mc > /etc/sendmail. Sometimes sendmail will archive this file when you do a version upgrade.mc File The sendmail.com Redhat versions up to 7.0+ [root@bigboy tmp]# m4 /etc/mail/sendmail. Having easily identifiable modifications in this file will make post upgrade reconfiguration much easier.0:25 0. To make it less cluttered I usually create two easily identifiable sections in it with all the custom commands I've ever added.

0." all by itself on the last line.another-site.. a poorly configured /etc/hosts file can make mail sent from your server to the outside world appear as if it came from users at localhost.100 localhost. pleased to meet you 250 HELP >>> MAIL From:<root@localhost.localdomain and not bigboy.168.com> 250 <example@another-site.localdomain>.com bigboy mail www Here the IP address is followed by the hostname.another-site.another-site.com LiteMail v3.02(BFLITEMAIL4A). Sender Ok >>> RCPT To:<example@another-site. example@another-site.1.com" domain and would ignore the security features of the access and relay-domains files we'll describe below. then you run the risk of having all your mail appear to come from localhost.com".. Connecting to mail.168.localdomain localhost bigboy. The server would therefore be open to relay all mail from any ".com.my-site..0.com) followed by the hostname and all the DNS CNAMEs assigned to the server's IP address. 220 ltmail.. via esmtp. Recipient Ok >>> DATA .221..1 192.com.localdomain and not bigboy. If bigboy had an entry like this: 192.localdomain> 250 <root@localhost.com Hello [67.. Here is a brief example: 127.localdomain 250-mx.com test text test text .mysite. 05 Oct 2002 06:48:44 -0400 >>> EHLO localhost.com (Wrong!!!) Sendmail would assume the server's name was my-site and that the domain was all of ".my-site.106].my-site.Chapter 21: Configuring Linux Mail 227 The /etc/hosts File It is very important to have a correctly configured /etc/hosts file.100 my-site. [root@bigboy tmp]# sendmail -v example@another-site.com.1. If you fail to put the IP address of your NIC in the /etc/hosts file altogether..my-site. Symptoms Of A Bad /etc/hosts File As discussed above. Sendmail uses this file to determine: o o The system name The domains it is responsible for relaying Sendmail looks for the IP address of your NIC in /etc/hosts and then assumes the first name after it is the fully qualified domain name of the server such as bigboy.domain (bigboy.com>.com. Use the sendmail program to send a sample email to someone in verbose mode. Enter some text after issuing the command and end your message with a single ". Sat.120.com..

localdomain. fix $j in config file [root@bigboy tmp]# With the accompanying error in /var/log/maillog log file that looks like this: Oct 16 10:23:58 bigboy sendmail[2582]: My unqualified host name (bigboy) unknown. my-super-duper-site. all mail sent from my-super-duper-site.. sleeping for retry The /etc/mail/relay-domains File The /etc/mail/relay-domains file is used to determine domains from which it will relay mail.another-site.com.. >>> QUIT [root@bigboy tmp]# Localhost.com and not destined for this mail server will be forwarded. the rejected email will be returned to localhost. or creating a new alias database file. You will probably get an error like this in /var/log/maillog if this happens: Oct 16 10:20:04 bigboy sendmail[2500]: g9GHK3iQ002500: SYSERR(root): savemail: cannot save rejected email anywhere Oct 16 10:20:04 bigboy sendmail[2500]: g9GHK3iQ002500: Losing . Sent (Message accepted for delivery) Closing connection to mail. PC2 will see that the mail originated from localhost. If mail sent from computer PC1 to PC2 appears to come from a user at localhost.localdomain and will think that the rejected email should be sent to a user on PC2 that may not exist.com .linuxhomenetworking.localdomain on PC1 and is rejected. (The newalias command will be explained later): [root@bigboy tmp]# sendmail -v root WARNING: local host name (bigboy) is not qualified. 250 Message accepted for delivery example@another-site. it is therefore an illegal internet domain.com 354 Enter mail. An error in the script could cause this type of message too. in this example "root". end with "." on a line by itself >>> ./qfg9GHK3iQ002500: savemail panic Note: You may also get this error if you are using a SPAM prevention program.com.228 www.localdomain is the domain that all computers use to refer to themselves. In this case. fix $j in config file [root@bigboy tmp]# newaliases WARNING: local host name (bigboy) is not qualified. for example a script based on the PERL module Mail::Audit. Another set of tell tale errors caused by the same problem can be generated when trying to send mail to a user . this file does not exist in a standard RedHat install. The contents of the relay-domains file should be limited to those domains that can be trusted not to originate spam. By default.

Remember that a server will only be considered a part of my-site. (In Outlook Express you set this using: Tools Menu -> Accounts -> Properties -> Servers) If you don't take the precaution of using this feature. Keywords include RELAY. If you delete /etc/mail/relay-domains. everyone on your 192.com.Chapter 21: Configuring Linux Mail 229 One disadvantage of this file is that it can only control mail based on the source domain which can be spoofed by SPAM email servers.0. two client PCs on your home 192.168. The /etc/mail/access file has more capabilities.0. OK (not ACCEPT) and DISCARD. In the sample file below. the mail server will only relay mail for those PCs on your network that have their email clients configured to use the mail server as their "outgoing SMTP mail server". Despite this. localhost). The /etc/mail/access File You can make sure that only trusted PCs on your network have the ability to relay mail via your mail server by using the /etc/mail/access file. Configuring the /etc/mail/access file will not stop SPAM coming to you. we allow relaying for only the server itself (127.0.168. REJECT. The second lists the type of action to be taken when mail from these sources / destinations is received. only SPAM flowing through you. There is no third column to state whether the IP address or domain is the source or destination of the mail.1 192.db. my experience has been that control on a per email address basis is much more intuitive via the /etc/mail/virtusertable file.1.16 192. Here are the commands to do that: [root@bigboy tmp]# cd /etc/mail [root@bigboy mail]# make Remember that the relay security features of this file may not work if you don't have a correctly configured /etc/hosts file.1.2. Sendmail has to be restarted after editing this file for the changes to take effect.1.localdomain localhost 127.168.com if its IP address can be found in a DNS reverse zone file: localhost.168.com RELAY RELAY RELAY RELAY RELAY RELAY RELAY You'll then have to convert this text file into a Sendmail readable database file named /etc/mail/access. .17 192. you may find your server being used to relay mail for SPAM email sites. such as restricting relaying by IP address or network range and is more commonly used.1. Sendmail will REJECT all other attempted relayed mail that doesn't match any of the entries in the /etc/mail/access file.X network.168. The /etc/mail/access file has two columns. Sendmail assumes it could be either and tries to match both.0. then relay access is fully determined by the /etc/mail/access file. That is to say.X network and everyone passing email through the mail server from servers belonging to my-site.2 my-site. The first lists IP addresses and domains from which the mail is coming or going.

it needs a way of determining whether it is responsible for the mail it receives. This file has a list of hostnames and domains for which sendmail will accept responsibility. . For example. It could be viewed as a mailing list file.com.com my-other-site. Primary Mail Exchanger for my-other-site.com. o o The first lists the destination to which the original sender intended to send the mail. The true destination in the eyes of the mail server could be a local Linux user.com" DNS zonefile point to my-site. It uses the /etc/mail/local-host-names file to do this.230 www.com then the file would look like this: my-site. it assumes the recipient is a local user.com The /etc/mail/local-host-names File When sendmail receives mail. The /etc/aliases file This file has two columns too.linuxhomenetworking.com Which User Should Really Receive The Mail? Sendmail uses two different methods to determine who the ultimate mail recipient will be. MX 10 mail.com In this case. The first column has the mailing list name (sometimes called a virtual mailbox) and the second column has the members of the mailing list separated by commas.com. The second column lists the single true destination. if this mail server was to accept mail for the domains my-site. .com and my-other-site. o o o If the mailing list member doesn't have an "@" in the name. then sendmail assumes the recipient is on the local box.com and the host server. It will then search the first column of the aliases file to see if the recipient isn't on yet another mailing list. remember to modify the MX record of the "my-other-site. If it doesn't find a duplicate.my-site." is important): my-other-site.my-site. a mailing list entry in the /etc/aliases file or the email address of someone on some other mail server to which the mail should be automatically forwarded. It checks these methods in this order: The /etc/mail/virtusertable file This file has two columns. Here is an example (Remember each ".

com goes to local user (or mailing list) "paul" all other users at my-site. you may want to delete the comment and change user "marc" to another user.com will go to local user (or mailing list) "webmasters". It contains a list of virtual mail boxes (or mailing lists) in the first column..db. mail sent to: o o o o webmaster@my-other-site.com will go to local user "marc". "paul" and "finance" at my-site..com. The first column lists the target email address and the second column lists the local user’s mail box or remote email address to which the email should be forwarded. all other mail to my-other-site. you can see that mail sent to users "bin". # Basic system aliases -. "apache". Here are the commands to do that: [root@bigboy tmp]# cd /etc/mail [root@bigboy mail]# make The /etc/aliases File This file is really a list of email aliases for local users.com webmasters marc sales@my-other-site.com paul paul error:nouser User unknown After editing this file you'll have to convert it into a sendmail readable database file named /etc/mail/virtusertable. then it goes through the process all over again to determine each individual in the mailing list and when it is all finished.com. The /etc/mail/virtusertable file This file contains a set of simple instructions on what to do with received mail. In the example below. "daemon".com @my-other-site. In this case "root" is actually an alias for a mailing list consisting of user "marc" and webmaster@my-site. . In the example below. etc by system processes will all be sent to user (or mailing list) "root". Note: The default /etc/aliases file installed with RedHat has the last line of this sample commented out with a "#". "lp".these MUST be present. and members of the mailing lists in the second column.Chapter 21: Configuring Linux Mail 231 o If the recipient is a mailing list.com will go to the sales department at my-othersite.com paul@my-site. "shutdown". "sales" at my-site.com finance@my-site. mailer-daemon: postmaster postmaster: root # General redirections for pseudo accounts.com sales@my-site. they will all get a copy of the email message. "named".com receive a "bounce back" message stating "User unknown" webmaster@my-other-site.com @my-site.

After editing this file you'll have to convert it into a sendmail readable database file named /etc/aliases.com. mail sent to "root" actually goes to user account "marc" and webmaster@my-site. then consider using a mailing list manager like majordomo. "paul" and "mary". Here is the command to do that: [root@bigboy tmp]# newaliases Simple Mailing Lists Using Aliases In the simple mailing list example above. Another is that all subscriptions and unsubscriptions have to be done manually by the mailing list administrator.mary Mail sent to "family@my-site. Despite this. Mail to "directors@my-site. user “root” is only needed update the aliases file.linuxhomenetworking. # Directors of my SOHO company directors: peter.232 www.com Notice that there are no spaces between the mailing list entries for “root”.sister Mail sent to admin-list gets sent to all the users listed in the file /usr/home/admin/admin-list.com" goes to users "grandma".webmaster@my-site. . "brother" and "sister" # My family family: grandma. The advantage of using mailing list files is that the admin-list file can be a file that trusted users can edit.brother.com" goes to users "peter". One is that bounce messages from failed attempts to broadcast goes to all users. This is important as you will get errors if you add spaces.com bin: daemon: lp: shutdown: mail: apache: named: system: manager: abuse: root root root root root root root root root root # trap decode to catch security attacks decode: root # Person who should get root's mail root: marc.paul. Here are a few more list examples for your /etc/aliases file. If either of these are a problem for you. there are some problems with mail reflectors.db.

mc configuration file and adding some masquerading commands and directives. This explained later in this chapter in the POP Mail section.com and not user@bigboy.com. if not. In other words you may want your mail server to handle all email by assigning a consistent return address to all outgoing mail. you'll have to convert it into a sendmail readable database file named /etc/aliases. If you then use a mail client like Outlook Express with a SPAM mail filtering rule to reject mail with no to: in the header. it will have no "to:" in the email header. Configuring masquerading In the DNS configuration. it will appear to come from mail.mc that all outgoing mail originating on bigboy should appear to be coming from my-site.db. Here is an example: # Person who should get root's mail root: webmaster@my-site.my-site. These are explained below: . based on our settings in the /etc/hosts file.com then you have two choices: o o Configure your email client. You now have to tell bigboy in the sendmail configuration file sendmail.Chapter 21: Configuring Linux Mail 233 # My mailing list file admin-list: ":include:/home/mailings/admin-list" After editing this file. Here is the command to do that: [root@bigboy tmp]# newaliases An Important Note About The /etc/aliases File By default your system uses sendmail to mail system messages to local user "root". we made bigboy the mailserver for the domain my-site. to set your email address to user@mysite. This isn't terrible. such as Outlook Express.com. This can be solved by editing your sendmail. this will force sendmail to insert the correct fields in the header. but you may not want your website site to be remembered with the word "mail" in front of it. When sendmail sends email to a local user. To get around this.com Sendmail Masquerading Explained If you want your mail to appear to come from user@mysite. no matter which server originated the email.com. you may find yourself dumping legitimate mail. Set up masquerading to modify the domain name of all traffic originating from and passing trough your mail server.mysite.com. try making root have an alias for a user with a fully qualified domain name.

com FEATURE(always_add_domain)dnl FEATURE(`masquerade_entire_domain')dnl FEATURE(`masquerade_envelope')dnl FEATURE(`allmasquerade')dnl MASQUERADE_AS(`my-site. Feature "allmasquerade" will make sendmail rewrite both recipient addresses and sender addresses relative to the local machine. The email header is what email clients.linuxhomenetworking.com domain appear to come from the MASQUERADE_AS domain of my-site. say the "to:" and "from:" should be.mysite.234 www. user "root" will not be masqueraded. It is easy to fake the header.com. Other Masquerading Notes By default. In other words. even if the mail is sent from a user on the mail server to another user on the same mail server. I have noticed that "sendmail -v username" ignores masquerading altogether.com)dnl • • The MASQUERADE_AS directive will make all mail originating on bigboy appear to come from a server within the domain my-site. only when you are sure you have the authority to do this. Feature "always_add_domain" will always masquerade email addresses.com. such as Outlook Express. it is detrimental to email delivery to fake the envelope. the other recipient will see a cc: to an address he knows instead of one on localhost. The "to:" and "from:" in the header is what is used when you use Outlook Express to do a "reply" or "reply all".com as my-site. Feature "masquerade_envelope" will rewrite the email envelope just as "MASQUERADE_AS" rewrote the header.com. as Spammers often do.')dnl MASQUERADE_AS(my-site.com.com and my-othersite. This is achieved with the: . • • • • Testing Masquerading The best way of testing masquerading from the Linux command line is to use the "mail -v username" command. You should also tail the /var/log/maillog file to verify that the masquerading is operating correctly and check the envelope and header of test email received by test email accounts. Use this with caution.com would be masqueraded too. The email envelope contains the "to:" and "from:" used by mailservers for protocol negotiation. Feature "masquerade_entire_domain" makes sendmail masquerade servers named *my-site.com would be masqueraded.localdomain.')dnl MASQUERADE_DOMAIN(`my-site.com. then only servers named mysite.com by rewriting the email header. and *my-other-site. The MASQUERADE_DOMAIN directive will make mail relayed via bigboy from all machines in the my-other-site. If you cc: yourself on an outgoing mail. It is the envelope's "from:" which is used when email rejection messages are sent between mail servers. mail from sales. If this wasn't selected.

Chapter 21: Configuring Linux Mail 235 EXPOSED_USER(`root')dnl command in /etc/mail/sendmail. It will then deny everything else.reject that specifies those that you should reject.mc. PERL doesn’t come with modules that are able to check email headers and envelopes so you will have to download them from CPAN (www. then you have a few more steps.forward” file and place an entry in /etc/smrsh Mail-filter will first reject all email based on the “reject” file and will then accept all mail found in the “accept” file. Place an executable version of the script in your home directory and modify the script’s $FILEPATH variable point to your home directory Update the two configuration files: mail-filter. . By default. Sendmail then looks for the filename in the directory /etc/smrsh and executes it. If you want to retrieve this mail from your Linux box's user account.org).forward” file in your home directory for the name of this script. Configuring Your POP Mail Server Sendmail will just handle mail sent to your "my-site. You can comment this out if you like with a "dnl" at the beginning of the line and recompiling / restarting sendmail A Simple PERL Script To Help Stop SPAM It is possible to limit the amount of unsolicited commercial email (UCE or SPAM) SPAM you receive by writing a small script to intercept your mail before it is written to your mailbox. using a mail client such as Microsoft Outlook or Outlook Express. mail-filter. which specifies the subjects and email addresses to accept.pl that effectively filters out SPAM email for my home system.accept. o Update your “. You'll also have to make your Linux box a POP mail server.cpan.com" domain. This is fairly simple to do as sendmail always checks the “. I have included a simple script with instructions on how to install the PERL modules in the Appendix. There are a few steps required to make the script work: o o o Install PERL and the PERL modules listed above. Each user on your Linux box will get mail sent to their account's mail folder. The most important modules are: o o o o MailTools IO-Stringy MIME-tools Mail-Audit I have written a script called mail-filter.

rpm o POP mail is started by xinetd.d like this: [root@bigboy tmp]# /etc/init.d/ipop3 file.linuxhomenetworking.i386.d]# vi ipop3 # default: off # description: The POP3 service allows remote users # to access their mail \ # using an POP3 client such as Netscape Communicator. Downloading and installing RPMs isn’t hard. mutt. o The IMAP/POP mail suite comes standard with the RedHat installation CDs. the chapter on RPMs covers how to do this in detail. If you need a refresher. The disable feature must be set to "no" to accept connections. [root@bigboy tmp]# chkconfig --level 35 xinetd on o To start/stop/restart POP mail after booting you can use the xinetd init script located in the directory /etc/init. [root@bigboy tmp]# cd /etc/xinetd. Follow the steps below and set the "disable" parameter to "no".236 www. so you’ll have to edit this file to start the program. Therefore to get POP mail configured to start at boot you have to use the chkconfig command to make sure xinetd starts up on booting.d/xinetd stop [root@bigboy tmp]# /etc/init.d/xinetd start [root@bigboy tmp]# /etc/init. Make sure the contents look like this. You can install the RPM with this command: [root@bigboy tmp]# rpm -Uvh imap-2001a-15.com Installing Your POP Mail Server Most RedHat Linux software products are available in the RPM format.d/xinetd restart Remember to restart the POP mail process every time you make a change to the configuration files for the changes to take effect on the running process Configuring Your POP Mail Server The starting and stopping of POP Mail is controlled by xinetd via the /etc/xinetd. \ # or fetchmail. POP Mail is deactivated by default. service pop3 { socket_type = stream wait = no user = root server = /usr/sbin/ipop3d log_on_success += HOST DURATION log_on_failure += HOST disable = no } .d [root@bigboy xinetd.

SMTP Set your SMTP mail server to be the IP address / domain name of your Linux mail server. o . you’ll have to edit the /etc/xinetd.com. If you have a user overlap.com and john2@my-other-site. John Smith (john@my-site. Here’s how: POP Mail Set your POP mail server to be the IP address of your Linux mail server. How to handle overlapping email addresses.com pointing to account "john2".d/ipop3 file.com) and John Brown (john@my-other-site. both users will get sent to the Linux user account "john". by default. The POP configuration in Outlook Express for each user should POP using "john1" and "john2" respectively. For example: john1@my-site.d directory. Naturally. You can now configure your email client such as Outlook Express to use your use your new POP / SMTP Mail Server quite easily.com).com pointing to account "john1" and john@my-other-site. Have a virtusertable entries for john@mysite. Create the user accounts "john1" and "john2".Chapter 21: Configuring Linux Mail 237 You will then have to restart xinetd for these changes to take effect using the startup script in the /etc/init. If the users insist on overlapping names then you may need to modify your virtusertable file. You have two choices: o Make the user part of the email address is different. eg. set “disable” to “yes” and restart xinetd. Create Linux accounts "john1" and "john2". How To Configure Your Windows Mail Programs All your POP email accounts are really only regular Linux user accounts in which Sendmail has deposited mail. Use your Linux user username and password when prompted. to disable POP Mail once again.

com .linuxhomenetworking.238 www.

www. Downloading and installing RPMs isn’t hard.conf File Upgrading Your DHCP Server How to get DHCP started Modify Your Routes for DHCP on Linux Server Configuring Linux clients to use DHCP Error Found When Upgrading From Redhat 7. You can choose to disable the DHCP server feature on your home router and set up a Linux box as the DHCP server. If you need a refresher. N Download and Install The DHCP Package Most RedHat Linux software products are available in the RPM format. the RPM chapter covers how to do this in detail. If you install a home cable/DSL router between your modem and home network your PC will most likely get its IP address at boot time from the home router instead. This chapter only covers the configuration of a DHCP server that provides IP addresses.com =========================================== ormally if you have a cable modem or DSL you get your home PC's IP address dynamically assigned from your service provider.239 Chapter 22 Configuring The DHCP Server =========================================== In This Chapter Chapter 22 Configuring The DHCP Server Download and Install The DHCP Package The /etc/dhcp. .3 To 8. The configuration of a Linux DHCP client that gets its IP address from a DHCP server is covered in the Linux Networking Topics chapter.0 © Peter Harrison.linuxhomenetworking.

1.220.sample Here is a quick explanation of the dhcp. .0+ subnet 192.i386.1.168.i386.conf file: Most importantly.168.168.240 www. It uses the commands here to configure your network.1.conf in the following directory which you can always use as a guide.com • For example.rpm The /etc/dhcp.255. # Set the default gateway to be used by # the PC clients option routers 192.conf.linuxhomenetworking.rpm • Install the package using the following command: [root@bigboy tmp]# rpm -Uvh dhcp-3. max-lease-time 86400.conf.0 RPM as of this writing was: dhcp-3.0 netmask 255. Normally you can find a sample copy of dhcpd. the RedHat 8.255. ddns-update-style interim # Redhat Version 8. # Set the amount of time in seconds that # a client may keep the IP address default-lease-time 86400.1.201 192.conf File When DHCP starts it reads the file /etc/dhcp.1. /usr/share/doc/dhcp-<version-number>/dhcpd.168. there must be a "subnet" section for each interface on your Linux box.0pl1-9.0pl1-9.0 { # The range of IP addresses the server # will issue to DHCP enabled PC clients # booting up on the network range 192. # Don't forward DHCP requests from this # NIC interface to any other NIC # interfaces option ip-forwarding off.

} # # List an unused interface here # subnet 192. fixed-address 192.168.100. in Redhat Version 8. These include telling the DHCP clients where to go for services such as finger and IRC.255.1. # Set the NTP server to be used by the # DHCP clients option nntp-server 192.Chapter 22: Configuring The DHCP Server 241 # Set the broadcast address and subnet mask # to be used by the DHCP clients option broadcast-address 192. # Set the DNS server to be used by the # DHCP clients option domain-name-servers 192. # you need to include the following option in the dhcpd.0.0 netmask 255.0b2pl11) you will need to add the line at the very top of the config file or else you will get errors:: ddns-update-style interim . The command to do this follows: [root@bigboy tmp]# man dhcp-options Upgrading Your DHCP Server Always refer to this sample file after doing an upgrade as new required commands may have been added.255.100.168.1. Check the dhcp-options man page after you do your install.222.100.2.1.168. } There many more options statements you can use to configure DHCP. option subnet-mask 255.1.1.168.255.255.conf file: option netbios-name-servers 192.168.255.168.0 { } # You can also assign specific IP addresses based on the clients' # ethernet MAC address as follows (Host's name is "smallfry": host smallfry { hardware ethernet 08:00:2b:4c:59:23. # If you specify a WINS server for your Windows clients. For example.0 (dhcpd version 3.

Note: More information on adding Linux routes and routing may be found in the Linux Networking chapter.255. You will have to add a route for this address on your Linux DHCP server so that it knows the interface on which to send the reply.255. Modify Your Routes for DHCP on Linux Server When a DHCP configured PC boots. it will request its IP address from the DHCP server.255.255. . we’re assuming that DHCP requests will be coming in on interface eth0).255. [root@bigboy tmp]# touch /var/lib/dhcp/dhcpd.leases" to create the file if it does not exist.255 from the command line. always remember to set your PC to get its IP address via DHCP.242 www. (In both examples below.com How to get DHCP started • Before you start the DHCP server for the first time. You also can test whether the DHCP process is running with the following command.leases file. it will fail unless there is an existing dhcpd.d/dhcpd stop [root@bigboy tmp]# /etc/init.leases • Use the chkconfig command to get DHCP configured to start at boot: [root@bigboy tmp]# chkconfig --level 35 dhcpd on • Use the /etc/init.linuxhomenetworking.d/dhcpd restart • Remember to restart the DHCP process every time you make a change to the conf file for the changes to take effect on the running process. Use the command "touch /var/lib/dhcp/dhcpd. you should get a response of plain old process ID numbers: [root@bigboy tmp]# pgrep dhcpd • Finally. It does this by sending a standardized DHCP broadcast request packet to the DHCP server with a source IP address of 255. Temporary solution o Add the route to 255.d/dhcpd script to start/stop/restart DHCP after booting [root@bigboy tmp]# /etc/init.d/dhcpd start [root@bigboy tmp]# /etc/init.

which is read on booting.255.3 To 8.255 o If this doesn't work properly try adding the following entry to your /etc/hosts file: 255.conf file: ddns-update-style interim Sample error: Starting dhcpd: Internet Software Consortium DHCP Server V3.isc.255 dhcp Then.255. All rights reserved.255. try: route add -host dhcp dev eth0 Permanent Solution o Edit /etc/sysconfig/static-routes. For info.255. try: eth0 host dhcp Configuring Linux clients to use DHCP Remember to have your Linux based clients configured to have DHCP obtained IP addresses Error Found When Upgrading From Redhat 7. and add the following line: eth0 host 255.255: Unknown host appears then try adding the following entry to your /etc/hosts file: 255.255.0pl1 Copyright 1995-2001 Internet Software Consortium. please visit http://www.255. .Chapter 22: Configuring The DHCP Server 243 [root@bigboy tmp]# route add -host 255.org/products/DHCP ** You must add a ddns-update-style statement to /etc/dhcpd.conf.255.255.255.255 dhcp Then.0 This dhcpd startup error is caused by not having the following line at the very top of your /etc/dhcpd.255 dev eth0 o If the message 255.255.

org.org and have not yet read the README. exiting. If you did get this software from ftp. please read the section on the README about submitting bug reports and requests for help. [FAILED] .isc. please get the latest from ftp.linuxhomenetworking.org mailing list.org and install that before requesting help. please read it before requesting help. add a line that says "ddns-update-style ad-hoc. ** If you did not get this software from ftp.244 www. If you intend to request help from the dhcp-server@isc.isc. Please do not under any circumstances send requests for help directly to the authors of this software .isc.please send them to the appropriate mailing list as described in the README file.conf manual page for more information." Please read the dhcpd.0b2pl11 and previous versions.com To get the same behaviour as in 3.

. A list of available servers may be found at: http://www.html What is NTP? Network Time Protocol (NTP) is a protocol used to help synchronize your system clock with an accurate time source. www.eecis.conf File How To Get NTP Started Determining If NTP Is Synchronized Properly Configuring Cisco Devices To Use An NTP Server Firewalls and NTP © Peter Harrison. It is good practice to have at least one server on your network be the local time server for all your other devices. There are a number of "Stratum 1" (NTP sites using an atomic clock for timing) and "Stratum 2" (NTP sites with slightly less accurate time sources) sites that allow the general public to synchronize with them.udel.com =========================================== You can keep accurate time under Linux by synchronizing your system clock with a Network Time Protocol (NTP) Server. this makes the correlation of system events on different systems much easier.linuxhomenetworking.245 Chapter 23 The NTP Server =========================================== In This Chapter Chapter 23 The NTP Server What is NTP? Download and Install The NTP Package The /etc/ntp.edu/~mills/ntp/servers.

1.linuxhomenetworking.255.0 notrust nomodify notrap . restrict otherntp.255.com There are a number of freely available NTP client programs for Windows.gov # A stratum 1 server at server.0 mask 255. Here is a sample of a home configuration using a pair of sample Internet based NTP servers: • First we specify the servers we’re interested in: server server otherntp.rpm The /etc/ntp.org restrict ntp.255.research.1-1.1-1. Download and Install The NTP Package Most RedHat Linux software products are available in the RPM format. You can use them to practice with your new NTP server.255 is really a subnet mask limiting access to the single IP address of the remote NTP servers.research.org # A stratum 2 server at research.255.i386.255.255.255 nomodify notrap noquery The mask statement 255. Downloading and installing RPMs isn’t hard.org ntp.168. In this example we’re not allowing them to modify or query our Linux NTP server.255.1.rpm • Install the package using the following command: [root@bigboy tmp]# rpm -Uvh ntp-4.246 www.server. If you need a refresher.gov • Then we restrict the type of access you allow these servers.conf File This is the main configuration file for Linux NTP in which you place the IP addresses of the stratum 1 and stratum 2 servers you want to use.255.1. the chapter on RPMs covers how to do this in detail. • The latest version of the RPM for RedHat 8.gov mask 255.server.i386. • Now list the NTP clients on our home network which should be querying our server for the time (notice that the noquery has been removed): restrict 192.255 nomodify notrap noquery mask 255.0 is: ntp-4.

you should get a response of plain old process ID numbers: [root@bigboy tmp]# pgrep ntpd . you need to make sure the default restrict statement is removed.10 offset 15.100.gov 24 Mar 18:16:36 ntpdate[10254]: step time server 200.266188 sec [root@bigboy tmp]# ntpdate otherntp.20.000267 sec How To Get NTP Started • To get NTP configured to start at boot: [root@bigboy tmp]# chkconfig --level 35 ntpd on • To start/stop/restart NTP after booting: [root@bigboy tmp]# /etc/init.research.d/ntpd stop [root@bigboy tmp]# /etc/init.100. comment it out like this: #restrict default ignore • Save the file • Do the following commands twice for each new server added to /etc/ntp. but most importantly.0.1 • Last.Chapter 23: The NTP Server 247 In this case the mask statement has been expanded to include all 255 possible IP addresses on our local network.d/ntpd restart Remember to restart the NTP process every time you make a change to the conf file for the changes to take effect on the running process • You can test whether the NTP process is running with the following command.d/ntpd start [root@bigboy tmp]# /etc/init.conf [root@bigboy tmp]# ntpdate otherntp.0. It will override all other restrict statements and you’ll find your NTP server will only be communicating properly with itself. • We also want to make sure that localhost (The universal IP address used to refer to a Linux server itself) has full access without any restricting keywords: restrict 127.20. If the line is there.10 offset -0.research.gov 24 Mar 18:16:43 ntpdate[10255]: adjust time server 200.

000 0.wis ben.wisc.linuxhomenetworking.000 0.424 -3. ciscorouter> enable password: ********* ciscorouter# config t ciscorouter(config)# ntp update-calendar ciscorouter(config)# ntp server 192.127 3.572 milo.979 0.cs. 2 u 972 1024 377 38. 1 u 426 1024 377 107.025 1.274 -5.201.0.000 0.0 16 u 64 0 0.00 • A telltale sign that you haven’t got proper synchronization is when all the remote servers have jitters of 4000 with delay and reach values of zero. ben.379 0.go 2 u 818 1024 125 41.1.net .000 4000.cs.GPS.392 -mailer1.206 19.589 28.100 .cc.com Determining If NTP Is Synchronized Properly • Use the following command to see the servers with which you are synchronized: [root@bigboy tmp]# ntpq -p Sample output: remote refid st t when poll reach delay offset jitter ============================================================================== -jj.1024 0 0.168.mcs.conf file not being commented out.00 snvl-smtp1.000 0.534 ntp1.248 www.0 16 u .047 -ntp0.wisc.cs.0.cs.0 16 u 64 0 0.strat 3 u 507 1024 377 115.168.000 4000.sigmaso 3 u 95 1024 377 31.168.strath harris.028 -dr-zaius. An explanation of the commands used follows.0. A firewall blocking access to your Stratum 1 and 2 NTP servers Configuring Cisco Devices To Use An NTP Server Cisco IOS Here are the commands you would use to make your router synchronize with NTP servers with IP addresses 192.000 4000.0 16 u 64 0 0.cs.008 ntp-cup.0.00 nist1.0.c 0.098 3.000 0.go ntp0. remote refid st t when poll reach delay offset jitter ============================================================================== LOCAL(0) LOCAL(0) 10 l 64 7 0.018 2.1.000 0.tr 0.trim 0.usno.333 +taylor.681 -18.anl.edu 2 u 454 1024 347 54.642 *clock.000 4000.1.umb.edu ntp1.navy.00 This could be caused by: o o The restrict default ignore statement in the /etc/ntp.0.264 1.edu gandalf.psc.993 -15.wisc.conectiv.100 and 192.0.mcs.via.0.edu 2 u 502 1024 357 55.cis.externa 0.anl.549 1.aol-ca.

1. but 123 also.201 ciscorouter(config)# exit ciscorouter# wr mem o o ntp server: Forms a server association with another system. the source port isn't a high port (ie. set ntp client enable: Activate the NTP client Firewalls and NTP NTP servers communicate with one another using UDP with a destination port of 123. An explanation of the commands used follows.168.168. Unlike most UDP protocols. . A sample Linux iptables firewall script snippet is in the Appendix.100 and 192. ciscoswitch> enable password: ********* ciscoswitch# set ntp client enable ciscoswitch# ntp server 192.100 ciscoswitch# exit o o o ntp server: Forms a server association with another system. You'll have to allow UDP traffic on source/destination port 123 between your server and the Stratum 1/2 server with which you are synchronizing. greater than 1023). CAT OS Here are the commands you would use to make your router synchronize with NTP servers with IP addresses 192.100 ciscoswitch# ntp server 192.168.1.168.201.Chapter 23: The NTP Server 249 ciscorouter(config)# ntp server 192.1.168.1.1. ntp update-calendar: Configures the system to update its hardware clock from the software clock at periodic intervals.

com .linuxhomenetworking.250 www.

specifically how to configure it. Network Address Translation (NAT) Network address translation is a method used to help conserve the limited number of IP addresses available for internet purposes. www.251 Chapter 24 Configuring Cisco PIX Firewalls =========================================== In This Chapter Chapter 24 Configuring Cisco PIX Firewalls Network Address Translation (NAT) Accessing the PIX command line Sample PIX Configuration: DSL .DHCP How To Get Static IPs For DSL Cheaply Sample PIX configuration: DSL . but first a very basic introduction on how to configure and use the PIX. there is a sample configuration in the appendix. The introduction to networking page explains the concept in more detail in addition to other fundamental topics. We will return to the NAT discussion.linuxhomenetworking. . later on this page.Static IPs © Peter Harrison.com =========================================== Sometimes you may have a Cisco PIX 501 firewall protecting your DSL based home network. This chapter covers how to configure it and in addition.

Escape character is '^]'.com o Once connected to the network you can access the PIX via telnet [root@bigboy tmp]# telnet pixfw Trying 192..0.168.1.252 www.1. pixfw> enable Password: ******** pixfw# o Use the "write terminal" command to see the current configuration.168. Here you list all the IP addresses of important devices that you may want to access with a corresponding nickname.168. or various programs # that require network functionality will fail. . User Access Verification Password: Type help or '?' for a list of available commands. If you are directly connected to the console.1 pixfw 192. Via Telnet o One easy way to get access to any device on your network is using the /etc/hosts file.1. o You'll be prompted for a password and will need another password to get into the privileged "enable" mode.localdomain localhost 192. you should get a similar prompt too. # wr term Building configuration.100 bigboy mail.. You will want to change your "password" and "enable password" right after completing your initial configuration. # 127..1.168.0.1 localhost.my-site.com Accessing the PIX command line Via The Console Port Your Cisco PIX will come with a console cable that will allow you to configure your PIX using terminal emulation software such as Hyperterm. Once you’ve set up all your PIX with an IP address you’ll be able to access it via Telnet.linuxhomenetworking.1: # Do not remove the following line..1. There is no password in a fresh out of the box PIX and simply hitting the "Enter" key will be enough. Here is a sample in which the PIX firewall "pixfw" has the IP address 192. Connected to pixfw.

in this case "ISP". (Remember to be in config mode) ip address outside pppoe setroute ... pixfw# conf t pixfw(config)# "Enter commands here" pixfw(config)# exit pixfw# o One of the first things you should do is change the default paswords for the PIX.2(2) nameif ethernet0 outside security0 nameif ethernet1 inside security100 enable password dsjf5sdfgsjrgjwk encrypted passwd sdffg8324dgrggjd encrypted hostname pixfw fixup protocol ftp 21 .. you can permanently save your changes by using the "write memory" command: pixfw# wr mem Building configuration. .DHCP Configuring PPPoE o DHCP and DSL require you to get a pppoe password and username from your ISP... by issuing the "configure terminal" command from enable mode prompt. o ALL PIX configuration commands need to be done in configuration mode. Most ISPs have a homepage where you can register to get the username and password. pixfw# conf t pixfw(config)# enable password "enable password here" pixfw(config)# passwd "console password here" pixfw(config)# exit pixfw# o When you've finished configuring. password. authentication type to a profile. Cryptochecksum: 3af43873 d35d6f06 51f8c999 180c2342 [OK] pixfw# Sample PIX Configuration: DSL . The configuration steps are relatively straight forward.Chapter 24 : Configuring Cisco PIX Firewalls 253 : Saved : PIX Version 6. You should substitute this username and password for "dsl-username" and "dsl-password" below. The VPDN group statements just assign a username. ask customer service for the URL..

Due to competition they'll even throw in a DSL modem and even a router for free.0.168.255.253.254 www.outside) tcp interface www 192. you may be able to hit your website using PCs behind your firewall using the firewall's outside interface's IP address as the destination.0 0 0 Dynamic DNS Port Forwarding Entries Here we allow all incoming www traffic (on TCP port 80) destined for the firewall's interface to be forwarded to the web server at 192. Once configured. eg: http://firewall-outside-ip-address access-list inbound permit icmp any any access-list inbound permit tcp any any eq www access-group inbound in interface outside static (inside.158.253.1.0.0.1 You must be using PIX IOS version 6. If you really want static IP addresses and are willing to pay the higher monthly fee.255 How To Get Static IPs For DSL Cheaply Many ISP DSL providers offer cheap DHCP (dynamic IP) service. This service frequently isn't available for users with static IPs which the ISPs frequently feel are businesses. NAT Configuration Here we allow any traffic coming in on the inside (private/protected) interface to be NAT-ted to the IP address of the outside (Public/unprotected) interface of the firewall.255.100 www netmask 255.255.12 then the traffic passing through the firewall. from your protected PCs. you will have to set the default gateway on all your servers to be 192. global (outside) 1 interface nat (inside) 1 0.DHCP has assigned an address of 97.1. the IP address of the PIX is 192.12. and it becomes bundled in free.255.linuxhomenetworking. .158.0 0.0 vpdn group ISP request dialout pppoe vpdn group ISP localname dsl-username vpdn group ISP ppp authentication pap vpdn username dsl-username password dsl-password In this example.1 255.com ip address inside 192.168.168.1. As the PIX will be acting as your default gateway to the internet. then you can reduce your installation costs by: • Ordering DHCP DSL first with the free modem and/or router • Upgrade to static IPs a week later.1. will appear to be coming from address 97.1.2 or greater for this to work. They probably won't ask about the modem and/or router.168.168.0. If DSL .100 on port 80 (www).1.

255.158.0.0 to 192.253.158.255 to be NAT-ted to the IP address of the outside (Public/unprotected) interface of the firewall which is 97.30 If you are converting from dynamic to static IP addresses.255.1 255.25 : global (outside) 1 interface nat (inside) 1 192.0 97.253.158.1.26 eq 53 access-group inbound in interface outside static (inside.0 0 0 Incoming Connections NAT Configuration Here we allow the firewall to handle traffic to a second IP address. you do not need the vpdn PIX command statements for static IPs ip address outside 97. the IP address of the PIX is 192.100.30 In this example.26 eq www access-list inbound permit tcp any host 97.158. we then allow all incoming traffic to be forwarded to the protected web server which has an IP address of 192.255.1. Only www and DNS (Port 53) traffic is allowed to access it via an access control list applied to the outside interface.1.0.255. the default gateway is 97.253.255.0 255.253.25.255.1. you will have to set the default gateway on all your servers to be 192.158.253.255 0 0 . As the PIX will be acting as your default gateway to the internet.1.25 255.248 ip address inside 192.158.0 route outside 0.168.253.255.158.158.253.168.158. namely 97.0 0.24 with a mask of 255.158.26.248 (/29). you won't be able to hit your website from PCs behind your firewall using the public IP address assigned to your web server as the destination.168.255.26 192.255.168.Static IPs PPOE authentication is only required for DSL DHCP.100 netmask 255.168.Chapter 24 : Configuring Cisco PIX Firewalls 255 Sample PIX configuration: DSL . In this example internet subnet that has been assigned is 97.0. You'll have to ask a friend t check it out. Once you go for static IPs.1.253.158.255.0.253.1.1 Outgoing Connections NAT Configuration Here we allow connections originating coming from servers connected to the inside (private/protected) interface with an IP address in the range 192.253.168. Once configured.outside) 97. the vpdn statements won’t be required.168. The IP address selected for the PIX is 97.253.1. access-list inbound permit tcp any host 97.26 eq 53 access-list inbound permit udp any host 97.168.1.

256 www.linuxhomenetworking. 21 25 110 443 .com Here are some additional TCP ports you may be interested in: Protocol FTP SMTP Mail POP3 Mail HTTPS / SSL Port 20.

linuxhomenetworking. The examples in this chapter also show how to configure NAT so you can also have a home / SOHO based website. This page should be suitable for the following Cisco routers: With Built In DSL Modems • 800 series • 1700 / 2600 / 3600 series with the ADSL WIC installed With External DSL Modems • 1700 / 2600 / 3600 series .com =========================================== This is a simple guide on how to set up your Cisco DSL router for DHCP using PPPoE.257 Chapter 25 Configuring Cisco DSL Routers =========================================== In This Chapter Chapter 25 Configuring Cisco DSL Routers An Introduction to Network Address Translation (NAT) Introduction to accessing the router command line Sample Configurations Other NAT Topics © Peter Harrison. www.

0.0. ciscorouter> enable Password: ******** . If you are directly connected to the console.com o Once connected to the network you can access the router via telnet [root@bigboy tmp]# telnet ciscorouter Trying 192.168.com An Introduction to Network Address Translation (NAT) Network address translation is a method used to help conserve the limited number of IP addresses available for internet purposes. We will return to the NAT discussion.1 ciscorouter 192.100 bigboy mail.localdomain localhost 192.168. User Access Verification Password: Type help or '?' for a list of available commands.1 localhost..linuxhomenetworking.168.258 www. There is no password in a fresh out of the box Cisco router and simply hitting the "Enter" key will be enough. or various programs # that require network functionality will fail. Escape character is '^]'.1. Introduction to accessing the router command line Via The Console Port Your Cisco router will come with a console cable that will allow you to configure your PIX using terminal emulation software such as Hyperterm..1.1. you should get a similar prompt too. # 127. Connected to ciscorouter. Here is a sample in which the router "ciscorouter" has the IP address 192. Once you’ve set up all your router with an IP address you’ll be able to access it via Telnet.1. o You'll be prompted for a password and will need another password to get into the privileged "enable" mode. but first a very basic introduction on how to configure and use Cisco DSL routers.168. Here you list all the IP addresses of important devices that you may want to access with a corresponding nickname.1: # Do not remove the following line. specifically how to configure it.1. later in this chapter. Via Telnet o One easy way to get access to any device on your network is using the /etc/hosts file.my-site. The introduction to networking page explains the concept in more detail in addition to other fundamental topics.

you can permanently save your changes by using the "write memory" command: ciscorouter# wr mem Building configuration. by issuing the "configure terminal" command from enable mode prompt. You will want to change your "password" and "enable password" right after completing your initial configuration.Chapter 25: Configuring Cisco DSL Routers 259 ciscorouter# o Use the "show running" command to see the current configuration.. ciscorouter# show run Building configuration.1 no service pad service timestamps debug uptime service timestamps log datetime localtime service password-encryption ! hostname ciscorouter ! no logging console no logging monitor logging trap debugging . o ALL router configuration commands need to be done in configuration mode.... Cryptochecksum: 3af43873 d35d6f06 51f8c999 180c2342 [OK] ciscorouter# . ciscorouter# conf t ciscorouter(config)# "Enter commands here" ciscorouter(config)# exit ciscorouter# o One of the first things you should do is change the default paswords for the router. .... ! version 12... ciscorouter# conf t ciscorouter(config)# enable secret ciscorouter(config)# line con 0 ciscorouter(config-line)# password ciscorouter(config-line)# line vty ciscorouter(config-line)# password ciscorouter(config-line)# ^z ciscorouter# o "enable password here" "console password here" 0 4 "telnet password here" When you've finished configuring. ..

If this is so. ask customer service for the URL. Most ISPs have a homepage where you can register to get the username and password.Configure the DSL interface !--.168.value not necesarily "1/1" ! interface ATM0 o o o .linuxhomenetworking.com Sample Configurations DSL Router With Built-In Modem .1 255.0 ip nat inside !--.Configure the router's PPPoE client so that it !--.1) uses NAT !--. Cisco IOS doesn’t support DHCP DSL and NAT.The "ip nat" statement tells your router that !--.1.can setup a session with the ISP ! vpdn-group pppoe request-dialin protocol pppoe !--.DHCP o DHCP and DSL requires you to get a pppoe password and username from your ISP.255. Some of the commands listed are part of Cisco's default settings. You should substitute this username and password for PPP "username" and "password" listed below.Your ISP may provide you with a different pvc !--.2) is the inside "private" interface ! interface FastEthernet0 ip address 192.IP address !--. Remember to be in "config" mode to enter these commands and remember to do a "write memory" at the end to permanently save the configuration Cisco DSL Router With Built-in Modem Configuration (DHCP) ! vpdn enable no vpdn logging !--.255. then putting an Internet accessible web server on your home network would be impossible using the routers mentioned above in this configuration. Here is a sample configuration for a Cisco home router.Configure the home / SOHO network interface's !--.260 www.this interface: !--. Do the "show run" command before starting to configure your router to see what commands you'll really need.

1) uses NAT !--.168.The "ip nat" statement tells your router that !--. This example uses the "CHAP" method.Chapter 25: Configuring Cisco DSL Routers 261 no ip address no atm ilmi-keepalive bundle-enable dsl operating-mode auto hold-queue 224 in ! interface ATM0."dialer" interface !--.this interface: !--.2) is the outside "public" interface ! interface Dialer1 ip address negotiated ip mtu 1492 ip nat outside encapsulation ppp dialer pool 1 !--!--!--!--!--! ppp ppp ppp ! Here are the commands to configure authentication with with your ISP. 2) And whose IP address is in the 192. Commands for using the "PAP" method are included at the end of this box authentication chap callin chap hostname <username> chap password <password> !--!--!--!--!--- Tells the router to NAT all traffic that passes through it: 1) From the inside to the outside.the PPPoE header overhead.Cisco prefers to run the PPPoE client on a virtual !--.0 network as given in access list 1 .size has been reduced from 1500 to accommodate !--.This is tied to the real ATM DSL interface with the !--"dialer pool" command.1. ! !--. The default ethernet MTU !--.1 point-to-point pvc 1/1 pppoe-client dial-pool-number 1 !--.

Remember to be in "config" mode to enter these commands and remember to do a "write memory" at the end to permanently save the configuration Cisco DSL Router With Built-in Modem Configuration (Static IP) Current Configuration: ! version 12. Do the "show run" command before starting to configure your router to see what commands you'll really need. type of authentication then you'll have to replace the lines: ppp authentication chap callin ppp chap hostname <username> ppp chap password <password> with only these two: ppp authentication pap callin ppp pap sent-username <username> password <password> o DSL Router With Built-In Modem .0.0. Some of the commands listed are part of Cisco's default settings.0.linuxhomenetworking.com !--.0 0.Static IP o Here is a sample configuration for a Cisco home router with a built-in modem. This example also shows how to use NAT so you can have a web server / mail server / FTP server etc.0.0.255 If your ISP tells you that you need to do the PAP.0 dialer1 no ip http server ! access-list 1 permit 192. in your home network.262 www. and not the CHAP.168.3) Giving it an outside "public" address that is the !--same as interface Dialer1 gets from the PPPoE !--connection ! ip nat inside source list 1 interface Dialer1 overload ip classless ip route 0.1 0.0.1 service timestamps debug uptime service timestamps log uptime ! hostname ciscorouter ! ip subnet-zero no ip domain-lookup ! bridge irb o o .

255.This is tied to the real ATM DSL interface with the !--.This statement performs the static address !--.168.253.1) From the inside to the outside.same as interface BVI1 ! ip nat inside source list 1 interface BVI1 overload !--.translation for the Web server.(The BVI number always matches the bridge-group number) !--."BVI" interface !--.through it: !--. With this statement.Cisco prefers to run the PPPoE client on a virtual !--.The "ip nat" statement tells your router that this !--.168.253.interface: !--.25 255.1 255.255.The "ip nat" statement tells your router that !--.26 port 80 (www) will be .2) is the inside "private" interface ! interface Ethernet0 ip address 192.255.2) And whose IP address is in the 192."bridge-group" command above.255. !--.this interface: !--.0 ip nat inside ! interface ATM0 no ip address no atm ilmi-keepalive pvc 0/35 encapsulation aal5snap ! bundle-enable dsl operating-mode auto bridge-group 1 ! !--.2) is the outside "public" interface ! interface BVI1 ip address 97.3) Must get an outside "public" address that is the !--.158.Chapter 25: Configuring Cisco DSL Routers 263 !--.0 network !--as given in access list 1 !--. !--.1) uses NAT !--.Configure the home / SOHO network interface's IP address !--. !--.1.Tells the router to NAT all traffic that passes !--.248 ip nat outside !--.users trying to reach 97.158.1.1) uses NAT !--.

0 97.100 port 80 !--. !--! ip nat inside source static tcp 192.168.30 ! access-list 1 permit 192.1.168.100 80 97.com !--. This example also shows how to use NAT so you can have a web server / mail server / FTP server etc.264 www.0 0.(www). in your home network.0.168.Set your default gateway as provided by your ISP ! ip classless ip route 0.linuxhomenetworking.0.158.253.0.0. which in this case is the Web server.automatically redirected to 192.0.1.255 bridge 1 protocol ieee bridge 1 route ip ! end DSL Router With External Modem .0.158.1 service timestamps debug uptime service timestamps log uptime ! hostname ciscorouter ! ip subnet-zero no ip domain-lookup ! !--!--!--!--Configure the home / SOHO network interface's IP address The "ip nat" statement tells your router that this interface: 1) uses NAT o o .Static IP o Here is a sample configuration for a Cisco home router with an external modem. Remember to be in "config" mode to enter these commands and remember to do a "write memory" at the end to permanently save the configuration Cisco Router Connected to DSL via External Modem Configuration (Static IP) Current Configuration: ! version 12.1. Some of the commands listed are part of Cisco's default settings.253.26 80 extendable !--. Do the "show run" command before starting to configure your router to see what commands you'll really need.0 0.

168.1.1.0.248 ip nat outside !--.2) And whose IP address is in the 192.26 80 extendable !--.253.for the Web server.253.With this statement.Chapter 25: Configuring Cisco DSL Routers 265 !--.port 80 (www) will be automatically redirected to !--.1.1.255.30 ! access-list 1 permit 192.253.This statement performs the static address translation !--.0 0.255.158. !--! ip nat inside source static tcp 192.0. users trying to reach 97.253.100 port 80 (www).3) Must get an outside "public" address that is the !--same as interface ethernet1 ! ip nat inside source list 1 interface ethernet1 overload !--.168.158.100 80 97.0.168.255.is the Web server.255 ! end . !--.168.1 255.0 97.through it: !--.0.Tells the router to NAT all traffic that passes !--.Set your default gateway as provided by your ISP ! ip classless ip route 0.255.0 0.192. !--.158.1) From the inside to the outside.26 !--.1.158.0 network !--as given in access list 1 !--. which in this case !--.168.0.2) is the inside "private" interface ! interface Ethernet0 ip address 192.0.25 255.0 ip nat inside ! interface Ethernet1 ip address 97.

1.168.168. regardless of port.253.100 53 97. then you can use the command: ip nat inside source static 192.100 97.com Other NAT Topics Commonly Used TCP And UDP Ports Here are some additional TCP ports you may be interested in for NAT "ip nat inside source static" statements: Protocol FTP SMTP Mail POP3 Mail HTTPS / SSL DNS Port 20.26.100 25 97.1.26 25 extendable o DNS requires a UDP type NAT statement such as: ip nat inside source static udp 192.1.158. to be NAT-ted to 192.25 How To Verify That NAT Is Working Correctly You can use the show ip nat translation command to determine whether NAT is actually occurring as expected: .158.158.253. the command for SMTP mail would be: ip nat inside source static tcp 192.168.1.25 53 extendable o To have all traffic trying to reach 97. 21 25 110 443 53 Type TCP TCP TCP TCP UDP o So for example.253.linuxhomenetworking.158.168.266 www.100.253.

1.26: wanted 80 got 80 03:29:49: NAT: o: tcp (198. 80) [0] . The Outside local the actual IP address of the remote computer on its local network..253. in this case.253. .253.168.158.158.26. The Inside global address is the IP address of the server presented to the Internet after NAT.26 03:29:49: NAT: Allocated Port for 192.253. The Outside global the IP address of the remote computer as presented on the Internet.. NAT seems to be functioning properly for the web server 192.219.133.34. . The Inside local address is the actual IP address of the local server on your home network.1.6:5698 ciscorouter# Outside local --.158.100:80 tcp 97.217. ciscorouter> enable Password: ******** ciscorouter#term mon ciscorouter#debug ip nat detailed IP NAT detailed debugging is on ciscorouter# 03:29:49: NAT: creating portlist proto 6 globaladdr 97.158.158.168.1.26:80 192.Chapter 25: Configuring Cisco DSL Routers 267 ciscorouter> enable Password: ******** ciscorouter#show ip nat translation Pro Inside global Inside local global tcp 97. .100..100 on the home network How To Troubleshoot NAT To troubleshoot NAT after you have logged into the router via Telnet requires you to first activate logging to the telnet terminal with the terminal monitor command and then using the debug ip nat detailed command to visualize the translation process.1.34.26:80 192.6:5698 Outside Cisco uses the following terms for the various IP addresses you’ll find in any NAT translation process.158. o o o o As you can see. and more specifically that remote host 67.100 -> 97.158. 5698) -> (97.253.253..168.6 was communicating with the inside global address of 97.1.168.168.217.100:80 67..34..26.--67.217.26 to 192.253.1. The example below shows that translation occurs for port 80 traffic (HTTP / www) from address 97.

268 www.com .linuxhomenetworking.

VPN relationships are established between trusted sites on the Internet making the public network appear to be virtually the same as a private network to the VPN members. What follows is an introduction to VPN terminology Authentication The process of ensuring that the VPN data received is both unchanged and from the expected source.269 Appendix I Miscellaneous Topics =========================================== In This Chapter Appendix I Miscellaneous Topics VPN Terminologies Running Linux Without A Monitor Make Your Linux Box Emulate A VT100 Dumb Terminal Syslog Configuration and Cisco Devices Disk Partitioning Explained The OSI Networking Model TCP/IP Packet Format © Peter Harrison. www. .linuxhomenetworking. VPN Terminologies A Virtual Private Network (VPN) provides security for transmission of sensitive information over unprotected networks such as the Internet.com =========================================== We briefly discuss some miscellaneous topics in this chapter that are beyond the scope of this book with the intention that you will be stimulated to consider utilizing some of the technologies discussed to improve your website and / or your SOHO network.

and anti-replay services. It does this by adding its own security header to the original IP packet. AH and an ESP are often used in combination with each other. Provides authentication and anti-replay services. It does this by encrypting the data within the packet and then adding its own security header to the original IP packet. IPSec The name given to a number of data communications protocols designed to authenticate and encrypt VPN data to protect it from unauthorized viewing or modification as it is transmitted across a network. without encryption. (For more information on the IP protocol. Provides authentication. Transport mode VPNs The original source and destination address of the data being sent over the VPN is unchanged.com Encryption The process of encoding VPN data to protect it from unauthorized viewing except by the intended recipient who has the decoder key. please refer to the OSI model page) Transport mode AH packet format Inserted Original Original DATA IP Header AH Header TCP Header Transport mode AH / ESP packet format Inserted Inserted Original Original DATA IP Header AH Header ESP Header TCP Header . Authentication Header (AH) One of two IPSec security protocols.270 www. This is called Transport Adjacency.linuxhomenetworking. As ESP headers don't authenticate the outer IP header like AH headers. encryption. Here are some examples of what transport mode VPN IP packets will look like. Encapsulating Security Protocol (ESP) The other IPSec security protocol.

and establishes IPSec keys. Internet Key Exchange (IKE) IKE provides authentication of the IPSec peers. (For more information on the IP protocol. . Here are some examples of what tunnel mode VPN IP packets will look like. The original packet is frequently encrypted. Encryption methods IPSec usually uses one of two methods to encrypt data: o o The Data Encryption Standard (DES) using a 56-bit encryption key Triple DES using a 168-bit encryption key. negotiates IPSec security associations.Appendix I : Miscellaneous Topics 271 Tunnel mode VPNs The original source and destination address of the data being sent over the VPN is changed by encapsulating the original IP packet within another IP packet. please refer to the OSI model page) Tunnel mode AH packet format New Inserted Original Original DATA IP Header AH Header IP Header TCP Header Tunnel mode AH / ESP packet format New Inserted Inserted Original Original DATA IP Header AH Header ESP Header IP Header TCP Header Authentication methods IPSec data integrity is usually provided by one of two Hashed Message Authentication Code (HMAC) methods: o o Message Digest 5 (MD5) Secure Hash Algorithm (SHA-1). header and all in an effort to provide an additional layer of security by not revealing the true identities of the servers communicating with each other.

serial number. Each peer then uses the pre-installed CA certificate they have to authenticate with the CA and securely receive the other peer's certificate from the CA using public key cryptography. or a "in-house" private server that you establish within your organization. the VPN peers authenticate by sending each other the certificate issued to them by the CA. Shared keys The devices at each end of the VPN use a shared key or password. The disadvantage is that each pair of VPN connections need set of keys. or IP address.272 www. During the key exchange. company. A successful exchange requires the receiver to have a copy of the sender's public key and knowing with a high degree of certainty that it really does belong to the sender. Unlike the RSA method. Once the the certificates received from the CA and the other peer match.linuxhomenetworking. Each peer then extracts the public key from the certificate they receive from the CA and then uses it to decrypt the certificate they just received from the other peer. CA overview A digital certificate contains information that identifies a user or device. each VPN device must be pre-configured with the certificate generated for them by the CA. This allows you to create a signature when the message is encrypted with a sender's private key. department. As the message could be decrypted using the sender's public key means that the holder of the private key created the message. there is no CA to provide an impartial audit trail of VPN connection initiations. A CA can either be a trusted public third party. authentication is complete. such as a name.com IKE authentication methods There are two main methods of establishing a trusted relationship between two devices that want to create a VPN between themselves: Public key cryptography using RSA encryption RSA overview Each VPN device has its own public and private keys. and not to someone pretending to be the sender. such as VeriSign. making it difficult for large scale implementations. Anything encrypted with one of the keys can only be decrypted with the other. The receiver verifies the signature by decrypting the message with the sender's public key. Certificates are managed and issued by Certification authorities (CAs). The VPN devices will also be pre-configured with the CA's certificate. It will also contain a copy of the entity's public key. Prior to installing a certificate based VPN. . This is done using Certification Authorities. but encrypted using their private key.

Here are some authentication methods used in such . SAs are comprised of two factors: Transforms Describes how the data will be transformed by the VPN to provide the desired security. This must also be allowed to pass through unimpeded. Unusually. IKE is then used by the VPN peers to negotiate the security associations (SAs) to be used at each end point. (SAs are permanent for when manually established) Shared keys The actual keyword used by the encryption and authentication to protect the data.Appendix I : Miscellaneous Topics 273 IKE's role in creating Security Associations Once authentication is complete. you may have to open up these ports and protocols to the CA as well. This includes: • • • • • Packet encryption methods Packet authentication methods Transport versus tunnel mode AH and or ESP usage SA lifetime before it is renegotiated. o VPN User Authentication Methods For Temporary Connections The above sections have been slanted towards a permanent connection between purpose built VPN devices. The VPN uses a separate channel through which the encrypted data passes. the source and destination port is 500. In permanent VPNs. Frequently the device at the other end of the connection is a PC. VPN Security And Firewalls o o All security devices in the path of a VPN connection will have to allow "protocol 50" between the two VPN devices to ensure that IKE works properly. IKE and ISAKMP IKE uses special ISAKMP IP packets using "protocol 50" to establish an Security Association. This uses UDP packets using port 500.

linuxhomenetworking.274 www. the user not only has to enter the username & password. Software uses a username. Remote home user authentication relies on the same username / password combination of the Windows Domain Controller that the user would normally use to login when they are at work. In order to login. Valid usernames and passwords are configured into the VPN device at the other end of the VPN ACE/SecurID Windows Domain Local user database . password in conjunction with a digital key FOB whose authentication serial number changes every few minutes for a login to occur.com Types Of Dial Up VPN Authentication Method IKE-XAUTH secured RADIUS Description Usernames and passwords entered into the VPN remote login software are relayed by the VPN device at the remote end to a trusted RADIUS server. but also the PIN tied to the FOB plus the FOB's dynamic serial number which is synchronized with the authentication server at the other end of the VPN. If the username / password combination is valid for remote login then the RADIUS server will authorize the VPN device to continue with the IKE interchange.

and I need to get to it by using: • A notebook PC with a console cable connected to the COM port. In such cases. connect the other end to the client PC running "Hyperterm" or whatever terminal emulation software you are using. This feature can usually be found on the very first screen under the “Halt On” option.linuxhomenetworking. access to the Linux box can be more cheaply provided via the COM port. • A modem connected to the COM port • Telnet to login to a terminal server that has one of its ports connected to the Linux box’s COM port Preparing To Go “Headless” o One of the advantages of this method is that you don't need a keyboard either. One popular Linux equivalent to Hyperterm is “minicom”. A brief configuration guide for minicom follows the section below. I’ve included this section as I have occasionally hosted the website www. then you'll need a FULL modem cable and testing will have to be done using a dial up connection. You will also need to make sure that you have activated your COM ports in your BIOS settings. Operating costs may not be important at home. Unfortunately your BIOS may halt the system during the Power On Self Test (POST) if it doesn't detect a keyboard. Here is a table that lists the physical ports to their equivalent Linux device names. In other versions of Linux. Make sure you disable this feature in the BIOS setup of your PC before proceeding. This creates what is also known as a “headless” system.Appendix I : Miscellaneous Topics 275 Running Linux Without A Monitor You can reduce the cost of ownership of your Linux system by not using a VGA monitor. locking out network access.com at friends’ homes and felt badly about borrowing their monitors. the COM1 and COM2 ports are controlled by a program called "agetty". Port Linux "agetty" Device Name ttyS0 ttyS1 COM1 COM2 . o o o Configuration Steps In RedHat Linux. If you're using a modem for connectivity. but "agetty" usually isn't activated when you boot up unless its configuration file /etc/inittab is modified. The most common occurrence is when the system is hung. but will be in a corporate environment with large numbers of Linux servers racked in data centers. For non-modem connectivity (PC to PC) connect a NULL modem cable to the COM port you want to test. "agetty" may be called just plain "getty". Having access via the COM ports has also helped me in both the home and business situations.

18-14 on an i586 bigboy login: Note: By default.com The following lines added to /etc/inittab will configure your COM ports for terminal access: # Run COM1 and COM2 gettys in standard runlevels S0:235:respawn:/sbin/agetty -L 19200 ttyS0 vt102 S1:235:respawn:/sbin/agetty -L 19200 ttyS1 vt102 In summary. user "root" will not be able to log in from a terminal. Just add ttyS0 and ttyS1 to the list if you need this access. The "-L" means ignore modem control signals. The next step is to restart the "init" process to re-read /etc/inittab [root@bigboy tmp]# init q Now you need to configure the terminal client such “as Hyperterm” to match the speed settings in /etc/inittab. . "agetty" must attach itself to devices ttyS0 and ttyS1 and emulate a VT102 terminal running at 19200 baud.linuxhomenetworking. The respawn means that agetty will restart automatically if. 3 or 5. Hit "enter" a couple times. this option should be omitted if you are connecting the port to a modem.4. it dies. when the system enters runlevels 2. To do this you'll have to edit the /etc/securetty file which contains the device names of tty lines on which root is allowed to login. and celebrate when you see something like this: Red Hat Linux release 8.0 (Psyche) Kernel 2.276 www. Connect the console / modem cable between the client and your Linux box. for whatever reason. these lines mean: o o o At boot time.

) Configuration Steps The most commonly used Linux terminal emulation program is minicom. It is simple to use mainly because it uses a text based GUI. Here are the steps you’ll need to go through to get it working. We then need to restart the init process to reload the new /etc/inittab settings. (This section will focus on the notebook scenario. COM1 will therefore be used for outbound minicom connections to other systems. There are a number of reasons to do this: • You run Linux on a notebook and you need to use it to access a hung “headless” Linux server via the COM port • You need to gain access to a modem connected to the COM port. not the use of using Linux to dial a modem. Other systems using minicom can use COM2 to access this system. o o You will first need to go through all the relevant steps listed in the “Preparing to go Headless” section of this chapter to ensure you have the right type of cable and correct BIOS settings. You can make your Linux box emulate a dumb terminal quite easily. Edit /etc/inittab # Run COM1 and COM2 gettys in standard runlevels #S0:235:respawn:/sbin/agetty -L 19200 ttyS0 vt102 S1:235:respawn:/sbin/agetty -L 19200 ttyS1 vt102 Restart init [root@bigboy tmp]# init q o Run minicom in setup mode using the minicom –s command [root@bigboy tmp]# minicom –s o You will get the setup menu . In the case below we disable agetty on COM1 by commenting out the ttyS0 agetty statements in the /etc/inittab file. Minicom will clash with your agetty configuration explained in the previous section. You therefore have to disable the agetty configuration for the port on which you wish to run minicom.Appendix I : Miscellaneous Topics 277 Make Your Linux Box Emulate A VT100 Dumb Terminal Dumb terminals can be loosely defined as devices that allow you to log in to your system via the COM port. In other words a “headless” system cannot be used to access another “headless” system using the “headless” COM port.

Connect the cables between the systems Re-enter minicom. Also make sure that flow control is off.. Device /dev/ttyS0 is COM1 and /dev/ttyS1 is COM2.278 www.linuxhomenetworking. | | Exit | | Exit from Minicom | ---------------------------o Select the serial port setup menu item. then Z.Callout Program : | | E Bps/Par/Bits : 19200 8N1 | | F . The way to get around this is for user “root” to .Lockfile Location : /var/lock | | C Callin Program : | | D . Search History Buffer. this time without the “-s” [root@bigboy tmp]# minicom o Hit enter and you should get a login prompt Welcome to minicom 2. Select the “Save setup as dfl” to make this your saved default setting and then “Exit from Minicom” Make sure the other system is correctly configured for headless operation.00. 16:41:20.Software Flow Control : No | | | | Change which setting? | ------------------------------------------o o o o Select the “Modem and dialing” option and make sure the “Init string” and “Reset string” settings are blank.0 OPTIONS: History Buffer. Make the speed match that of the remote “headless” system and make sure the correct serial COM device is chosen.Hardware Flow Control : No | | G . Press CTRL-A Z for help on special keys bigboy login: o o To exit minicom you type CTRL-A. ------------------------------------------| A Serial Device : /dev/ttyS0 | | B . then X Non “root” users will get a “permission denied” message if they use minicom as the COM ports are not normally accessible to regular users. F-key Macros.com ------[configuration]------| Filenames and paths | | File transfer protocols | | Serial port setup | | Modem and dialing | | Screen and keyboard | | Save setup as dfl | | Save setup as. I18n Compiled on Jun 23 2002.

Appendix I : Miscellaneous Topics 279 either give everyone read/write access using the chmod command below. Remember that minicom will reset the privileges to the COM port each time you change the configuration with “minicom –s” so you may find yourself having to run chmod from time to time. or add selected trusted users to your sudo configuration. [root@bigboy tmp]# chmod o+rw /dev/ttyS0 .

The following examples will show how to have a different log file for each class of device. Routers.168. The value provided must be in the format FF. therefore making routers and switches log to the same file.SS (facility.severity) using the numbering scheme below: . In all the network device configuration examples below we are logging to the remote Linux logging server 192. set set set set logging logging logging logging server enable server 192. firewalls and load balancers each logging with a different facility can each have their own log files for easy troubleshooting. We won't change this facility either.linuxhomenetworking. then you may also want to switch off all logging to /var/log/messages as suggested above for the home/SOHO environment. We won't set the facility in this case. Cisco Routers By default Cisco routers send syslog messages to their logging server with a default facility of local7.100 level all 5 server severity 6 Cisco Local Director Local Directors use the "syslog output" command to set their logging facility and severity.100 Catalyst CAT Switches running CATOS By default Cisco switches also send syslog messages to their logging server with a default facility of local7.280 www.1. switches. If you have a large data center.168.1. but we can tell the router to timestamp the messages and make the messages have the source IP address of the loopback interface.168.1. service timestamps log datetime localtime no logging console no logging monitor logging 192.100 which we set up in the previous section.com Syslog Configuration and Cisco Devices Syslog reserves facilities "local0" through "local7" for log messages received from remote servers and network devices.

1.Appendix I : Miscellaneous Topics 281 Facility local 0 local 1 local 2 local 3 local 4 local 5 local 6 local 7 FF Value 16 17 18 19 20 21 22 23 Severity System unusable Immediate action required Critical condition Error conditions Warning conditions Normal but significant conditions Informational messages Debugging messages SS Value 0 1 2 3 4 5 6 7 Here we using facility LOCAL4 and logging debugging messages and above.100 .168. syslog output 20.7 no syslog console syslog host 192.

168. logging logging logging logging logging logging on standby timestamp trap notifications facility 19 host inside 192. Facility Logging Facility Command Value 16 17 18 19 20 21 22 23 local 0 local 1 local 2 local 3 local 4 local 5 local 6 local 7 This configuration example assumes that the logging server is connected on the side of the "inside" protected interface.com Cisco PIX Filewalls PIX firewalls use the following numbering scheme to determine their logging facilities.100 facility 6 set logging subsystem all info-6 logging commands enable . This example shows the CSS11000 logging facility LOCAL 6 and severity level 6 (Informational) logging host 192. You specify the facility with an intuitive number using the "logging host" command and set the severity with the "logging subsystem" command.100 Cisco CSS11000 (Arrowpoints) This configuration for this is more straight forward.168. We're sending log messages to facility LOCAL3 with a severity level of 5 (Notification) set by the "logging trap" command.1.linuxhomenetworking.282 www.1.

debug /var/log/cisco/ciscold # # All LOCAL6 messages (debug and above) go to the CSS file ciscocss # local6.notice /var/log/cisco/ciscoinfo local7.debug /var/log/cisco/ciscofw # # All LOCAL4 messages (debug and above) go to the Local Director file ciscold # local4.debug ciscoacl # # LOCAL7 messages (notice and above) go to the ciscoinfo # This excludes ACL logs which are logged at severity debug # local7.debug /var/log/cisco/ciscocss # # All LOCAL7 messages (debug and above) go to the ciscoacl # This includes ACL logs which are logged at severity debug # local7.Appendix I : Miscellaneous Topics 283 The Sample Cisco syslog.notice ciscoinfo .conf File # # All LOCAL3 messages (debug and above) go to the firewall file ciscofw # local3.debug /var/log/cisco/ciscoacl local7.

Linux partitions handle all files in the subdirectory of your choice. What Is A Filesystem? Filesystems can be considered as being the directory structures on a disk partition that contains all the files. everything appears to be a single set of "folders" or directories. The directory allocation will be: Partition /var/log /var Directory Allocation All files in directory /var/log and all the subdirectories underneath /var/log All files in /var except the contents of directory /var/log and all the subdirectories underneath /var/log . Partitions cannot be moved or resized without destroying the data on them. This allows you to be able to boot different operating systems from the same disk. the partitions hide underneath unseen to the regular user. each of which is treated as a separate disk by your operating system. In other words. whereas Linux users would be familiar with the terms "directories" and "sub-directories". The choice of which subdirectories belong in which partition is made when you partition the hard drive. What Is A Partition? A partition is a means of dividing your hard disk into multiple sections. Linux and Windows. for example. Most Windows users would be familiar with the analogous terms "folders" and "subfolders". In Linux.com Disk Partitioning Explained Here’s some interesting information on how Linux handles hard drives and their partitions. How Linux Links Filesystems And Partitions In Windows. a disk with two partitions would most likely find itself with a "C:" drive and a "D:" drive each with a separate set of folders.284 www. If you create a file system called "/var" and another called "/var/log".linuxhomenetworking.

This reduces the need to reformat the "root" partition if it becomes corrupted. In most cases. . you may look at the bottom of the table to see the settings I used for the 4GB hard disk I used to first run www.com The RedHat default partitioning scheme used during the Linux installation should be sufficient for most home / SOHO systems. Recommended Sizes For Disk Partitions Here are some allocation suggestions that may be useful. a corrupted root filesystem will make your system unbootable from the hard drive. RedHat automatically creates this partition and usually makes it about twice the amount of system RAM. Usually recovery requires reformatting the root file system and doing a Linux reinstall. swap Used as a location to place data temporarily if RAM memory becomes full.Appendix I : Miscellaneous Topics 285 What Partitions Are Mandatory? The mandatory partitions are: "/". /boot The /boot partition contains the Linux kernel which is the "master control program". Most Linux systems then will then become multi-user systems by changing their runlevel and executing the associated startup scripts including those that will mount the remaining file systems.linuxhomenetworking. This is a generous guide. there is a high possibility that you will lose all your data. Also Known As "root" The root filesystem ("/") contains the files necessary for the system to boot up in single user mode with the bare minimum of functionality. It is for this reason that you should consider placing similar files in dedicated partitions. If all your files are located in a root filesystem that becomes corrupted. especially if you have more than 4GB. but also the normal functioning of Linux. Redhat Linux creates this partition automatically. not only for controlling the boot process.

286 www. /home Variable Variable . Contains the system kernel files.5+ GB 500 4.0+ GB 500+ 1. / Usually called "root" /boot Automatically determined by RedHat 50 (approx) Automatically determined by RedHat 50 (approx) 1.0+ GB 750+ 500+ 750+ N/A 250+ Third party software Man pages (Help files) Error log files Print queues (Needed only if you plan to do printing) Mail queues Temporary files Multiply the expected number of users by the amount of disk space you want to assign per user.0+ GB 250+ /usr /var /var/log /var/spool /var/spool/mail /tmp 2.linuxhomenetworking. Remember MP3s fill disks quickly.com Some Recommended Partition Sizes Partition Size Workstation / Home Web Server (MB) Swap 2X Physical Memory 100 Size Mail Server (MB) Purpose of the Partition 2X Physical Memory 100 Used as a location to place data temporarily if RAM memory becomes full Base system program files Configuration files Libraries Device drivers Assigned automatically by RedHat.

you can ask users to delete unnecessary files such as downloaded software and MP3s If it is in the /var partition.Appendix I : Miscellaneous Topics 287 How Much Space Do I Have On My Partitions? You can use the "df" command. You may want to also consider backing up files and then deleting them. These are the settings I used for the hard disk I used to first run this site. [root@bigboy root]# df -k Filesystem 1K-blocks /dev/hda3 505636 /dev/hda1 46636 /dev/hda5 505605 /dev/hda7 830104 /dev/hda2 4633108 /dev/hda6 256667 [root@bigboy root]# Used Available Use% Mounted on 90002 389529 19% / 9164 35064 21% /boot 87915 391586 19% /home 17632 770304 3% /tmp 1797504 2600252 41% /usr 169577 73838 70% /var What Can I Do When I Run Out Of Disk Space? o o If it is in the /home partition. then you can consider deleting some of your log files in /var/log. See the logging page for a description of the log files and how you can use the "logrotate" command to help reduce their size. o .

data is frequently sent using the MAC addresses of the NIC cards of the communicating devices. The Seven OSI Layers Layer Name Description Application 7 Applicati on Presentat ion • The user interface to the application Telnet FTP Sendmail 6 • Converts data from one presentation format to another. It consists of layers of sub-applications. For example. IP and ARP can be found in the Introduction to Networking chapter. • Error control and timing of bits speeding down the wire between two directly connected devices. In the home environment. Your network address can stay the same if the NIC is replaced. each building on the lower ones to provide a complete connectivity solution. Each layer generally has "hooks" into the layer immediately above and below it so that the data can flow smoothly through the sub-applications designed to handle each layer. • Handles the routing of data between links that are not physically connected together.linuxhomenetworking. • Also provides the option of having multiple addresses of the same networking protocol being assigned to the same MAC address.288 www. • Manages continuing requests and responses between the applications at both ends over the various established connections.com The OSI Networking Model The Open System Interconnection (OSI) protocol suite acts as a framework for designing network based applications. Correctly re-sequences data packets that arrive in the wrong order. Detailed descriptions of TCP. • Also allows you to select your own numbering scheme for the global network independent of the MAC address which in rare cases could also be duplicated. • Defines the electrical and physical characteristics of the network cabling and interfacing hardware TCP UDP 5 Session 4 Transport 3 Network IP ARP 2 Link Ethernet ARP 1 Physical Ethernet . Ensures that unacknowledged data is retransmitted. • Manages the establishment and tearing down of a connection. • Used as a means of not tying the address of the server to its MAC address. UDP. email text entered into Outlook express being converted into SMTP mail formatted data.

is the current version used by most devices on the Internet. The TTL decrement feature is used by routers as an additional precaution to prevent the packet from mistakenly being routed around the Internet in an infinite loop due to a routing error. Total length of the IP header Total length of the IP packet IHL Total Length DF Bit Indicator to tell whether the data in the packet may be fragmented into smaller packets due to limitations of the communications line Indicator to tell whether this data in this packet is the last one of a stream of fragments. then this specifies where in the complete datagram the data in this packet should be inserted. Defines the type of protocol header to expect at the end of this header. If this packet is part of a fragmented datagram. The server sending the data usually sets the TTL to a value high enough to reach it's destination without being discarded. When the value reaches zero. IP Header TCP/UDP Header DATA Contents Of The IP Header Field IP Version Description The version of IP being used. Time to live. MF Bit Fragment Offset TTL Protocol Header checksum Source Address Destination Address Indicates the IP address of the server sending the data Indicates the IP address of the server intended to receive the data .Appendix I : Miscellaneous Topics 289 TCP/IP Packet Format The TCP/IP packet contains an IP header followed by a TCP or UDP header followed by the TCP/UDP data. Internet Header Length. This value is decremented by each router through which the packet has passes. 17 = UDP Used to ensure that the header contents are error free. For example. Version 6. 6 = TCP. Version 4. the packet is discarded by the router. is a newer format which allows for a much more vast range of addresses.

Length of the TCP header. In the connection-establishment phase. Carries a variety of control information. Usually specifies the number assigned to the first byte of data in the current message. this field also can be used to identify an initial sequence number to be used in an upcoming transmission.linuxhomenetworking. Specifies the length of the UDP header and data Used to ensure that the header contents are error free. Contains upper-layer information Acknowledgment Number Data Offset Flags Window Checksum Data Contents Of The UDP Header Field Source and Destination Port Length Checksum Description Identifies points at which upper-layer source and destination processes receive TCP services. and the FIN bit used for connection termination. including the SYN and ACK bits used for connection establishment. Specifies the size of the sender's receive window (that is. the buffer space available for incoming data) Used to ensure that the header contents are error free. Contains the sequence number of the next byte of data the sender of the packet expects to receive.290 www. .com Contents Of The TCP Header Field Source and Destination Port Sequence Number Description Identifies points at which upper-layer source and destination processes receive TCP services.

Appendix I : Miscellaneous Topics 291 .

292 www.com .linuxhomenetworking.

..................................................................... Scripts and Configurations ......................................................................................................................................................................................................................................... ........................................................296 Sendmail SPAM Filter Script .......................305 DNS Zone File For my-site.....329 Cisco PIX Firewall .........................................com ..........................................................297 IPtables FTP Client..................DHCP DSL Configuration...........................................................................................................293 Appendix II Codes........................ Scripts and Configurations =========================================== In This Chapter Appendix II......................................294 Apache File Permissions Script .........................................................................linuxhomenetworking.............. 293 Subnet Calculator Script ..................................319 Forward Zone File For A Home Network Using NAT ...com .............................................................................................................322 Sendmail Sample /etc/aliases File .323 Sendmail Sample /etc/mail/sendmail............................Static DSL Configuration..........................................................................mc File ....305 IPtables Complex script ...................................................................................320 Reverse Zone File For A Home Network Using NAT ............................................................................. www.................................................................................324 Sendmail Sample /etc/mail/virtusertable File...........................320 Sendmail Sample /etc/mail/access File .................................................................com =========================================== Here we have samples of all the scripts used in the previous chapters....................................319 DNS Zone File For my-other-site...................................................................................327 Cisco PIX Firewall ................ 293 Codes.....................................................................................................................326 ICMP Codes.......................................................................................................................................................................................................................................................................................................................................................................................................322 Sendmail Sample /etc/mail/local-host-names File .....................................................................................................................................304 IPtables NTP Server..............................................................................................................................................................................................303 IPtables FTP Server .................330 © Peter Harrison..

then netmask="255.sh .255.255.255” or in # the range /24 to /30 # # Usage: # # subnet-calc. then netmask="255.com # # # Get the IP address.255.255.255.255. then netmask="255.linuxhomenetworking.255.294 www.224" fi if [ "$netmask" = "/26" ]. then netmask="255. then netmask="255. then netmask="255.252" fi if [ "$netmask" = "/29" ].192" fi if [ "$netmask" = "/25" ].255.240" fi if [ "$netmask" = "/27" ].255.255.128" fi .com Subnet Calculator Script #/bin/bash # # subnet-calc.248" fi if [ "$netmask" = "/28" ].255. the subnet mask and broadcast address of # the external interface # IPADDR=$1 netmask=$2 # # Convert "/" notation to dotted decimal # if [ "$natmask" = "/30" ].sh IP-address subnet-mask # # (c) SiliconValleyCCIE.255.255.Calculates subnets given an IP address and subnet mask # The subnet mask must begin with “255.

//g'`" # # Get first three octets of the IP address # IPADDR_octet_1="`echo IPADDR_octet_2="`echo IPADDR_octet_3="`echo IPADDR_octet_4="`echo $IPADDR $IPADDR $IPADDR $IPADDR | | | | sed sed sed sed -e -e -e -e 's/\. Scripts and Configurations 295 if [ "$netmask" = "/24" ]. then netmask="255.255. then subnet_base="0" else subnet_base=$[$IPADDR_octet_4/$subnet_size] subnet_base=$[$subnet_base*$subnet_size] fi SUBNET_BASE=$IPADDR_octet_1./ 's/\.$IPADDR_octet_2.$IPADDR_octet_3.255.$IPADDR_octet_3./ /g' /g' /g' /g' | | | | awk awk awk awk '{print '{print '{print '{print $1}'`" $2}'`" $3}'`" $4}'`" # # Get the size of the subnet # subnet_size=$[256-$netmask_octet_4] # # Get the last octet of the network address # if [ "$netmask_octet_4" = "0" ].$subnet_base SUBNET_BROADCAST=$IPADDR_octet_1.0" fi # # Get the last octet of the subnet mask # netmask_octet_4="`echo $netmask | sed -e 's/255.Appendix II : Codes./ 's/\.$[$subnet _base-1+$subnet_size] echo echo echo echo echo echo echo echo "IP Address : "$IPADDR "Network Base Address : "$SUBNET_BASE "Broadcast Address : "$SUBNET_BROADCAST "Subnet Mask "Subnet Size : "$netmask : "$subnet_size IP Addresses .$IPADDR_octet_2./ 's/\.

/fix-www-perms.296 www. [root@bigboy tmp]# .com # for i in `find $1` do if [ -d $i ] .. The script will print out a list of all the files it’s modified to the screen.sh . [root@bigboy tmp] Here’s how it’s done: #!/bin/sh # # fix-www-perms.htm .com Apache File Permissions Script The first argument of the script is the target directory and must have a trailing "/". . then chmod 755 $i echo $i else chmod 644 $i echo $i fi done . .htm /home/www/webpages/file2..linuxhomenetworking..Recursively fixes file permissions in a www directory # so that Apache may serve the pages correctly # # (c) SiliconValleyCCIE...sh /home/www/webpages/ /home/www/webpages/ /home/www/webpages/file1..

• The first column has either the word “subject:” or “address:” and the second column has either a subject string (inclusive of spaces) or a single address entry. • The script will match addresses in both the TO: and FROM: of the received email. o o o Click on the CPAN home page's "modules” link Click the "All Modules" listing and download and install the MailTools.pl in your $HOME directory (default login directory) • Use the “chmod” command to make it executable [root@bigboy mailuser]# chmod 700 mail-filter. If you receive emails as part of mailing lists. • The script will reject emails in which your email address doesn’t appear in the “TO:”. it then reads the accept file and accepts any matching emails. • The script is very tolerant of email addresses. Here is a sample I’ve used at home for some time. • Mail-filter. put the name of the mailing list in your “accept” file. IO-Stringy. • You will have to go to www.cpan. The CPAN modules page also has a link on how to install the modules.Appendix II : Codes. “BCC:” emails are therefore denied.pl • Create a .org to download and install a variety of PERL modules beforehand.accept lists all the mail to accept and file mailfilter. Here’s how to install the script: • The script runs using the PERL scripting language which is installed by default on RedHat. Here is a summary of its operation: • This script is called mail-filter.forward file in your home directory with the following text: . “FROM:” or “CC:”. File mail-filter. The script will match on a partial address too. [root@bigboy mailuser]# cd /etc/smrsh [root@bigboy smrsh]# ln –s /home/mailuser/ mail-filter. You do not have to have an “@” sign in the configuration files’ entries. then it denies everything else. • The script reads the “reject” file and rejects any matching emails. Look at this file from time to time as you may find yourself rejecting too much traffic which will require you to modify the configuration files.pl • It uses two configuration files.log.pl file there. Each file has two columns.pl will log all accepted and denied emails in a file called mail-filter. • Place mail-filter.pl • Go to directory /etc/smrsh and create a logical link to the mail-filter. MIME-tools & Mail-Audit modules in that order.reject lists all the mail to reject. Scripts and Configurations 297 Sendmail SPAM Filter Script One of the good things about having a Linux box at home is that you can create your own customized SPAM filter.

pl # use Mail::Audit.PERL Script # # by Peter Harrison © www.forward file with the following line in it # #/bin/bash # | ~/mail-filter. MIME-tools & Mail-Audit in this order # # Need to have: # # a logical link to this file in /etc/smrsh # .com address: cnn subject: Alumni Association The mail-filter.linuxhomenetworking. # # Spam filter variables # .pl • You should then be ready to go! The mail-filter.1/Audit.cpan.html # # Need to install the following modules: # # MailTools.LinuxHomeNetworking.accept File address: my-address@mysite. IO-Stringy.html # # PERL modules needed from http://www.org/author/SIMON/Mail-Audit-2.cpan.org/modules/01modules.com #!/bin/bash | ~/mail-filter.pm # http://simon-cozens.index.org/writings/mail-audit.298 www.com subject: porn The mail-filter Script #!/usr/bin/perl # # # Mail-filter .reject File address: spammer@spammer.com # # Reference pages # # http://search.

chomp($FROM. study $CC. $SUBJECT). $TO. (). $type) = &Strip_Record($record).accept". study $TO. sub Mail_Filter { my my my my %badsubjects %badaddresses %goodsubjects %goodaddresses = = = = (). } } close (REJECT_FILE). "$REJECT_FILE").Appendix II : Codes. #################### Don't edit below here ################### $ITEM $FROM $TO $CC $SUBJECT $DATE $INBOX_LOG $ACCEPT_FILE $REJECT_FILE = = = = = = = = Mail::Audit->new. # # Get the bad subjects / address # if ($type =~ /subject/i){ $badsubjects{$value} = "$type". (). chomp($DATE = `date '+ %m/%d/%Y %H:%M:%S'`). $FILEPATH .log". $ITEM->cc(). while(<REJECT_FILE>){ my $record = $_. "mail-filter. $FILEPATH . "mail-filter. "". (). # # Read in the configuration files # open (REJECT_FILE. $ITEM->subject(). } if ($type =~ /address/i){ $badaddresses{$value} = "$type". $ITEM->to(). Scripts and Configurations 299 $FILEPATH = "/home/mailuser/". exit. $CC. my ($value. study $SUBJECT. "mail-filter. = $FILEPATH . $ITEM->from(). &Mail_Filter. study $FROM. .reject".

} # # Accept emails to/from these addresses # for my $criteria (keys %goodaddresses) { . # # Reject by subject # foreach my $criteria (keys %badsubjects) { next unless $SUBJECT =~ /$criteria/i. } # # Accept some subject lines # for my $criteria (keys %goodsubjects) { next unless $SUBJECT =~ /$criteria/i. while(<ACCEPT_FILE>){ my $record = $_. my ($value.300 www. &Reject_Mail("no"). &Reject_Mail("yes").linuxhomenetworking. "$ACCEPT_FILE").com open (ACCEPT_FILE. &Reject_Mail("yes"). } if ($type =~ /address/i){ $goodaddresses{$value} = "$type". $type) = &Strip_Record($record). # # Get the good subjects / address # if ($type =~ /subject/i){ $goodsubjects{$value} = "$type". } # # Reject email to/from these addresses # foreach my $criteria (keys %badaddresses) { next unless ($TO =~ /$criteria/i) or ($CC =~ /$criteria/i) or ($FROM =~ /$criteria/i). } } close (ACCEPT_FILE).

&Reject_Mail("no"). # # Log message receipt to file # if ($ok =~ /yes/i){ print LOG "REJECT $DATE To: $TO From: $FROM Subject: $SUBJECT\n".*?)\s*$/$1/. } sub Strip_Record{ my $record = shift(@_). $domain. } } } sub Reject_Mail { my $ok = shift(@_)."\@" . "address"). return ($person . ">> $INBOX_LOG"). "subject"). } else{ return ($fields[1].Appendix II : Codes. $domain) = split(/\@/. open (LOG. $fields[1] =~ s/^\s*(. # # Return the subjects / addresses # if ($fields[0] =~ /subject/i){ return ($fields[1]. $ITEM->reject.$record). # # Split out the fields in the record and strip out #leading/trailing white space # chomp $record. $fields[1]). } # # Reject everything else # &Reject_Mail("yes"). Scripts and Configurations 301 next unless ($TO =~ /$criteria/i) or ($CC =~ /$criteria/i) or ($FROM =~ /$criteria/i). } elsif ($fields[0] =~ /address/i){ if ($fields[1] =~ /\@/){ my ($person. my @fields = split(/\:/. } . "address").

} .302 www. exit. $ITEM->accept.com else{ print LOG "ACCEPT $DATE To: $TO From: $FROM Subject: $SUBJECT\n".linuxhomenetworking. } close(LOG).

RELATED -j ACCEPT #--------------------------------------------------------------# FTP connections from your Linux server # Passive FTP data connection established from your Linux server #--------------------------------------------------------------iptables -A -m state iptables -A -m state OUTPUT -o eth0 -p tcp --dport 1024:65535 --sport 1024:65535 \ --state NEW -j ACCEPT INPUT -i eth0 -p tcp --sport 1024:65535 --dport 1024:65535 \ --state ESTABLISHED.Appendix II : Codes.Interface eth0 is the internet interface # . Scripts and Configurations 303 IPtables FTP Client # .RELATED -j ACCEPT #=============================================================== #=============================================================== # Select one of the following two #=============================================================== #=============================================================== #--------------------------------------------------------------# FTP connections from your Linux server # Active FTP data connection established back from remote server #--------------------------------------------------------------iptables -A -m state iptables -A -m state INPUT -i eth0 -p tcp --sport 20 --dport 1024:65535 \ --state NEW -j ACCEPT OUTPUT -o eth0 -p tcp --dport 20 --sport 1024:65535 \ --state ESTABLISHED.RELATED -j ACCEPT .Interface eth1 is the private network interface modprobe ip_conntrack_ftp #--------------------------------------------------------------# FTP connections from your Linux server # Outbound FTP requests on control connection (port 21) #--------------------------------------------------------------iptables -A -m state iptables -A -m state OUTPUT-o eth0 -p tcp --sport 1024:65535 --dport 21 \ --state NEW -j ACCEPT INPUT -i eth0 -p tcp --sport 21 --dport 1024:65535 \ --state ESTABLISHED.

Interface eth0 is the internet interface # .Interface eth1 is the private network interface modprobe ip_conntrack_ftp #--------------------------------------------------------------# FTP connections to your Linux server # Inbound FTP requests on control connection (port 21) #--------------------------------------------------------------iptables -A -m state iptables -A -m state INPUT -i eth0 -p tcp --dport 21 --sport 1024:65535 \ --state NEW -j ACCEPT OUTPUT-o eth0 -p tcp --dport 1024:65535 --sport 21 \ --state ESTABLISHED.RELATED -j ACCEPT #=============================================================== #=============================================================== # Select one of the following two #=============================================================== #=============================================================== #--------------------------------------------------------------# FTP connections to your Linux server # Active FTP data connection established back to client from # your server #--------------------------------------------------------------iptables -A -m state iptables -A -m state OUTPUT -o eth0 -p tcp --sport 20 --dport 1024:65535 \ --state NEW -j ACCEPT INPUT -i eth0 -p tcp --dport 20 --sport 1024:65535 \ --state ESTABLISHED.RELATED -j ACCEPT .RELATED -j ACCEPT #--------------------------------------------------------------# FTP connections to your Linux server # Passive FTP data connection established to your Linux server # from remote client #--------------------------------------------------------------iptables -A -m state iptables -A -m state INPUT -i eth0 -p tcp --sport 1024:65535 --dport 1024:65535 \ --state NEW -j ACCEPT OUTPUT -o eth0 -p tcp --dport 1024:65535 --sport 1024:65535 \ --state ESTABLISHED.304 www.linuxhomenetworking.com IPtables FTP Server # .

253.158.255" address NOC_SUBNET="180.0/24" firewall with pings WEBSERVER="192. mail.168.25" EXTERNAL_SUBNET_BASE="97.Interface eth1 is the private network interface iptables -A OUTPUT -o eth0 -p udp -m multiport --ports 123 \ -j ACCEPT iptables -A INPUT -i eth0 -p udp -m multiport --ports 123 \ -j ACCEPT IPtables Complex script #!/bin/bash # # DNS.168.0/24" address space # Internet-connected interface # Interface connected to the # your IP address # ISP network segment base # network segment broadcast # NOC subnet that monitors the # Test webserver for port # Protected internal network .168.0" address EXTERNAL_SUBNET_BROADCAST="97.253.158.Appendix II : Codes. Scripts and Configurations 305 IPtables NTP Server # .1.253.Interface eth0 is the internet interface # .101" forwarding and masquerading INTERNAL_NET="192.158. and web servers running on a firewall used as \ # the Internet NAT gateway for a home network # modprobe ip_conntrack_ftp modprobe iptable_nat #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= # # The variables in this section are site specific and should be # changed to match your network # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= EXTERNAL_INT="eth1" INTERNAL_INT="eth0" private network EXTERNAL_IP="97.7.1.

Clear and recreate existing chains prior to # adding rules to the chains # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= .linuxhomenetworking.0.38.127" server TIME_SERVER2="65.0.203.0.0/12" networks RESERVED_IP_10_SPACE="10.0.81.0/16" RESERVED_IP_172_SPACE="172.168.0.113" server # address of a remote time # address of a remote time # address of a remote time #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= # # The variables below should not normally be changed as they # are not site specific # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= LOOPBACK="127.0/4" RESERVED_IP_FUTURE="240.0.0.0/5" use HIGH_PORTS="1024:65535" clients using servers # reserved loopback address range # class C private networks # RFC1918 172 space B private # RFC1918 10 space private # Multicast addresses # IP addresses reserved for future # High TCP/UDP ports used by #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= # # Define the names of the user defined chains we'll be using # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= ADDITIONAL_CHAINS="INPUT-external OUTPUT-icmp-external local-tcp-client local-ntp-client valid-tcp-flags valid-source-address LOG-and-drop" OUTPUT-external \ INPUT-icmp-external \ remote-tcp-client \ remote-ntp-server \ established-connection \ valid-destination-address \ #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#= # # Prepare Chains .0/8" networks RESERVED_IP_MULTICAST="224.206" server TIME_SERVER3="207.0.0.60.com TIME_SERVER1="192.16.200.0/8" RESERVED_IP_192_SPACE="192.0.6.306 www.

Appendix II : Codes. # We'll recreate them in the next step #--------------------------------------------------------------iptables iptables iptables iptables --delete-chain -t filter --delete-chain -t nat --delete-chain -t mangle --delete-chain #--------------------------------------------------------------# If a packet doesn't match one of the built in chains. Scripts and Configurations 307 #--------------------------------------------------------------# Delete all entries in the built-in tables. do iptables -N $i . then # The policy should be to drop it #--------------------------------------------------------------iptables iptables iptables iptables iptables --policy INPUT DROP --policy OUTPUT DROP --policy FORWARD DROP -t nat --policy POSTROUTING ACCEPT -t nat --policy PREROUTING ACCEPT #--------------------------------------------------------------# The loopback interface should accept all traffic #--------------------------------------------------------------iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT #--------------------------------------------------------------# Re-create our user-defined chains #--------------------------------------------------------------for i in $ADDITIONAL_CHAINS. #--------------------------------------------------------------iptables iptables iptables iptables --flush -t filter --flush -t nat --flush -t mangle --flush #--------------------------------------------------------------# Delete all the user defined chains.

Local machine initiating connections to a # remote server # # TCP responses from the remote server are handled # by the established-connection chain # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# iptables -A OUTPUT-external -p tcp --sport $HIGH_PORTS \ -j local-tcp-client #--------------------------------------------------------------# Local client rules for: # # SMTP .308 www.Port 25 # SSH .22.Remote machines initiating connections to # local server # # TCP responses from the local server are handled # by the established-connection chain # .com done #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # TCP Rules .113 \ --syn -m state --state NEW -j ACCEPT #--------------------------------------------------------------# Passive FTP data.Port 21 #--------------------------------------------------------------iptables -A local-tcp-client -p tcp \ -m multiport --dport 25.Port 113 # FTP control .linuxhomenetworking. initiated from local machine to # remote server #--------------------------------------------------------------iptables -A local-tcp-client -p tcp --dport $HIGH_PORTS \ --syn -m state --state NEW -j ACCEPT #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # TCP Rules .21.Port 22 # AUTH (ident) .

Source and Destination port the same (123) #--------------------------------------------------------------iptables -A OUTPUT-external -p udp -m multiport --ports 123 \ -j local-ntp-client iptables -A INPUT-external -p udp -m multiport --ports 123 \ -j remote-ntp-server iptables -A local-ntp-client -p udp -d $TIME_SERVER1 \ -j ACCEPT iptables -A local-ntp-client -p udp -d $TIME_SERVER2 \ -j ACCEPT iptables -A local-ntp-client -p udp -d $TIME_SERVER3 \ .25.Port 110 # DNS .Appendix II : Codes.53.Port 22 # POP mail .Port 25 # SSH .22.443.Port 21 #--------------------------------------------------------------iptables -A remote-tcp-client -p tcp -m state --state NEW \ -m multiport --dports 80.Port 443 # SMTP .110 \ -j ACCEPT #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # UDP Rules # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #--------------------------------------------------------------# NTP time client .Port 113 # FTP control .21.Port 80 # HTTPS .Port 53 # AUTH (ident) . Scripts and Configurations 309 #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# iptables -A INPUT-external -p tcp --sport $HIGH_PORTS \ -j remote-tcp-client #--------------------------------------------------------------# Local server rules for: # # HTTP (www) .

com -j ACCEPT iptables -A remote-ntp-server -p udp -s $TIME_SERVER1 \ -j ACCEPT iptables -A remote-ntp-server -p udp -s $TIME_SERVER2 \ -j ACCEPT iptables -A remote-ntp-server -p udp -s $TIME_SERVER3 \ -j ACCEPT #--------------------------------------------------------------# DNS server to DNS server queries via UDP #--------------------------------------------------------------iptables -A OUTPUT-external -p udp -m multiport --ports 53 \ -j ACCEPT iptables -A INPUT-external -p udp -m multiport --ports 53 \ -j ACCEPT #--------------------------------------------------------------# Remote DNS clients querying local DNS server via UDP #--------------------------------------------------------------iptables -A INPUT-external -p udp --sport $HIGH_PORTS --dport 53 \ -j ACCEPT iptables -A OUTPUT-external -p udp --sport 53 --dport $HIGH_PORTS \ -j ACCEPT #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # Port forwarding statements # # (FORWARD statements related to ESTABLISHED and RELATED traffic # is covered in the CORE Chains section) # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #--------------------------------------------------------------# Allow port forwarding on port 8080 to port 80 on server $WEBSERVER #--------------------------------------------------------------iptables -t nat -A PREROUTING -p tcp -i $EXTERNAL_INT -d $EXTERNAL_IP \ .310 www.linuxhomenetworking.

Scripts and Configurations 311 --dport 8080 --sport 1024:65535 -j DNAT --to $WEBSERVER:80 #--------------------------------------------------------------# After DNAT.Start #=# #=# #=# #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # Install the User-defined Chains on the built-in # INPUT and OUTPUT chains # . They include not responding to packets with # the following bad characteristics: # # 1) Incorrect TCP flags in the header # 2) Attempts to connect or respond to bogus IP addresses # 3) Attempts to connect or respond to applications not suitable # for use over the Internet # # All the user defined chains are also tied to the built in # INPUT and OUTPUT chains in this section # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #=# #=# #=# CORE Chains . # Connections on port 80 to the target machine on the private # network must be allowed. #--------------------------------------------------------------iptables -A FORWARD -p tcp -i $EXTERNAL_INT -o $INTERNAL_INT -d $WEBSERVER \ --dport 80 --sport 1024:65535 -m state --state NEW -j ACCEPT #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # Rules in the section below should not normally be changed # for most firewalls. the packets are routed via the filter table's FORWARD chain.Appendix II : Codes.

linuxhomenetworking.312 www.com #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #--------------------------------------------------------------# Check TCP packets for invalid state flag combinations #--------------------------------------------------------------iptables -A INPUT -p tcp -j valid-tcp-flags iptables -A OUTPUT -p tcp -j valid-tcp-flags #--------------------------------------------------------------# Verify valid source and destination addresses for all packets #--------------------------------------------------------------iptables iptables iptables iptables -A -A -A -A INPUT -p ! tcp -j valid-source-address INPUT -p tcp --syn -j valid-source-address INPUT -j valid-destination-address OUTPUT -j valid-destination-address #--------------------------------------------------------------# Already established connections should be allowed #--------------------------------------------------------------iptables -A INPUT -j established-connection iptables -A OUTPUT -j established-connection #--------------------------------------------------------------# Start the protocol specific rules #--------------------------------------------------------------iptables -A INPUT -i $EXTERNAL_INT -d $EXTERNAL_IP -j INPUT-external iptables -A OUTPUT -o $EXTERNAL_INT -s $EXTERNAL_IP -j OUTPUT-external #--------------------------------------------------------------# Allow all bidirectional traffic from your firewall to the protected network #--------------------------------------------------------------iptables -A INPUT -j ACCEPT -p all -s $INTERNAL_NET -i $INTERNAL_INT iptables -A OUTPUT -j ACCEPT -p all -d $INTERNAL_NET -o $INTERNAL_INT #--------------------------------------------------------------# Allow masquerading # Enable routing by modifying the ip_forward /proc filesystem file #--------------------------------------------------------------- .

RELATED -j ACCEPT #--------------------------------------------------------------# Log all other packets.Stop #=# #=# #=# #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # Check for incorrect TCP state flags # # # All state bits zeroed .RELATED -j ACCEPT iptables -A FORWARD -t filter -i $EXTERNAL_INT -m state \ --state ESTABLISHED. The default policy will also drop them #--------------------------------------------------------------iptables -A INPUT -j LOG-and-drop iptables -A OUTPUT -j LOG-and-drop #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #=# #=# #=# CORE Chains . the packets are routed via the filter # table's FORWARD chain. established and related connections # Allowed inbound : Established and related connections # # These statements handle both FORWARD-ing for both MASQUERADE # and port forwarding # #--------------------------------------------------------------iptables -A FORWARD -t filter -i $INTERNAL_INT -m state \ --state NEW.Appendix II : Codes.ESTABLISHED. Scripts and Configurations 313 iptables -A POSTROUTING -t nat -o $EXTERNAL_INT -s $INTERNAL_NET \ -d 0/0 -j MASQUERADE echo 1 > /proc/sys/net/ipv4/ip_forward #--------------------------------------------------------------# Prior to masquerading. # Allowed outbound: New.

255.2.254.0/24 -j DROP $EXTERNAL_IP -j DROP iptables -A valid-destination-address -d $EXTERNAL_SUBNET_BASE -j DROP iptables -A valid-destination-address -d $EXTERNAL_SUBNET_BROADCAST -j DROP iptables -A valid-destination-address -d $RESERVED_IP_MULTICAST -j DROP .0.255.255 -j DROP 169.linuxhomenetworking.PSH PSH -j LOG-and-drop ACK.URG URG -j LOG-and-drop SYN.0/8 -j DROP 255.RST FIN.0.0.FIN SYN.RST -j LOG-and-A valid-tcp-flags -p tcp --tcp-flags FIN.RST SYN.FIN -j LOG-and- -A valid-tcp-flags -p tcp --tcp-flags SYN.com # FIN set ACK cleared # PSH set ACK cleared # URG set ACK cleared # SYN and FIN set # SYN and RST set # FIN and RST set # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# iptables iptables iptables iptables iptables drop iptables drop iptables drop -A -A -A -A -A valid-tcp-flags valid-tcp-flags valid-tcp-flags valid-tcp-flags valid-tcp-flags -p -p -p -p -p tcp tcp tcp tcp tcp --tcp-flags --tcp-flags --tcp-flags --tcp-flags --tcp-flags ALL NONE -j LOG-and-drop ACK.0/16 -j DROP 192.0.314 www.RST -j LOG-and- #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # Source and Destination Address Sanity Checks # # Drop packets from networks covered in RFC 1918 (private nets) # Drop packets from external interface IP # Drop directed broadcast packets # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# iptables iptables iptables iptables iptables iptables iptables iptables iptables iptables iptables -A -A -A -A -A -A -A -A -A -A -A valid-source-address valid-source-address valid-source-address valid-source-address valid-source-address valid-source-address valid-source-address valid-source-address valid-source-address valid-source-address valid-source-address -s -s -s -s -s -s -s -d -s -s -s $RESERVED_IP_10_SPACE -j DROP $RESERVED_IP_172_SPACE -j DROP $RESERVED_IP_192_SPACE -j DROP $RESERVED_IP_MULTICAST -j DROP $RESERVED_IP_FUTURE -j DROP $LOOPBACK -j DROP 0.FIN FIN -j LOG-and-drop ACK.

Scripts and Configurations 315 #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # ICMP # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# iptables -A INPUT-external -p icmp -j INPUT-icmp-external iptables -A OUTPUT-external -p icmp -j OUTPUT-icmp-external #--------------------------------------------------------------# Drop fragmented ICMP packets #--------------------------------------------------------------iptables -A INPUT-icmp-external --fragment -j LOG-and-drop iptables -A OUTPUT-icmp-external --fragment -j LOG-and-drop #--------------------------------------------------------------# Allow outbound pings #--------------------------------------------------------------iptables -A OUTPUT-icmp-external -p icmp --icmp-type echo-request \ -m state --state NEW -j ACCEPT iptables -A INPUT-icmp-external -p icmp --icmp-type echo-reply -j ACCEPT #--------------------------------------------------------------# Allow inbound pings from the NOC #--------------------------------------------------------------iptables -A INPUT-icmp-external -p icmp -s $NOC_SUBNET \ --icmp-type echo-request -m state --state NEW \ -j ACCEPT iptables -A OUTPUT-icmp-external -p icmp --icmp-type echo-reply \ -d $NOC_SUBNET -j ACCEPT #--------------------------------------------------------------# Accept the following ICMP Messages # # .Time exceeded # .Appendix II : Codes.Destination unreachable .Fragmentation needed # .Source quench # .Parameter problem # .

RELATED -j ACCEPT iptables -A established-connection -m state --state INVALID \ -j LOG-and-drop #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # OS supplied protection # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# #--------------------------------------------------------------- .linuxhomenetworking.com #--------------------------------------------------------------iptables -A unreachable iptables -A ACCEPT iptables -A ACCEPT iptables -A ACCEPT iptables -A ACCEPT iptables -A -j ACCEPT iptables -A ACCEPT INPUT-icmp-external -p icmp --icmp-type destination-j ACCEPT INPUT-icmp-external -p icmp --icmp-type parameter-problem -j INPUT-icmp-external -p icmp --icmp-type time-exceeded -j INPUT-icmp-external -p icmp --icmp-type source-quench -j OUTPUT-icmp-external -p icmp --icmp-type source-quench -j OUTPUT-icmp-external -p icmp --icmp-type fragmentation-needed OUTPUT-icmp-external -p icmp --icmp-type parameter-problem -j #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # Log and drop chain # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# iptables -A LOG-and-drop -j LOG --log-ip-options --log-tcp-options \ --log-level debug iptables -A LOG-and-drop -j DROP #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# # # Already ESTABLISHED connections accepted # #=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=#=# iptables -A established-connection -m state \ --state ESTABLISHED.316 www.

Respond to queries out # the same interface. not another.Appendix II : Codes. Helps to maintain state # Also protects against IP spoofing #--------------------------------------------------------------echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter #--------------------------------------------------------------# Enable logging of packets with malformed IP addresses #--------------------------------------------------------------echo 1 > /proc/sys/net/ipv4/conf/all/log_martians #--------------------------------------------------------------# Disable redirects #--------------------------------------------------------------echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects #--------------------------------------------------------------# Disable source routed packets #--------------------------------------------------------------echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route #--------------------------------------------------------------# Disable acceptance of ICMP redirects #--------------------------------------------------------------echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects #--------------------------------------------------------------# Turn on protection from Denial of Service (DOS) attacks #--------------------------------------------------------------echo 1 > /proc/sys/net/ipv4/tcp_syncookies #--------------------------------------------------------------# Disable responding to ping broadcasts #--------------------------------------------------------------echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts . Scripts and Configurations 317 # Disable routing triangulation.

318 www.com exit 0 .linuxhomenetworking.

. . seconds 3600 .com. The full zone file . . refresh. Primary Mail Exchanger A A CNAME 127.1 97.com. serial.my-site.com. todays date + todays serial # 3600 . $TTL 3D @ IN SOA www. seconds 3600 .0. Inet Address of name server . expire.Appendix II : Codes. minimum. NS www .26 www DNS Zone File For my-other-site. . ( 200211151 .my-othersite. seconds . localhost www mail MX 10 mail . seconds 3600 . NS www . retry.com . seconds 3600 . seconds 3600 ) . Scripts and Configurations 319 DNS Zone File For my-site. .com. hostmaster.253. hostmaster. minimum. expire. retry.my-other-site. serial.com . Zone file for my-other-site.com .my-site. The full zone file . Zone file for my-site. $TTL 3D @ IN SOA www. seconds . refresh.com. ( 200211152 . Inet Address of name server my-site. todays date + todays serial # 3600 . seconds 3600 ) . .com .158.0.

com in which we can also access bigboy as bigboy.1 bigboy A 192. Zone file for my-site-internal. hostmaster.com.1. seconds 3600 . The full zone file .0.168.168.my-site. As server bigboy is also a mail and web server we have also added CNAMEs so that you can access 192. localhost A 127. . seconds . localhost www MX 10 mail.1.com .com.my-site-internal. expire. serial# 3600 .100.com. you could access it as mail. .my-site-internal.0.100 by one of two aliases depending on the role you wish it to play.168. retry.com my-other-site.linuxhomenetworking. For mail. There is also an entry for one of the home PCs named smallfry which you can now additionally access as smallfry.100 smallfry A 192.1 97. . NS www . .168. .320 www.26 Forward Zone File For A Home Network Using NAT Here is an example for a zone file for my-site-internal.com which maps to 192.158. Primary Mail Exchanger A A 127.my-site-internal.com and for web applications you could access it as www.my-site-internal. .1.168. refresh.1 www mail CNAME CNAME bigboy bigboy Reverse Zone File For A Home Network Using NAT . minimum. .com. Inet Address of name server .com.253. seconds 3600 . $TTL 3D @ IN SOA www.my-site-internal. ( 200211152 .102 firewall A 192.0.com.0. seconds 3600 ) .my-siteinternal.1.1.

hostmaster. Scripts and Configurations 321 You can also create a reverse zone file for the home network on the 192. refresh.x .1.my-site-internal. $TTL 3D @ IN SOA www. ( 200210023 .com. seconds 2H . seconds 4W . retry. Zone file for 192. minimum.X network using the same principles you used for a public network.168. . 100 102 1 PTR PTR PTR bigboy. NS www .my-site-internal. expire. Inet Address . firewall. smallfry. .168.com.com.com.com. Now you’ll get correct responses for both forward and reverse lookups using the host or nslookup commands. serial number 8H .1. seconds . . seconds 1D ) .my-site-internal.Appendix II : Codes.my-site-internal.my-site-internal.

com Sendmail Sample /etc/mail/access File # Check the /usr/share/doc/sendmail/README.0. mailer-daemon: postmaster postmaster: root # General redirections for pseudo accounts.0. # Basic system aliases -.. but WILL be visible over networks or from /bin/mail. bin: root daemon: root adm: root lp: root sync: root shutdown: root halt: root . # # by default we allow relaying from localhost.cf is part of the sendmail-doc # package.these MUST be present. (search for access_db in that file) # The /usr/share/doc/sendmail/README.linuxhomenetworking.localdomain RELAY localhost RELAY 127.168 RELAY Sendmail Sample /etc/aliases File # # # # # # # # # # @(#)aliases 8.1 RELAY # # Relay messages from the local subnet 192.2 (Berkeley) 3/5/94 Aliases in this file will NOT be expanded in the header from Mail.cf file for a description # of the format of this file. localhost. >>>>>>>>>> >> NOTE >> >>>>>>>>>> The program "newaliases" must be run after this file is updated for any changes to show through to sendmail.322 www..

com Sendmail Sample /etc/mail/local-host-names File # local-host-names . Scripts and Configurations 323 mail: news: uucp: operator: games: gopher: ftp: nobody: apache: named: xfs: gdm: mailnull: postgres: squid: rpcuser: root rpc: ingres: system: toor: manager: root dumper: abuse: newsadm: news newsadmin: usenet: ftpadm: ftpadmin: ftp-adm: ftp ftp-admin: root root root root root root root root root root root root root root root root root root root root root news news ftp ftp ftp # trap decode to catch security attacks decode: root # Person who should get root's mail root: t689ndtw@my-site.Appendix II : Codes.my-site.com .com www.my-site.include all aliases for your machine here.com mail. # my-site.

provider') define(`confDEF_USER_ID'. `/etc/aliases')dnl dnl define(`STATUS_FILE'. `A')dnl dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl dnl define(`confAUTH_MECHANISMS'. `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl dnl define(`confCACERT_PATH'. `/etc/mail/userdb.cf dnl include(`/usr/share/sendmail-cf/m4/cf.`/usr/share/ssl/certs/ca-bundle.pem') dnl define(`confSERVER_KEY'.true)dnl define(`confDONT_PROBE_INTERFACES'.com # my-other-site.my-other-site.your.true)dnl define(`PROCMAIL_MAILER_PATH'. `2000000')dnl define(`confUSERDB_SPEC'.restrictqrun')dnl define(`confAUTH_OPTIONS'.cf by running the following command: dnl dnl m4 /etc/mail/sendmail. If you make changes to this file.`smtp.``8:12'')dnl undefine(`UUCP_RELAY')dnl undefine(`BITNET_RELAY')dnl dnl define(`confAUTO_REBUILD')dnl define(`confTO_CONNECT'. `/etc/mail/statistics')dnl define(`UUCP_MAILER_MAX'.novrfy.linuxhomenetworking.db')dnl define(`confPRIVACY_FLAGS'.com ns.crt') dnl define(`confSERVER_CERT'.com ns.com www.com Sendmail Sample /etc/mail/sendmail.`/usr/share/ssl/certs/sendmail.mc File divert(-1) dnl This is the sendmail macro config file. `authwarnings.noexpn.m4') VERSIONID(`linux setup for Red Hat Linux')dnl OSTYPE(`linux') dnl dnl Uncomment and edit the following line if your mail needs to be sent out dnl through an external mail server: dnl dnl define(`SMART_HOST'.pem') .my-site. dnl you need the sendmail-cf rpm installed and then have to generate a dnl new /etc/mail/sendmail.my-other-site.`/usr/share/ssl/certs/sendmail.my-other-site.`/usr/share/ssl/certs') dnl define(`confCACERT'.com mail.`/usr/bin/procmail')dnl define(`ALIAS_FILE'. `1m')dnl define(`confTRY_NULL_MX_LIST'.324 www.mc > /etc/mail/sendmail.

Addr=127. However.1 dnl and not on any other network devices.0. Family=inet6') dnl We strongly recommend to comment this one out if you want to protect dnl yourself from spam.`hash -T<TMPF> -o /etc/mail/access.db')dnl FEATURE(`virtusertable'. dnl DAEMON_OPTIONS(`Port=smtp. Comment this out if you want dnl to accept email over the network.`hash -o /etc/mail/mailertable. dnl FEATURE(`accept_unresolvable_domains')dnl dnl FEATURE(`relay_based_on_MX')dnl .`procmail -t -Y -a $h -d $u')dnl FEATURE(`access_db'.`/usr/sbin/smrsh')dnl FEATURE(`mailertable'.Appendix II : Codes.db')dnl FEATURE(`blacklist_recipients')dnl dnl dnl dnl ***** Customised section 1 start ***** dnl dnl FEATURE(always_add_domain)dnl FEATURE(`masquerade_entire_domain')dnl FEATURE(`masquerade_envelope')dnl FEATURE(`allmasquerade')dnl FEATURE(delay_checks)dnl dnl FEATURE(genericstable. `5d')dnl dnl define(`confQUEUE_LA'.`dnl')dnl FEATURE(`smrsh'. Scripts and Configurations 325 dnl define(`confTO_QUEUEWARN'. `18')dnl define(`confTO_IDENT'. `4h')dnl dnl define(`confTO_QUEUERETURN'. `0')dnl dnl FEATURE(delay_checks)dnl FEATURE(`no_default_msa'. FEATURE(local_procmail. `hash -o /etc/mail/genericstable')dnl dnl GENERICS_DOMAIN_FILE(`/etc/mail/genericstable')dnl dnl dnl dnl ***** Customised section 1 end ***** dnl dnl dnl EXPOSED_USER(`root')dnl dnl This changes sendmail to only listen on the loopback device 127. the user runs over his quota. Name=MTA') dnl NOTE: binding both IPv4 and IPv6 daemon to the same port requires dnl a kernel patch dnl DAEMON_OPTIONS(`port=smtp.g. Name=MTA-v6.db')dnl FEATURE(redirect)dnl FEATURE(always_add_domain)dnl FEATURE(use_cw_file)dnl FEATURE(use_ct_file)dnl dnl The '-t' option will retry delivery if e.1.0.`'. `12')dnl dnl define(`confREFUSE_LA'. the laptop and users on computers that do dnl not have 24x7 DNS do need this.0.0.`hash -o /etc/mail/virtusertable.Addr=::1.

com)dnl (for local machine) dnl dnl dnl ***** Customised section 2 end ***** dnl dnl Sendmail Sample /etc/mail/virtusertable File @my-other-site.com t689ndtw@my-site.localdomain dnl dnl dnl ***** Customised section 2 start ***** dnl dnl define(`confPRIVACY_FLAGS'.16384)dnl dnl MASQUERADE_AS(`my-site.com MAILER(smtp)dnl MAILER(procmail)dnl dnl Cwlocalhost.`goaway')dnl .')dnl (for local machine) MASQUERADE_DOMAIN(`my-site.com.Limits command usage define(`confSMTP_LOGIN_MSG'.326 www.com.com error:nouser User unknown error:nouser User unknown paul paul paul .com @my-site.')dnl (for everyone else) MASQUERADE_AS(my-site.com paul@my-site.Changes login message define(`confMAX_HEADERS_LENGTH'. `$j server ready at $b')dnl .linuxhomenetworking.com paul@my-other-site.

. indicating the host is not available at this time Protocol Unreachable The protocol defined in IP header cannot be forwarded. Reply contains IP address of best router to destination. Name ICMP sender (router) has been configured to block access to the desired destination host. Redirect Datagram for the Host ICMP sender (router) is not the best way to get to the desired host. Dynamically adds a host entry in original sender's route tables. The sender is using a Type of Service (TOS) that is not available through this router for that specific network. Source Host Isolated Communication with Destination Network is Administratively Prohibited Communication with Destination Host is Administratively Prohibited Destination Network Unreachable for Type of Service Destination Host Unreachable for Type of Service Communication Administratively Prohibited Host Precedence Violation 5 ICMP sender (router) has been configured to not forward packets from source (the old electronic pink slip). Redirect Codes Redirect Datagram for the Network ICMP sender (router) is not the best way to get to the (or subnet) desired network.Appendix II : Codes. Reply contains IP address of best router to destination. indicating this network may never have been an available. Perhaps the network is too far away through the known route. Precedence value defined in sender's original IP header is not allowed (for example. Destination Network Unknown ICMP sender does not have a route entry for the destination network. Scripts and Configurations 327 ICMP Codes Type 3 Description Destination Unreachable Codes Net Unreachable The sending device knows about the network but believes it is not available at this time. Destination Host Unknown ICMP sender does not have a host entry. Dynamically adds a network entry in original sender's routing tables. ICMP sender (router) has been configured to block access to the desired destination network. Port Unreachable The sending device does not support the port number you are trying to reach Fragmentation Needed and Don't The router needs to fragment the packet to forward it across Fragment was Set a link that supports a smaller maximum transmission unit (MTU ) size. Source Route Failed ICMP sender can't use the strict or loose source routing path specified in the original packet. However. Host Unreachable The sending devices knows about host but doesn't get ARP reply. application set the Don't Fragment bit. ICMP sender is not available for communications at this time. indicating the host may never have been available on connected network. using Flash Override precedence). The sender is using a Type of Service (TOS) that is not available through this router for that specific host.

Redirect Datagram for the Type of ICMP sender (router) does not offer a path to the Service and Host destination host using the TOS requested.com Type 6 11 12 Name Description Redirect Datagram for Type of the ICMP sender (router) does not offer a path to the Service and Network destination network using the TOS requested.328 www. Dynamically adds a host entry in original sender's route tables. . Parameter Problem Codes Pointer indicates the error Error is defined in greater detail within the ICMP packet. Should redirect application to another host. Missing a Required Option ICMP sender expected some additional information in the Option field of the original packet. Dynamically adds a network entry in original sender's route tables. Time Exceeded Codes Time to Live exceeded in Transit ICMP sender (router) indicates that originator's packet arrived with a Time To Live (TTL) of 1. Bad Length Original packet structure had an invalid length. Alternate Host Address Codes Alternate Address for Host Reply that indicates another host address should be used for the desired service.linuxhomenetworking. Fragment Reassembly Time ICMP sender (destination host) did not receive all fragment Exceeded parts before the expiration (in seconds of holding time) of the TTL value of the first fragment received. Routers cannot decrement the TTL value to 0 and forward the packet.

1. ! Substitute your DSL username for "myusername" and your ! password for "*********" ! vpdn group ISP request dialout pppoe vpdn group ISP localname myusername vpdn group ISP ppp authentication pap vpdn username myusername password ********* ! ! Set up the outside.0 0 0 ! ! Port forwarding setup.1. Forward all www traffic to 192.168.0 0.0.DHCP DSL Configuration ! ! NAT Setup ! global (outside) 1 interface nat (inside) 1 0.255.100 ! (Linux webserver) ! static (inside. Cisco suggests you remove it when troubleshooting ! getting your IP address.0. Internet interface to use the PPPOE protocol ! to get it's IP address and default route.1.100 snmp-server community password ! ! DSL setup using a generic group called "ISP".100.168.1. Scripts and Configurations 329 Cisco PIX Firewall .0. or else you'll ! never get your default route back ! ip address outside pppoe setroute .outside) tcp interface www 192. Don't forget to put it back.100 www netmask 255.255 0 0 ! ! Apply an access list entry to allow www (TCP Port 80)traffic in ! access-group inbound in interface outside access-list inbound permit tcp any any eq www ! ! Enable SNMP queries from 192.Appendix II : Codes.168.255. Substitute "password" ! with the real SNMP string (Optional) ! snmp-server host inside 192. The set route command ! is very important.0.168.

1.2(2) nameif ethernet0 outside security0 nameif ethernet1 inside security100 enable password sde0sdD0sGz09COjx encrypted passwd sde0sdD0sGz09COjx encrypted hostname aquapix domain-name stcla1.253.158.linuxhomenetworking.26 access-list inbound permit tcp any host 97.com fixup protocol ftp 21 fixup protocol http 80 fixup protocol h323 h225 1720 fixup protocol h323 ras 1718-1719 fixup protocol ils 389 fixup protocol rsh 514 fixup protocol rtsp 554 fixup protocol smtp 25 fixup protocol sqlnet 1521 fixup protocol sip 5060 fixup protocol skinny 2000 names access-list inbound permit icmp any any access-list inbound permit tcp any host 97.253.253.168.158.601 UTC Sat Nov 23 PIX Version 6.158.100 interface ethernet0 10baset interface ethernet1 10full icmp deny any outside 2002 eq eq eq eq eq www 222 domain domain smtp .255.255.1 255.home.158.com ip address inside 192.26 pager lines 25 logging on logging timestamp logging trap warnings logging history warnings logging facility 22 logging host inside 192.253.Static DSL Configuration : Saved : Written by enable_15 at 22:33:57.158.253.26 access-list inbound permit tcp any host 97.26 access-list inbound permit udp any host 97.1.26 access-list inbound permit tcp any host 97.168.330 www.0 ! ! Setup DHCP autoconfiguration for the outside interface ! dhcpd auto_config outside Cisco PIX Firewall .sfba.

253.1.255.27 192.255.0 255.158.28 192.168.0.0 ip audit info action alarm ip audit attack action alarm pdm logging informational 100 pdm history enable arp timeout 14400 global (outside) 1 interface nat (inside) 1 192.0.110 1 timeout xlate 0:05:00 timeout conn 1:00:00 half-closed 0:10:00 udp 0:02:00 rpc 0:10:00 h323 0:05:00 sip 0:30:00 sip_media 0:02:00 timeout uauth 0:05:00 absolute aaa-server TACACS+ protocol tacacs+ aaa-server RADIUS protocol radius aaa-server LOCAL protocol local filter java 80 0.168.0 0.221.0.1.0 0.0.0 0.255.0.255.0.0.1.168.255.96 255.168.255.1 255.255 0 0 static (inside.0.outside) 97.0 67.168.0.168.168.1.168.0 0.255.158.0 inside snmp-server host inside 192.158.100 /aquapix-confg floodguard enable no sysopt route dnat telnet 192.1.0.1.1.255.0.253.158.0.253.255.0.0 0.0 0.0 255.100 source inside http server enable http 192.0.168.99 netmask 255.255 0 0 static (inside.100 no snmp-server location no snmp-server contact snmp-server community simiya2002 snmp-server enable traps tftp-server inside 192.253.255.255.0 filter activex 80 0.1.0.1.30 inside dhcpd lease 3600 dhcpd ping_timeout 750 dhcpd auto_config outside terminal width 80 Cryptochecksum:3af43873d35d6f0651f8c999180c2342 .255.1.248 ip address inside 192.1.255. Scripts and Configurations 331 mtu outside 1500 mtu inside 1500 ip address outside 97.168.25 255.0 ntp server 192.0.168.168.168.255.0.100 netmask 255.0 inside telnet timeout 15 ssh 192.0 255.0.101 netmask 255.255.255.255.255.0 inside ssh timeout 15 dhcpd address 192.outside) 97.20-192.255 0 0 access-group inbound in interface outside route outside 0.0.26 192.1.120.0.1.248 0 0 static (inside.outside) 97.0 0.Appendix II : Codes.

com : end .linuxhomenetworking.332 www.

www.333 Appendix III Bibliography =========================================== In This Chapter Appendix III Bibliography Wireless Linux Cisco Router Configuration Examples Cisco PIX Firewall Configuration Examples Netfilter .linuxhomenetworking.iptables Configuration General Home Networking Resource Pages SSH Servers and SSH Clients The Windows SCP client called WinSCP FTP Server and FTP Clients DHCP Server Apache Web Server Software Sendmail Mail Configuration Dynamic DNS .Hosting Your Website at Home Static DNS NTP Server POP Mail Server Samba .com =========================================== An informal listing of some of the sites I visited to create this manual.Linux as a Windows File Server General Linux Resource Pages Disk Partitioning Network Monitoring My Other Sites © Peter Harrison. .

html http://www.unixguru.com Wireless Linux A good reference page (Has GUI screens for PCMCIA type cards) • • • • • http://www.html Configuring Cisco 800 series routers Configuring 1700 / 2600 / 3600 series routers Cisco .com/personal/Jean_Tourrilhes/Linux/ http://www.net/LinuxG3/ls-wlan.shtml http://linuxdoc.com/en/US/products/sw/iosswrel/ps1835/products_configuration_guide_chapt er09186a00800ca7b1.com/en/US/products/hw/routers/ps380/prod_configuration_examples_list.us The LDP Wireless LAN Resources for Linux The drivers are here.org/HOWTO/Wireless-HOWTO http://www.raleigh.com http://www.html http://www.cisco.cisco.cisco.linuxhomenetworking.linux-wlan. RPM versions of the drivers can be found here Cisco Router Configuration Examples Cisco Systems • • • • http://www.cisco.hp..334 www.htm Configuring Cisco PIX firewalls for DHCP .html http://www..com/en/US/products/sw/iosswrel/ps1835/products_configuration_guide_chapt er09186a00800ca7b1.nc.Configuring IOS IPSec Network Security • Cisco PIX Firewall Configuration Examples Cisco Systems • • http://www.Configuring IPSec Network Security Cisco .org/ http://prism2.hpl.com/univercd/cc/td/doc/product/iaabu/pix/pix_62/config/pixclnt.cisco.com/en/US/products/hw/routers/ps221/prod_configuration_examples_list.com http://www.cisco.saragossa.cisco.

Configuring PIX IPSec Network Security • Cisco PIX error messages • • Configuring Cisco PIX logging parameters Netfilter .cisco.vandyke.ht ml http://www.com/univercd/cc/td/doc/product/iaabu/pix/pix_sw/v_62/syslog/index.org/assignments/port-numbers ICMP codes listing TCP and UDP port assignments SSH Servers and SSH Clients PuTTY homepage (Free) • • http://www.iptables Configuration Netfilter iptables HOWTO tutorial site • http://www.html http://www.tldp.cisco.htm http://www.org.org/HOWTO/Networking-Overview-HOWTO.com/ SecureCRT homepage (Purchase Required) .cisco.cisco.tldp.Appendix III : Bibliography 335 Cisco PIX 500 series configuration guides • http://www.html General Home Networking Resource Pages Linux networking HOWTO • • • • • http://www.htm#xtocid15 Cisco .org/HOWTO/Net-HOWTO/ http://www.iana.greenend.cisco.nwconnection.html Linux Networking-HOWTO http://www.Configuring IPSec Network Security • Cisco .99/icmp09/code.org/documentation/tutorials/blueflux/iptables-tutorial.html#xtocid3 http://www.com/oct.netfilter.com/en/US/products/sw/secursw/ps2120/products_configuration_guide_chapt er09186a00800eb72a.com/en/US/products/sw/iosswrel/ps1835/products_configuration_guide_chapt er09186a00800ca7b1.com/en/US/products/hw/vpndevc/ps2030/prod_configuration_examples_list.uk/~sgtatham/putty/ http://www.chiark.com/univercd/cc/td/doc/product/iaabu/pix/pix_62/cmdref/gl.html http://www.

com The Windows SCP client called WinSCP • http://winscp.cz/eng/ FTP Server and FTP Clients A good site on how to install one of the many Windows GUI FTP clients • • Zen and the Art of FTP: An FTP Tutorial http://www.htm Perl Script to do Automatic FTP File Copies to Update Your Website DHCP Server RedHat's guide to configuring DHCP • http://www.linuxhomenetworking.html Good page on how to stop SPAM with sendmail .html http://www.brettglass.unixreview.com/2000-04/networknirvana_05.html Linux Magazine's detailed guide • Apache Web Server Software Apache's documents on setting up virtual hosts • • http://httpd.0-Manual/custom-guide/s1-dhcp-configuringserver.html http://www.apache.com/features/vhost Apache week's description of how to do virtual hosting Sendmail Mail Configuration Good sendmail quick setup guide • • http://www.neilgunton.redhat.com/network_howto/part3/ http://www.com/spam/paper.336 www.com/docs/manuals/linux/RHL-8.org/docs/vhosts/examples.com/documents/s=2426/uni1018361705067/0204e.apacheweek.linux-mag.vse.

net http://www.0-Manual/ref-guide/s1-email-sendmail.html All you ever need to know about setting up DNS for a home / SOHO environment NTP Server NTP Configurations • http://www.net .technopagan.redhat.org http://gusnet.eecis.com/permanentEmailAddress.html http://www. MiniDNS.DDNS Provider dynDNS.tldp. Mirrored here.org/dynamic/ http://www.edu/~mills/ntp/servers.minidns.org/HOWTO/DNS-HOWTO.html Masquerading explanations Explanation on the difference between email headers and envelopes RedHat's recommendations for configuring sendmail Dynamic DNS .html .com/docs/manuals/linux/RHL-8.Appendix III : Bibliography 337 Some more was found here • • • • http://www.sendmail.cx/proj/ez-ipupdate/ See the README for more information.html http://www.org/dynamic/ http://www.org .org/m4/features.udel.com/handbook/sendmail.primemail.dyndns.hml http://www.Hosting Your Website at Home What is Dynamic DNS (DDNS)? • • • • • http://www.technopagan.DDNS Provider Ez-ipupdate DDNS Update Script DDclient DDNS Update Script Static DNS What is DNS? • • http://www.freebsdsystems.

html http://us6.linuxpowered.org/docs/connect/csamba6.samba.de/howtos/html/NET-3-HOWTO.3-xml/imapop.html http://playstation2-linux.html http://www.washington.in/pipermail/plug-mail/2002-June/004274.rosko.338 www.com/library/weekly/aa102500c.uoregon.html The Unoffical Samba HOWTO.org http://hr.com POP Mail Server From the creators of the default Redhat POP server • • http://www.html Automount HOWTO with FAQs • • http://home.html http://unix.html http://plug.org. by David Lechnyr Simple Windows Workgroup Networking Tutorial SAMBA organization's description of creating a PDC Mandrake's resource page on Samba PDCs Sharing a Windows hard drive from a Linux box (Windows steps to do this) Sharing a Windows hard drive from a Linux box (Linux steps to do this) General Linux Resource Pages Text Terminal HOWTO • http://www.org/samba/ftp/docs/htmldocs/Samba-PDC-HOWTO.edu/davidrl/samba.uni-bayreuth.edu/imap/ http://www.azstarnet.html http://www.com/community/articles/security/v1.htm A very comprehensive guide to sudo .samba.about.net/rosko/howto/en/mini/Automount.linux.html POP server compilation and configuration details Samba .com/download/cfyc/HOWTO_setup_samba.com/archive/howto/Text-Terminal-HOWTO.openna.mandrakeuser.Linux as a Windows File Server The Samba Project • • • • • • • http://www.com/~jemorrow/samba/implementation.html#toc14 Complete Linux Networking HOWTO http://www.linuxhomenetworking.

Appendix III : Bibliography 339 Disk Partitioning • http://www.html Network Monitoring The MRTG homepage • http://www.mrtg.org.au/tips/disk-partitioning.Caribbean Art and Photos • Simiya .org My Other Sites Simiya .linuxsa.

Sign up to vote on this title
UsefulNot useful