L220: Advanced Linux System Administration II

Transcription

L220: Advanced LinuxSystem Administration IIcourse materialsoriginally released under the GFDL by LinuxITmodified and released under the GFDL by University of Zagreb University Computing Centre SRCE(“the publisher”)

University of Zagreb University Computing Centre SRCECopyright (c) 2005 LinuxIT.Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2or any later version published by the Free Software Foundation;with the Invariant Sections being History, Acknowledgements, with theFront-Cover Texts being “released under the GFDL by LinuxIT”.Copyright (c) 2014 SRCE.Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2or any later version published by the Free Software Foundation;with the Invariant Sections being History, Acknowledgements, with theFront-Cover Texts being “modified and released under the GFDLby University of Zagreb University Computing Centre SRCE”.see full GFDL license agreement on p. 133.2

University of Zagreb University Computing Centre SRCEAcknowledgmentsThe original material was made available by LinuxIT's technical training centre www.linuxit.com.The original manual is available online at he modified version of this manual is available at VS version 0.0 January 2004, Adrian Thomasset adrian@linuxit.com .Reviewed/Updated April 2004, Andrew Meredith andrew@anvil.org .Review/Update May 2005, Adrian Thomasset adriant@linuxit.com .February 2014. Title: L220: Advanced Linux System Administration II (version 1.0). Revised and modified atUniversity of Zagreb University Computing Centre SRCE (“the publisher”) by Vladimir Braus.NotationsCommands and filenames will appear in the text in bold.The symbols are used to indicate a non optional argument.The [] symbols are used to indicate an optional argumentCommands that can be typed directly in the shell are highlighted as belowcommandNo GuaranteeThe manual comes with no guarantee at all.3

University of Zagreb University Computing Centre SRCEUniversity Computing Centre SRCEAs the major national infrastructural ICT institution in the area ofresearch and higher education in Croatia, the UniversityComputing Centre SRCE is providing a modern, sustainableand reliable e-infrastructure for research and educationcommunity.This includes computing and cloud services, high performancecomputing, advanced networking, communication systems andservices, middleware, data and information systems andinfrastructure. At the same time SRCE acts as the computingand information centre of the largest Croatian university – the University of Zagreb, and is responsiblefor the coordination of the development and usage of e-infrastructure at the University.Furthermore, by applying cutting edge technologies SRCE continuously enriches academic andreserach e-infrastructure and its own service portfolio. This enables the active participation of Croatiaand Croatian scientists in European and global research and higher education area and projects.Since its founding in 1971 as a part of the University of Zagreb, at that time the only Croatian university,SRCE has provided an extended advisory and educational support to institutions and individuals fromthe academic and research community in the use of ICT for education and research purposes.From its beginnings, and still today, SRCE has been recognized as an important factor of thedevelopment of modern e-infrastructure at the national level, participating in different projects andproviding services like Croatian Intenet eXchange (CIX).SRCE has a 41 year old tradition of organizing professional courses from the field of ICT.University Computing Centre SRCEJosipa Marohnića 510000 ZagrebCroatiahttp://www.srce.unizg.hre-mail: ured@srce.hrphone: 385 1 6165 5554

University of Zagreb University Computing Centre SRCETable of ContentsTable of ContentsDNS . 71. Basic Bind Configuration . 71.1 The Logging Statement . 81.2 The Options Statement . 101.3 The Zone Statement . 111.4 The Access Control Lists (acl) Statement. 122. Create and Maintain Zone Files. 133. Securing a DNS Server . 153.1 Server Authentication . 153.2 DATA Integrity and Authenticity . 17MAIL AND LISTS . 191. Using Sendmail . 191.1 Configuration Settings . 191.2 Virtual Hosting. 212. Configuring Mailing Lists . 222.1 Majordomo and Sendmail . 223. Managing Mail Traffic . 243.1 Mail Filtering with Procmail. 24WEB SERVICES . 271. Implementing a Web Server . 271.1 Installing Apache. 271.2 Monitoring apache load . 271.3 Using Apachectl . 281.4 Basic Configuration Options . 291.5 Restricting Client Access . 311.6 Client Basic Authentication . 312. Maintaining a Web Server. 322.1 HTTPS Overview . 322.2 SSL Virtual Hosts . 332.3 Managing Certificates . 342.4 Virtual Hosts . 353. Implementing a Proxy Server . 373.1 Getting Started . 373.2 Access Lists and Access Control . 373.3 Additional Configuration Options . 393.4 Reporting Tools. 403.5 User Authentication (using PAM) . 425

University of Zagreb University Computing Centre SRCETable of ContentsNETWORK CLIENT MANAGEMENT . 441. DHCP Configuration . 441.1 Default DHCP Configurations. 441.2 Dynamic DNS . 461.3 DHCP Relay . 482. NIS Configuration . 492.1 Master Server Configuration . 492.2 Slave Server Configuration . 502.3 Client Setup . 502.4 Setting up NFS home directories. 512.5 Basic NIS Administration . 513. LDAP Configuration . 523.1 What is ldap . 523.2 OpenLDAP server configuration . 533.3 Client configuration files . 543.4 Migrating System Files to LDAP . 543.5 LDAP Authentication Scheme . 574. PAM Authentication . 594.1 PAM Aware Applications . 594.2 PAM Configuration . 60SYSTEM SECURITY . 611. Iptables/Ipchains . 611.1 The Chains . 611.2 The Tables . 621.3 The Targets . 621.4 Example Rules . 632. Differences with Ipchains . 643. Security Tools . 653.1 SSH . 653.2 LSOF . 673.3 NETSTAT . 683.4 TCPDUMP . 683.5 NMAP . 70GNU Free Documentation License . 726

University of Zagreb University Computing Centre SRCEDNSDNSNOTICEComputer name resolution can be performed in a number of ways, including /etc/hostsfile and DNS./etc/hosts file is a convenient way to manage name resolution for a small number ofcomputers, such as a small home network with just two or three machines. /etc/hostsmust be updated on every computer on a network whenever any machine’s name or IPaddress changes or whenever a computer is added to or removed from the network.In addition to /etc/hosts and DNS, several other name resolution systems exist, includingNetwork Information Service (NIS), Windows Internet Name Service (WINS), and more.1. Basic Bind ConfigurationThe configuration file for a Bind server is /etc/named.conf. This file has the following mainentries:Main entries in named.confloggingSpecify where logs are written too and what needs to be loggedoptionsGlobal options are set here (e.g the path to the zone files)zoneDefines a zone: the name, the zone file, the server typeaclAccess control listserverSpecific options for remote serversLet's look at a typical configuration file for a caching only server. We will add entries to it aswe go to create new zones, logging facilities, security, etc.7

University of Zagreb University Computing Centre SRCEDNSSkeleton named.conf fileoptions {directory "/var/named";datasize 100M;};zone "." IN {type hint;file "named.ca";};zone "localhost" IN {type master;file "localhost.zone";allow-update { none; };};zone "0.0.127.in-addr.arpa" IN {type master;file "named.local";allow-update { none; };};1.1 The Logging StatementThe syntax for logging is:logging {channel "channel name" {file "file name";versions number of files;size log size;syslog daemon auth syslog authpriv local0 -to- local7 null ;severity critical error warning notice info debug dynamic ;print-category yes or no;print-severity yes or no;print-time yes or no;};category "category name" {"channel name";};};The channel defines where logs are sent to (file, syslog or null). If syslog is selected thenthe facility and the log level can be specified too.8

University of Zagreb University Computing Centre SRCEDNSThe category clause defines the type of information sent to a given channel (or list ofchannels). The type of channel is given then the default logging facility is usedcategory default { default syslog; default debug; };Example:We choose not to use the syslog daemon and log everything to a file called “LOG” that willbe created in the same directory as the zone files (default /var/named/). For this we willcreate the channel foo channel. Next we want to log queries using this channel.The entry in named.conf will look like this:logging {channel foo channel {file "LOG";print-time yes;print-category yes;print-severity yes;};category "queries" {"foo channel";};};Categories such as queries are predefined and listed in the named.conf(5) manpages.However some of the names have changed since BIND 8, so we include as a referencethe list of categories for BIND 9 below:BIND 9 Logging CategoriesdefaultCategory used when no specific channels (log levels, files .) havebeen definedgeneralCatch all for messages that haven't been classified belowdatabaseMessages about the internal zone filessecurityApproval of requestsconfigProcessing of the configuration fileresolverInfornation about operations performed by clientsxfer-in or xfer-out Received or sent zone filesnotifyLog NOTIFY messagesclientClient activityupdateZone updatesqueriesClient QueriesdnssecDNSEC transactionslame-serversTransactions sent from servers marked as lame-servers9

University of Zagreb University Computing Centre SRCEDNS1.2 The Options StatementThe global options for the server are set at the beginning of named.conf. The syntax is:options{option1;option2;.};We next cover the most common options.versionManpage says “The version the servershould report via the ndc command. Thedefault is the real version number of thisserver, but some server operators preferthe string (surely you must be joking )”version " (surely you must bejoking) ";directoryThe working directory of the serverdirectory "/var/named";fetch-glue (default yes) - obsoletePrevent the server from resolving NS records (the additional data section). When a recordis not present in the cache BIND can determine which servers are authoritative for thenewly queried domain. This is often used in conjunction with recursion no.notify (default yes)Send DNS NOTIFY messages to the slave servers to notify zone changes (helps speedup convergence)recursion (default yes)The server will perform recursive queries when neededforward (only or first)The default value is first and causes the sever to query the forwarders before attemptingto answer a query itself. If the option is set to only the server will always ask theforwarders for an answer. This option has to be used with forwarders.10

University of Zagreb University Computing Centre SRCEDNSforwarders (list)List of servers to be used forforwarding. The default is an emptylist.datasizeLimit the size of the cacheforwarders { 10.0.0.1; 10.0.0.10;};datasize 512M;allow-query (list)A lists of hosts or networks that may query the serverallow-recursion (list)List of hosts that can submit recursive queriesallow-transfer (list)List of hosts (usually the slaves) who are allowed to do zone transfers1.3 The Zone StatementThe syntax for a zone entry in named.conf is as follows:zone domain name {type zone type;file zone file;local options;};We first look at the local options available. Some of these are the same options with thesame syntax as the global options we have just covered (with some additional ones). Themost common ones are notify, allow-transfer and allow-query. Additional ones aremasters (list of master servers) or dialup.The domain name is the name of the domain we want to keep records for. For eachdomain name there is usually an additional zone that controls the local in-addr.arpa zone.The zone type can either bemasterslavehintstubthe server has a master copy of the zone filethe server has a version of the zone file that was downloaded from amaster serverpredefined zone containing a list of root serverssimilar to a slave server but only keeps the NS records11

University of Zagreb University Computing Centre SRCEDNSThe zone file is a path to the file containing the zone records. If the path is not an absolutepath then the path is taken relatively to the directory given earlier by the directory option(usually /var/named).Example master zone entries, allowing zone transfers to a slave server at 10.1.2.3:zone seafront.bar {type master;file "seafront.zone";allow-transfer{10.1.2.3;);};zone 2.1.10.in-addr.arpa {type master;file "10.1.2.zone"allow-transfer{10.1.2.3;);};The next example is the corresponding named.conf zone section for the slave server,assuming the master has the IP 10.1.2.1:zone "seafront.bar" IN {type slave;masters {10.1.2.1;};file "slave/seafront.zone";};zone "2.1.10.in-addr.arpa" IN {type slave;masters {10.1.2.1;};file "slave/10.1.2.local";};1.4 The Access Control Lists (acl) StatementRather than use IPs it is possible to group lists of IP addresses or networks and assign aname to this grouping.Exmaple acl:acl internal net {10.0.0.0/8; };12

University of Zagreb University Computing Centre SRCEDNSThere are built-in ACLs as follow:anyall hostsnoneno hostlocalhostall IP address for the local interfaceslocalnetsnetwork associated to the localhost interfacesThe Server StatementThis statement is used to assign configuration options for a specific server. For example ifa server is giving bad information it can be marked as bogus. One can also set the keysassociated with a server for hosts authentication when using DNSSEC (see section 4.Securing a DNS Server)2. Create and Maintain Zone FilesThe format of the zone files is defined in RFC 1035 and contains resource records (RR) forthe administered domain or sub-domain.The types of resource records are:1 – Start Of Authority (SOA)root-name TTL IN SOA name-server email-address (serial number;refresh;retry;expire;minimum;)The SOA record includes the following details: the primary name server for the domain the responsible party for the domain a timestamp (serial number) that changes whenever you update your domain the number of seconds before the zone should be refreshed the number of seconds before a failed refresh should be retried the upper limit in seconds before a zone is considered no longer authoritative the negative result TTL (for example, how long a resolver should consider a negativeresult for a subdomain to be valid before retrying).13

University of Zagreb University Computing Centre SRCEDNSThe root-name is often replaced with an “@” symbol which resolves to the name of thezone specified in named.conf.Example: TTL@1D86400INSOAns.seafront.bar. root.seafront.bar. (46; serial (d. adams)1H; refresh15M; retry1W; expiry1D ); minimum2 – Records defining the name-servers for this domain, NS recordsdomain-name IN NS name-serverExample:INNSnsNOTICE1. If the name of the domain is missing then @ is assumed2. The fully qualified name of the name-server is ns.seafront.bar. A host name thatdoesn't end with a dot will automatically have the domain-name '@' appended to it.Here for examplens becomes ns.seafront.bar.3 – Records defining the mail-servers for this domain, MX recordsdomain-name IN MX PRI mail-serverThe PRI entry is a priority number. If several mail-servers are defined for a domain thenthe servers with the lowest priority number are used first.4 – Authoritative information for hosts on the domain, called A recordshost-name IN A IP-addressAuthority DelegationWhen defining the name-servers responsible for another sub-domain additional NSrecords are added as well as some glue records which are simple A records resolving theDNS servers.14

University of Zagreb University Computing Centre SRCEDNSExample:devel.myco.com.ns1IN NSIN Ans1.devel.myco.com192.168.21.254Reverse zone files5 – Authoritative PTR records, resolving IP addressesnIN PTRhost-name3. Securing a DNS ServerIn 1995, following major security flaws discovered in DNS, a new topic called DNSSECwas started within the IETF. This DNSSEC protocol is described in a sequence of threedraft documents known as RFC2535bis and proposes to handle server authentication aswell as data authenticity.3.1 Server AuthenticationDNSSEC attempts to handle vulnerabilities that occur during unauthorised dynamicupdates as well as spoofed master impersonations. These involve host-to-hostauthentications between either a DHCP or a slave server and the master server.The dnssec-keygen tool is used to generate a host key on the master server that canthen be transferred on a slave server. This authentication mechanism is call TSIG andstands for Transaction Signature. Another mechanism is SIG0 and is not covered in thesenotes.Master Configuration1. First generate the host key on the master server called seafront.bar:dnssec-keygen –a HMAC-MD5 -b 256 -n host seafront.bar.This will create the following public and a private key pair:Kseafront.bar. 157 49196.keyKseafront.bar. 157 49196.privateNotice:These keys must NOT be inserted in the zone files (there is an IN KEYsection in the public key that is misleading, looks like a RR).The public and the private keys are identical: this means that the private keycan be kept in any location. This also means that the public key shouldn't bepublished.15

University of Zagreb University Computing Centre SRCEDNSThe content of the Kseafront.bar. 157 49196.key is:seafront.bar. IN KEY 512 3 157 QN3vIApnV76WS a2Hr3qj AqZjpuPjQgVWeeMMGSBC4 2. In the same directory as the server's named.conf configuration file create the fileslave.key with the following content:key "seafront.bar." {algorithm hmac-md5;secret "QN3vIApnV76WS a2Hr3qj AqZjpuPjQgVWeeMMGSBC4 ";};3. Apply the following changes in named.conf:include "/etc/slave.key";zone "seafront.bar" IN {type master;file "seafront.zone";allow-transfer { key seafront.bar.; };};zone 2.1.10.in-addr.arpa {type master;file "10.1.2.zone"allow-transfer { key seafront.bar.; );};Slave ConfigurationCopy the slave.key file to the slave server in the directory containing named.conf. Addthe following server and include statements to named.conf:server 10.1.2.1 {keys {seafront.bar.;};};(this is the IP for the master server)include "/etc/slave.key";TroubleshootingRestart named on both servers and monitor the logs. Notice that DNSSEC is sensitive totime stamps so you will need to synchronise the servers (using NTP). Then run thefollowing command on the master server in the same directory where the dnssec keys16

University of Zagreb University Computing Centre SRCEDNSwhere generated:dig @10.1.2.1 seafront.bar AXFR -k Kseafront.bar. 157 49196.key3.2 DATA Integrity and AuthenticityThis aspect of DNSSEC is above the level of this manual and is simply a summary of theconcepts involved.Data authenticity may be compromised at different levels.The recognised areas are: altered slave zone files cache impersonation cache poisoning.New RR recordsThe integrity and authenticity of data is guaranteed by signing the Resource Records usinga private key. These signatures can be verified using a public DNSKEY. Only the validityof the DNSKEY needs to be established by the parent server or “delegation signer” DS.So we have the following new RRs in the zone files:RRSIGDNSKEYDSthe signature of the RR setpublic key used to verify RRSIGsthe Delegation SignerSigning Zone RecordsThese are the basic steps:1. Create a pair of public/private zone signing keys (ZSK)dnssec-keygen -a DSA -b 1024 -n zoneYou should get two files such as these:Kseafront.bar. 003 31173.keyKseafront.bar. 003 31173.private17seafront.bar.

University of Zagreb University Computing Centre SRCEDNS2. Insert the public key into the unsigned zone file:catKseafront.bar. 003 31173.key seafront.bar3. Sign the zone filednssec-signzone-oseafront.barKseafront.bar. 003 31173You should see a message such as:WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNINGWARNINGWARNINGWARNINGWARNINGWARNING This version of dnssec-signzone produces zones that areWARNINGWARNING incompatible with the forth coming DS based DNSSECWARNINGWARNING standard.WARNINGWARNINGWARNINGWARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNINGseafront.zone.signedThis is due to the fact that the dnssec-signzone tool doesn't support the -k switch whichwould allow to make use of a key signing key (KSK) which is then forwarded to a parentzone to generate a DS record.If you want to make use of this signed zone, change the filename in named.conf to“seafront.bar.signed”18

University of Zagreb University Computing Centre SRCEMail and ListsMail and ListsA wide variety of SMTP servers can run on Linux. The most popular servers are:SendmailThis server has long dominated Internet mail delivery. sendmail has also earned areputation for a difficult-to-master configuration file format. Fortunately, tools to create aconfiguration file from a simpler file are common.PostfixThis server is comparable to sendmail in popularity. Postfix uses a series of smallprograms to handle mail delivery tasks, as opposed to the monolithic approach used bysendmail. Its configuration is much easier to handle than is sendmail’s.EximThis mail server is not quite as popular as sendmail or Postfix, but it is still a popular Linuxmail server. Like sendmail, Exim uses a monolithic design, but Exim’s configuration file ismuch more intelligible. This server includes extensive pattern - matching tools that arevery useful in fighting spam.1. Using SendmailSendmail is a general purpose internetwork email routing facility that supports many kindsof mail-transfer and delivery methods, including the Simple Mail Transfer Protocol(SMTP) used for email transport over the Internet.1.1 Configuration SettingsDNS Settings1. We first want to make sure that mail will be sent to our machine. We assume that wehave properly configured a domain called seafront.bar with BIND 8 or 9. Let's makesure that the zone file for this domain has an MX record pointing to our system.For example if our machine is called test1 and has the IP 192.168.246.12 thenwe need the following lines:seafront.bar.INMX .246.1219

University of Zagreb

February 2014. Title: L220: Advanced Linux System Administration II (version 1.0). Revised and modified at University of Zagreb University Computing Centre SRCE (“the publisher”) by Vladimir Braus. Notations Commands and filenames will appear in the text in bold. The &