4 Linux Network Configuration
Total Page:16
File Type:pdf, Size:1020Kb
Version 4.0 Linux Administration II Linux as a Network Client $ echo tux tux $ ls hallo.c hallo.o $ /bin/su - Password: tuxcademy – Linux and Open Source learning materials for everyone www.tuxcademy.org [email protected] ⋅ This training manual is designed to correspond to the objectives of the LPI-102 (LPIC-1, version 4.0) certification exam promulgated by the Linux Professional Institute. Further details are available in Appendix B. The Linux Professional Institute does not endorse specific exam preparation materials or tech- niques. For details, refer to [email protected]. The tuxcademy project aims to supply freely available high-quality training materials on Linux and Open Source topics – for self-study, school, higher and continuing education and professional training. Please visit http://www.tuxcademy.org/! Do contact us with questions or suggestions. Linux Administration II Linux as a Network Client Revision: adm2:0cd011e4d0e3d9e9:2015-08-21 adm2:0cd20ee1646f650c:2015-08-21 1–13, B adm2:D6IMdRN77OjUKOKAMJE2Cq © 2015 Linup Front GmbH Darmstadt, Germany © 2015 tuxcademy (Anselm Lingnau) Darmstadt, Germany http://www.tuxcademy.org [email protected] ⋅ Linux penguin “Tux” © Larry Ewing (CC-BY licence) All representations and information contained in this document have been com- piled to the best of our knowledge and carefully tested. However, mistakes cannot be ruled out completely. To the extent of applicable law, the authors and the tux- cademy project assume no responsibility or liability resulting in any way from the use of this material or parts of it or from any violation of the rights of third parties. Reproduction of trade marks, service marks and similar monikers in this docu- ment, even if not specially marked, does not imply the stipulation that these may be freely usable according to trade mark protection laws. All trade marks are used without a warranty of free usability and may be registered trade marks of third parties. This document is published under the “Creative Commons-BY-SA 4.0 Interna- tional” licence. You may copy and distribute it and make it publically available as long as the following conditions are met: Attribution You must make clear that this document is a product of the tux- cademy project. Share-Alike You may alter, remix, extend, or translate this document or modify or build on it in other ways, as long as you make your contributions available under the same licence as the original. Further information and the full legal license grant may be found at http://creativecommons.org/licenses/by-sa/4.0/ Authors: Anselm Lingnau, Tobias Elsner Technical Editor: Anselm Lingnau [email protected] ⟨ ⟩ English Translation: Anselm Lingnau Typeset in Palatino, Optima and DejaVu Sans Mono Contents 1 System Logging 13 1.1 The Problem . 14 1.2 The Syslog Daemon . 14 1.3 Log Files . 17 1.4 Kernel Logging . 18 1.5 Extended Possibilities: Rsyslog . 18 1.6 The “next generation”: Syslog-NG. 22 1.7 The logrotate Program . 26 2 System Logging with Systemd and “The Journal” 31 2.1 Fundamentals . 32 2.2 Systemd and journald . 33 2.3 Log Inspection . 35 3 TCP/IP Fundamentals 41 3.1 History and Introduction . 42 3.1.1 The History of the Internet . .$ . echo. tux. 42 3.1.2 Internet Administration . .tux. 42 3.2 Technology . .$ . ls. 44 3.2.1 Overview . .hallo.c. 44 3.2.2 Protocols . .hallo.o. 45 3.3 TCP/IP . .$ . /bin/su. .- . 47 3.3.1 Overview . .Password:. 47 3.3.2 End-to-End Communication: IP and ICMP . 48 3.3.3 The Base for Services: TCP and UDP . 51 3.3.4 The Most Important Application Protocols. 54 3.4 Addressing, Routing and Subnetting . 56 3.4.1 Basics . 56 3.4.2 Routing . 57 3.4.3 IP Network Classes . 58 3.4.4 Subnetting . 58 3.4.5 Private IP Addresses . 59 3.4.6 Masquerading and Port Forwarding . 60 3.5 IPv6. 61 3.5.1 IPv6 Addressing . 62 4 Linux Network Configuration 67 4.1 Network Interfaces . 68 4.1.1 Hardware and Drivers . 68 4.1.2 Configuring Network Adapters Using ifconfig . 69 4.1.3 Configuring Routing Using route . 70 4.1.4 Configuring Network Settings Using ip . 72 4.2 Persistent Network Configuration . 73 4.3 DHCP . 76 4.4 IPv6 Configuration . 77 4.5 Name Resolution and DNS . 78 4 Contents 5 Network Troubleshooting 83 5.1 Introduction. 84 5.2 Local Problems. 84 5.3 Checking Connectivity With ping . 84 5.4 Checking Routing Using traceroute And tracepath . 87 5.5 Checking Services With netstat And nmap . 90 5.6 Testing DNS With host And dig . 93 5.7 Other Useful Tools For Diagnosis . 95 5.7.1 telnet and netcat . 95 5.7.2 tcpdump . 97 5.7.3 wireshark . 97 6 inetd and xinetd 99 6.1 Offering Network Services with inetd . 100 6.1.1 Overview . 100 6.1.2 inetd Configuration . 100 6.2 The TCP Wrapper—tcpd . 101 6.3 xinetd . 104 6.3.1 Overview . 104 6.3.2 xinetd Configuration . 104 6.3.3 Launching xinetd . 105 6.3.4 Parallel Processing of Requests . 106 6.3.5 Replacing inetd by xinetd . 106 7 Network services with systemd 109 7.1 Introductory Remarks . 110 7.2 Persistent Network Services . 110 7.3 Socket Activation . 112 8 System Time 117 8.1 Introduction. 118 8.2 Clocks and Time on Linux. 118 8.3 Time Synchronisation with NTP . 120 9 Printing on Linux 127 9.1 Overview. 128 9.2 Commands for Printing . 129 9.3 CUPS Configuration . 133 9.3.1 Basics . 133 9.3.2 Installing and Configuring a CUPS Server . 135 9.3.3 Miscellaneous Hints . 139 10 The Secure Shell 141 10.1 Introduction. 142 10.2 Logging Into Remote Hosts Using ssh . 142 10.3 Other Useful Applications: scp and sftp . 145 10.4 Public-Key Client Authentication . 146 10.5 Port Forwarding Using SSH . 148 10.5.1 X11 Forwarding . 148 10.5.2 Forwarding Arbitrary TCP Ports . 149 11 Electronic Mail 153 11.1 Fundamentals . 154 11.2 MTAs for Linux . 154 11.3 Basic Functionality . 155 11.4 Managing The Mail Queue . 156 11.5 Local Delivery, Aliases And User-Specific Forwarding . 156 5 12 Introduction to GnuPG 159 12.1 Asymmetric Cryptography and the “Web of Trust” . 160 12.2 Generating and Managing GnuPG Keys. 163 12.2.1 Generating Key Pairs . 163 12.2.2 Publishing a Public Key . 165 12.2.3 Importing and Signing Public Keys . 166 12.3 Encrypting and Decrypting Data . 169 12.4 Signing Files and Verifying Signatures . 171 12.5 GnuPG Configuration . 173 13 Linux and Security: An Introduction 175 13.1 Introduction. 176 13.2 File System Security . 176 13.3 Users and Files . 179 13.4 Resource Limits . 182 13.5 Administrator Privileges With sudo. 186 13.6 Basic Networking Security . 190 A Sample Solutions 193 B LPIC-1 Certification 203 B.1 Overview. 203 B.2 Exam LPI-102 . 203 B.3 LPI Objectives In This Manual . 204 C Command Index 211 Index 213 List of Tables 1.1 syslogd facilities . 15 1.2 syslogd priorities (with ascending urgency) . 15 1.3 Filtering functions for Syslog-NG . 24 3.1 Common application protocols based on TCP/IP . 55 3.2 Addressing example . 57 3.3 Traditional IP Network Classes . 58 3.4 Subnetting Example . 59 3.5 Private IP address ranges according to RFC 1918 . 59 4.1 Options within /etc/resolv.conf ..................... 79 5.1 Important ping options . 86 6.1 Text substitutions in command entries in /etc/hosts.allow and /etc/ hosts.deny .................................. 102 6.2 Attributes in the /etc/xinetd.conf file . 105 6.3 xinetd and signals . .$ . .echo . .tux . 106 tux 13.1 Access codes for processes with fuser$ ..................ls 181 hallo.c hallo.o $ /bin/su - Password: List of Figures 1.1 Example configuration for logrotate (Debian GNU/Linux 8.0) . 27 2.1 Complete log output of journalctl .................... 38 3.1 Protocols and service interfaces . 46 3.2 ISO/OSI reference model . 46 3.3 Structure of an IP datagram . 49 3.4 Structure of an ICMP packet . 50 3.5 Structure of a TCP Segment . 51 3.6 Starting a TCP connection: The Three-Way Handshake . 52 3.7 Structure of a UDP datagram . 53 3.8 The /etc/services file (excerpt) . 54 4.1 /etc/resolv.conf example . 79 4.2 The /etc/hosts file (SUSE) . 80 7.1 Unit file for Secure Shell daemon (Debian 8) . 114 $ echo tux 9.1 The mime.types file (excerpt) . .tux . 133 9.2 The /etc/cups/mime.convs file (excerpt)$ .ls . 134 9.3 The CUPS web interface . .hallo.c . 135 9.4 The CUPS web interface: Printer managementhallo.o . 136 9.5 The CUPS web interface: Adding a$ printer /bin/su . .- . 136 9.6 An /etc/cups/printers.conf file (excerpt)Password: . 138 Preface This training manual deals with the knowledge necessary to configure and oper- ate a Linux workstation as part of an (existing) local area network. It is aimed towards advanced Linux administrators and presumes knowledge on a level tested in the LPI-101 exam. This includes solid experience using the shell, a text editor, and the fundamental Linux commands as well as the basics of Linux administration. In addition, this training manual builds on the manual Advanced Linux, which covers topics such as shell programming, sed and awk, cron, and at. After an introduction to the system logging service, the fundamentals of TCP/IP and Linux network configuration, this manual covers the details of net- work troubleshooting and explains how to.