Red Hat Linux Networking , System Administration (P8) ppsx

30 333 0
Red Hat Linux Networking , System Administration (P8) ppsx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

174 Chapter # Everybody gets emergency messages *.emerg * # Save news errors of level crit and higher in a special file uucp,news.crit /var/log/spooler Listing 8-4 (continued) ld.so.conf This configuration file is used by ldconfig, which configures dynamic linker runtime bindings It contains a listing of directories that hold shared libraries Shared library files typically end with so, whereas static library files typically end with a, indicating they are an archive of objects You may need to edit this file if you’ve installed a program that has installed a shared library to a different library directory that is not listed in the ld.so.conf file In this case, you get an error at runtime that the library does not exist An additional troubleshooting step to take in that case is to run ldd on the executable in question, which prints shared library dependencies The output would look something like this: [root@terry root]# ldd /bin/bash libtermcap.so.2 => /lib/libtermcap.so.2 (0x40026000) libdl.so.2 => /lib/libdl.so.2 (0x4002a000) libc.so.6 => /lib/tls/libc.so.6 (0x42000000) /lib/ld-linux.so.2 (0x40000000) You can see a default listing of library directories in Listing 8-5 include ld.so.conf.d/*.conf /usr/X11R6/lib /usr/lib/qt-3.3/lib /usr/lib/mysql Listing 8-5 A typical ld.so.conf file logrotate.conf logrotate.conf and the files within the logrotate.d directory determine how often your log files are rotated by the logrotate program Log rotation refers to the process of deleting older log files and replacing them with more recent ones logrotate can automatically rotate, compress, remove, Examining the System Configuration Files and mail your log files Log files can be rotated based on size or on time, such as daily, weekly, or monthly As you can see from the default logrotate.conf file shown in Listing 8-6, most of the options set for how and when to rotate the system logs are pretty self-explanatory For every program that has a separate log rotation configuration file in logrotate.d, and uses syslogd for logging, there should be a logrot config file for all log entries in /etc/syslog.conf, as well as log files produced by external applications, such as Apache This is because syslog needs to save log entries for these programs in separate files so that their log files can be rotated independently of one another # see “man logrotate” for details # rotate log files weekly weekly # keep weeks worth of backlogs rotate # create new (empty) log files after rotating old ones create # uncomment this if you want your log files compressed #compress # RPM packages drop log rotation information into this directory include /etc/logrotate.d # no packages own wtmp we’ll rotate them here /var/log/wtmp { monthly create 0664 root utmp rotate } # system-specific logs may be also be configured here Listing 8-6 The logrotate.conf file Examining the /etc/sysconfig/ Directory The following information outlines some of the files found in the /etc /sysconfig/ directory, their functions, and their contents This information is not intended to be complete, as many of these files have a variety of options used only in very specific or rare circumstances The /usr/share/doc /initscripts-version-number/sysconfig.txt file contains a more 175 176 Chapter authoritative listing of the files found in the /etc/sysconfig directory and the configuration options available Figure 8-1 shows the contents in a Fedora Core /etc/sysconfig directory N OT E These files are used to pass configuration information to scripts that run when the system starts It is possible that your system may be missing some of the configuration files described here, or it may have more of the files and directories, depending on whether the corresponding programs that need the files are installed or not Also, if the service that uses the configuration file is not started, the configuration file will not be read /etc/sysconfig/apmd The /etc/sysconfig/apmd file is used by apmd as a configuration for what things to start, stop, change on suspend, or resume It provides information to the apmd during startup if apmd is set to start, depending on whether your hardware supports Advanced Power Management (APM) or whether you choose to use it APM is a monitoring daemon that works with power management code within the Linux kernel It can alert you to a low battery if you are using Red Hat Linux on a laptop, among other things Figure 8-1 The contents of the /etc/sysconfig directory Examining the System Configuration Files /etc/sysconfig/authconfig The /etc/sysconfig/authconfig file provides settings to /usr/sbin /authconfig, which is called from /etc/rc.sysinit for the kind of authorization to be used on the host The basic syntax for lines in this file is: USE = Some sample lines from the file are shown here ■ ■ USEMD5=value, where value is one of the following: ■ ■ ■ ■ ■ ■ yes — MD5 is used for authentication no — MD5 is not used for authentication USEKERBEROS=value, where value is one of the following: ■ ■ ■ ■ ■ ■ yes — Kerberos is used for authentication no — Kerberos is not used for authentication USELDAPAUTH=value, where value is one of the following: ■ ■ yes — LDAP is used for authentication ■ ■ no — LDAP is not used for authentication /etc/sysconfig/clock The /etc/sysconfig/clock file controls the interpretation of values read from the system clock Currently, the correct values are as follows: ■ ■ UTC=value, where value is one of the following Boolean values: ■ ■ ■ ■ ■ ■ true — Indicates that the hardware clock is set to Universal Time Any other value indicates that it is set to local time ARC=value, where value is the following: ■ ■ ■ ■ ■ ■ true — Indicates the ARC console’s 42-year time offset is in effect Any other value indicates that the normal UNIX epoch is assumed (for Alpha-based systems only) ZONE=filename — Indicates the time zone file under /usr/share /zoneinfo that /etc/localtime is a copy of, such as: ZONE= ”America/New York” Identifies the time zone file copied into /etc /localtime, such as ZONE=”America/New York” Time zone files are stored in /usr/share/zoneinfo 177 178 Chapter /etc/sysconfig/crond This file contains settings for the cron daemon You typically not need to make any changes to this file /etc/sysconfig/desktop The /etc/sysconfig/desktop file specifies the desktop manager to be run and is used by the /etc/X11/xinit/Xclients script, for example: DESKTOP=”GNOME” /etc/sysconfig/firstboot In Fedora Core and Enterprise Linux, the first time you boot the system after the OS installation, the /sbin/init program calls the etc/rc.d/init.d /firstboot script This allows the user to install additional applications and documentation before the boot process completes The /etc/sysconfig /firstboot file tells the firstboot command not to run on subsequent reboots If you want firstboot to run the next time you boot the system, simply remove /etc/sysconfig/firstboot and execute chkconfig -level firstboot on /etc/sysconfig/grub The /etc/sysconfig/grub file is used to pass arguments to GRUB at boot time The information passed is the drive to boot from and whether to use lba mode /etc/sysconfig/harddisks The /etc/sysconfig/harddisks file allows you to tune your hard drive(s) C AU T I O N Do not make changes to this file lightly If you change the default values stored here, you could corrupt all of the data on your hard drive(s) The /etc/sysconfig/harddisks file may contain the following: ■■ USE_DMA=1, where setting this to enables DMA However, with some chipsets and hard-drive combinations, DMA can cause data corruption Check with your hard-drive documentation or manufacturer before enabling this Examining the System Configuration Files ■ ■ Multiple_IO=16, where a setting of 16 allows for multiple sectors per I/O interrupt When enabled, this feature reduces operating system overhead by 30 to 50 percent Use with caution ■ ■ EIDE_32BIT=3 enables (E)IDE 32-bit I/O support to an interface card ■ ■ LOOKAHEAD=1 enables drive read-lookahead ■ ■ EXTRA_PARAMS= specifies where extra parameters can be added /etc/sysconfig/hwconf The /etc/sysconfig/hwconf file lists all the hardware that kudzu detected on your system, as well as the drivers used, vendor ID, and device ID information The kudzu program detects and configures new and/or changed hardware on a system The /etc/sysconfig/hwconf file is not meant to be manually edited If you edit it, devices can suddenly show up as added or not show up if removed /etc/sysconfig/i18n The /etc/sysconfig/i18n file sets the default language, for example: LANG=”en_US” /etc/sysconfig/init The /etc/sysconfig/init file controls how the system will appear and function during the boot process The following values may be used: ■ ■ BOOTUP=value, where value is one of the following: ■ ■ BOOTUP=color means the standard color boot display, where the success or failure of devices and services starting up is shown in different colors ■ ■ BOOTUP=verbose means an old-style display, which provides more information than purely a message of success or failure ■ ■ Anything else means a new display, but without ANSI formatting ■ ■ RES_COL=value, where value is the number of the column of the screen to start status labels It defaults to 60 ■ ■ MOVE_TO_COL=value, where value moves the cursor to the value in the RES_COL line It defaults to ANSI sequences output by echo -e 179 180 Chapter ■■ SETCOLOR_SUCCESS=value, where value sets the color to a color indicating success It defaults to ANSI sequences output by echo -e, setting the color to green ■■ SETCOLOR_FAILURE=value, where value sets the color to one indicating failure It defaults to ANSI sequences output by echo -e, setting the color to red ■■ SETCOLOR_WARNING=value, where value sets the color to one indicating warning It defaults to ANSI sequences output by echo -e, setting the color to yellow ■■ SETCOLOR_NORMAL=value, where value sets the color to “normal.” It defaults to ANSI sequences output by echo -e ■■ LOGLEVEL=value, where value sets the initial console logging level for the kernel The default is 7; means everything (including debugging); means nothing except kernel panics syslogd will override this once it starts ■■ PROMPT=value, where value is one of the following Boolean values: ■■ yes — Enables the key check for interactive mode ■■ no — Disables the key check for interactive mode /etc/sysconfig/iptables The /etc/sysconfig/iptables file stores information used by the kernel to set up packet-filtering services at boot time or whenever the service is started You should not modify this file by hand unless you are familiar with how to construct iptables rules The simplest way to add rules is to use the /usr/sbin/lokkit command from a terminal prompt if you aren’t running an X server If you are running an X server, you can type system-configsecuritylevel from a terminal prompt or select Applications ➪ System Settings ➪ Security Level from the main menu to start the graphical application to create your firewall Using these applications automatically edits this file at the end of the process If you wish, you can manually create rules using /sbin/iptables and then type /sbin/service iptables save to add the rules to the /etc/ sysconfig/iptables file Once this file exists, any firewall rules saved there are persisted through a system reboot or a service restart C R O S S-R E F E R E N C E For more information on iptables, see Chapter 34 Examining the System Configuration Files /etc/sysconfig/irda The /etc/sysconfig/irda file controls how infrared devices on your system are configured at startup The following values may be used: ■ ■ IRDA=value, where value is one of the following Boolean values: ■ ■ yes — irattach will be run, which periodically checks to see whether anything is trying to connect to the infrared port, such as another notebook computer attempting to make a network connection For infrared devices to work on your system, this line must be set to yes ■ ■ no — irattach will not be run, preventing infrared device communication ■ ■ DEVICE=value, where value is the device (usually a serial port) that handles infrared connections ■ ■ DONGLE=value, where value specifies the type of dongle being used for infrared communication This setting exists for people who use serial dongles rather than real infrared ports A dongle is a device attached to a traditional serial port to communicate via infrared This line is commented out by default because notebooks with real infrared ports are far more common than computers with add-on dongles ■ ■ DISCOVERY=value, where value is one of the following Boolean values: ■ ■ yes — Starts irattach in discovery mode, meaning it actively checks for other infrared devices This needs to be turned on in order for the machine to be actively looking for an infrared connection (meaning the peer that does not initiate the connection) ■ ■ no — Does not start irattach in discovery mode /etc/sysconfig/kernel The settings in this file specify whether new kernels loaded by the up2date utility should be booted by default You can change the setting from yes to no to prevent the newly updated kernel from booting /etc/sysconfig/keyboard The /etc/sysconfig/keyboard file controls the behavior of the keyboard The following values may be used: ■ ■ KEYBOARDTYPE=sun|pc, which is used on SPARCs only sun means a Sun keyboard is attached on /dev/kbd, and pc means a PS/2 keyboard is connected to a PS/2 port 181 182 Chapter ■■ KEYTABLE=file, where file is the name of a keytable file For example: KEYTABLE=”us” The files that can be used as keytables start in /usr/lib/kbd/keymaps/i386 and branch into different keyboard layouts from there, all labeled file.kmap.gz The first file found beneath /usr/lib/kbd/keymaps/i386 that matches the KEYTABLE setting is used /etc/sysconfig/kudzu The /etc/sysconfig/kuzdu is used by /etc/init.d/kudzu, and it allows you to specify a safe probe of your system’s hardware by kudzu at boot time A safe probe is one that disables serial port probing ■■ SAFE=value, where value is one of the following: ■■ yes — kuzdu does a safe probe ■■ no — kuzdu does a normal probe /etc/sysconfig/mouse The /etc/sysconfig/mouse file is used by /etc/init.d/gpm to specify information about the available mouse The following values may be used: ■■ FULLNAME=value, where value refers to the full name of the kind of mouse being used ■■ MOUSETYPE=value, where value is one of the following: ■■ microsoft — A Microsoft mouse ■■ mouseman — A MouseMan mouse ■■ mousesystems — A Mouse Systems mouse ■■ ps/2 — A PS/2 mouse ■■ msbm — A Microsoft bus mouse ■■ logibm — A Logitech bus mouse ■■ atibm — An ATI bus mouse ■■ logitech — A Logitech mouse ■■ mmseries — An older MouseMan mouse ■■ mmhittab — An mmhittab mouse Examining the System Configuration Files ■ ■ XEMU3=value, where value is one of the following Boolean values: ■ ■ yes — The mouse has only two buttons, but three mouse buttons should be emulated ■ ■ no — The mouse already has three buttons ■ ■ XMOUSETYPE=value, where value refers to the kind of mouse used when X is running The options here are the same as those provided by the MOUSETYPE setting in this same file ■ ■ DEVICE=value, where value is the mouse device In addition, /dev/mouse is a symbolic link that points to the actual mouse device /etc/sysconfig/named The /etc/sysconfig/named file is used to pass arguments to the named daemon at boot time if the named daemon is started The named daemon is a Domain Name System (DNS) server, which implements the Berkeley Internet Name Domain (BIND) version distribution This server maintains a table of which hostnames are associated with IP addresses on the network Currently, only the following values may be used: ■ ■ ROOTDIR=/some/where, where /some/where refers to the full directory path of a configured chroot environment under which named will run This chroot environment must first be configured Type info chroot for more information on how to this ■ ■ OPTIONS=”value”, where value is any option listed in the man page for named except -t In place of -t, use the preceding ROOTDIR line For more information about what parameters you can use in this file, type man named By default, the file contains no parameters C R O S S-R E F E R E N C E For detailed information on how to configure a BIND DNS server, see Chapter 18 /etc/sysconfig/netdump The /etc/sysconfig/netdump file is the configuration file for the /etc/ init.d/netdump service The netdump service sends both oops data and memory dumps over the network In general, netdump is not a required service, so you should run it only if you absolutely need to For more information about what parameters you can use in this file, type man netdump 183 Examining the System Configuration Files ■ ■ Set up the hostname of your machine Make changes to: /etc/sysconfig/network /etc/hosts ■ ■ Set up the DNS servers to reference Make changes to: /etc/resolv.conf ■ ■ Make a local file of hostname to IP address mappings Make changes to: /etc/hosts ■ ■ Set up the device order from which hostnames are looked up Make changes to: /etc/nsswitch.conf C R O S S-R E F E R E N C E Chapter 20 explains the Domain Name System (DNS) and how to set it up on your network T I P Fedora Core and Red Hat Enterprise Linux provide a handy graphical tool, called the Network Configuration tool for configuring your network settings Start up the Network Configuration tool while in X-Window, and enjoy an interface very similar to the Windows control panel for networks Refer to Chapter 11 for instructions on using the Network Configuration tool If you use the Network Configuration tool to set up your network, you not need to edit the files manually as explained in the next sections Also, if you use DHCP to obtain your IP information, you not need to any manual configuration and can skip the sections related to manually configuring your network settings Setting Up the IP Address The first thing you should is set an IP address on your network interfaces This step provides your computer with an identity on the network If you haven’t set the IP address already in the installation process, you need to edit the configuration files by hand To set the IP address on your first Ethernet interface eth0, edit the /etc/ sysconfig/network-scripts/ifcfg-eth0 file A copy of this file is shown in Listing 8-7 Insert your interface’s IP address on the line that says: IPADDR=”” You should also check that the rest of the lines look all right, but pay special attention to the following two lines: 189 190 Chapter BROADCAST=192.168.1.255 NETMASK=”255.255.255.0” DEVICE=”eth0” BOOTPROTO=”static” BROADCAST=192.168.1.255 IPADDR=”192.168.1.10” NETMASK=”255.255.255.0” NETWORK=192.168.1.0 ONBOOT=”yes” USERCTL=no Listing 8-7 The /etc/sysconfig/network-scripts/ifcfg-eth0 file Setting Up the Hostname Once you’ve picked your hostname, you need to put it into two different places: /etc/sysconfig/network and /etc/hosts In /etc/sysconfig/network, shown next, change the line that says: HOSTNAME=”terry” This is the /etc/sysconfig/network file: NETWORKING=yes HOSTNAME=”terry” GATEWAY=”192.168.1.1” GATEWAYDEV=”eth0” FORWARD_IPV4=”yes” You also need to modify the /etc/hosts file Change the first line in the file, which would look something like this by adding the hostname you want: 127.0.0.1 terry localhost.localdomain localhost locala localb localc Setting Up the DNS Name Resolution Now you should be able to communicate with the other hosts on the network However, you won’t be able to talk to them unless you know their IP addresses, because you haven’t set up what DNS servers you should reference to map hostnames to IP addresses Examining the System Configuration Files The program that resolves hostnames to IP addresses reads a file called resolv.conf, so you need to put your DNS server IP addresses there Generally, you need one name server, but you can include up to three, if you’d like Specifying more than one name server is important If the first one on the list is not responding, your computer tries to resolve against the next one on the list, and so on, until it finds one that is responding Edit /etc/resolv.conf to contain a list of name servers, like this: nameserver 1.2.3.4 nameserver 1.2.3.5 nameserver 1.2.3.6 Making a Local File of Hostname to IP Address Mappings Linux gives you the ability to store a list of hostnames and their corresponding IP addresses in /etc/hosts, so that you don’t have to look them up in DNS every time you use them While you shouldn’t this with every hostname you ever use, one of the advantages gained by configuring often-used hostnames in this way includes the ability to alias a fully qualified hostname to a shorter version of itself So instead of typing ssh foo.xena.edu every time you want to SSH to that machine, you can just type ssh foo, and have it connect to the same host Another useful example occurs if you’re monitoring several servers’ network services from a monitoring host If you’re monitoring SSH connectivity to certain servers, for example, and your DNS server stops responding, then the monitoring software may report that all your hosts are down This happens because the monitoring software tries to connect to the server via its hostname, and gets no response because DNS is not providing it with an IP address to connect to In this case it looks as if your whole network fell over, when the real problem is that your DNS service is not responding properly To keep this kind of scenario from happening, you should put the hostnames and IP addresses of all your monitored servers in /etc/hosts This way, your monitoring software looks into /etc/hosts to get the proper IP addresses, instead of relying on DNS The only caveat to keep in mind when putting hosts in /etc/hosts is that if the hostname’s IP address changes for whatever reason, the hosts file does not automatically update to reflect that change If you start getting connection errors when connecting to a host in the /etc/hosts file, you should an nslookup on the host and update your /etc/hosts file accordingly Your /etc/hosts file should contain IP address to hostname mappings that follow this format IP_address canonical_hostname aliases 191 192 Chapter so that the lines look like this: 192.168.1.66 192.168.1.76 152.2.210.81 foo.xena.edu buffy.xena.edu sunsite.unc.edu foo buffy sunsite Setting Up Name Service Resolution Order Now that you’ve set up your DNS servers and hosts file, you need to tell your Linux server which method it should use first to look up hostnames The place to set up this configuration is in the /etc/nsswitch.conf file Edit the following line: hosts: files nisplus dns The order of the words files, nisplus, and dns determines which method is checked first Files refers to the /etc/hosts file, nisplus refers to any nisplus servers you may have on your network, and dns refers to any DNS servers you have set up your machine to reference As you can see in Listing 8-8, the /etc/nsswitch.conf file contains some other useful settings; for example the following two lines, specify whether the server should authenticate users off the local password file or off the network’s NIS plus service: passwd: shadow: # # # # # # # # # # # # # # # # # # files nisplus files nisplus /etc/nsswitch.conf An example Name Service Switch config file This file should be sorted with the most-used services at the beginning The entry ‘[NOTFOUND=return]’ means that the search for an entry should stop if the search in the previous entry turned up nothing Note that if the search failed due to some other reason (like no NIS server responding) then the search continues with the next entry Legal entries are: nisplus or nis+ nis or yp dns files Use Use Use Use NIS+ (NIS version 3) NIS (NIS version 2), also called YP DNS (Domain Name Service) the local files Listing 8-8 The /etc/nsswitch.conf file (continued) Examining the System Configuration Files # # # # # db compat hesiod [NOTFOUND=return] # To use db, put the # looked up first in # # Example: #passwd: db files #shadow: db files #group: db files Use the local database (.db) files Use NIS on compat mode Use Hesiod for user lookups Stop searching if not found so far “db” in front of “files” for entries you want to be the databases nisplus nis nisplus nis nisplus nis passwd: shadow: group: files nisplus files nisplus files nisplus #hosts: hosts: db files nisplus nis dns files nisplus dns # Example - obey only what nisplus tells us #services: nisplus [NOTFOUND=return] files #networks: nisplus [NOTFOUND=return] files #protocols: nisplus [NOTFOUND=return] files #rpc: nisplus [NOTFOUND=return] files #ethers: nisplus [NOTFOUND=return] files #netmasks: nisplus [NOTFOUND=return] files bootparams: nisplus [NOTFOUND=return] files ethers: netmasks: networks: protocols: rpc: services: files files files files nisplus files files nisplus netgroup: files nisplus publickey: nisplus automount: aliases: files nisplus files nisplus Listing 8-8 (continued) Starting Up Network Services from xinetd xinetd is the replacement for inetd xinetd is started on bootup and listens on ports designated in the /etc/xinetd.conf for incoming network 193 194 Chapter connections When a new connection is made, xinetd starts up the corresponding network service You should disable any unnecessary services from being started from xinetd as part of securing your machine The way to this is to edit that service’s configuration file xinetd’s main configuration file is /etc/xinetd.conf At the end of the xinetd.conf file is a line that indicates that all the files in the /etc/ xinetd.d are also included in the configuration This means that you need to go through the files in that directory as well to turn off any services you don’t want So, to disable Telnet, you would look in /etc/xinetd.d for a file called telnet The telnet file is shown in Listing 8-9 Edit the line in the config file that says disable = no, and change that to disable = yes, as it appears in Listing 8-9 After that line is set to disable = yes, the service is disabled and does not start up the next time you boot up /etc/xinetd.d/telnet # default: on # description: The telnet server serves telnet sessions; it uses \ # unencrypted username/password pairs for authentication service telnet { flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin/in.telnetd log_on_failure += USERID disable = yes } Listing 8-9 The Telnet config file in the xinetd.d directory An automated tool, called chkconfig, manages what services are started from xinetd and the rc scripts You can read more about chkconfig in the section called “Managing rc Scripts Using chkconfig.” Starting Up Network Services from the rc Scripts Network services that are not started out of xinetd are started out of the rc scripts at boot time Network services started at the default boot level (multiuser networked mode) are started out of the /etc/rc3.d directory If you look in that directory, you should see a file with the name of the service you want to stop or start The script to start the service starts with an S, and the kill script starts with a K So for example, SSH is started from /etc/rc3.d /S55sshd, and killed upon shutdown from /etc/rc6.d/K25sshd Runlevel is the shutdown level, so that’s why its kill script is located in the rc6.d directory Examining the System Configuration Files Detailed information on managing all the services started at boot time can be found in the section “Managing the init Scripts” later in this chapter C R O S S-R E F E R E N C E See Chapter for details about the system startup process Other Important Network Configuration Files in the /etc/sysconfig Directory You can use the files listed in this section to create routes to other hosts, either on your own network or on outside networks You also can use these files to set up firewall rules for your network to either allow or disallow connections to your network static-routes If you want to set up some static routes on your machine, you can so in the static-routes file This config file has lines in the following format: network-interface net network netmask netmask gw gateway Iptables iptables is the current Fedora Core and Enterprise Linux firewall It supercedes the ipchains firewall It can use ipchains rules as a component of its firewall filtering, but iptables and ipchains cannot be run at the same time This is the file where the iptables rules are stored When you install Fedora or Enterprise Linux, the installation asks if you would like to enable a host-based firewall If you select to enable a host-based firewall, a default set of iptables rules installs according to your preferences The following is a simplified configuration file The gist of this configuration is that all incoming traffic to privileged ports (those below 1024) is dropped except for SSH traffic The first line accepts all traffic from the loopback interface The second line accepts all incoming TCP traffic to the SSH port The third line drops all incoming TCP traffic to ports between and 1024 The last line drops all incoming UDP traffic to ports between and 1024 -A -A -A -A INPUT INPUT INPUT INPUT -i -p -p -p lo -j ACCEPT tcp dport 22 -p tcp -j ACCEPT tcp -s ! 192.168.1.0/24 dport 1:1024 -j DROP udp -s ! 192.168.1.0/24 dport 1:1024 -j DROP 195 196 Chapter Network Configuration Files in /etc/sysconfig/network-scripts You can use the files in this directory to set the parameters for the hardware and software used for networking The scripts contained here are used to enable network interfaces and set other network-related parameters ifcfg-networkinterfacename A few files fall into this specification Red Hat specifies a separate configuration file for each network interface In a typical Red Hat install, you might have many different network interface config files that all follow the same basic syntax and format You could have ifcfg-eth0 for your first Ethernet interface, ifcfgirlan0 for your infrared network port, ifcfg-lo for the network loopback interface, and ifcfg-ppp0 for your PPP network interface ifup and ifdown These files are symlinks to /sbin/ifup and /sbin/ifdown In future releases, these symlinks might be phased out But for now, these scripts are called when the network service is started or stopped In turn, ifup and ifdown call any other necessary scripts from within the network-scripts directory These should be the only scripts you call from this directory You call these scripts with the name of the interface that you want to bring up or down If these scripts are called at boot time, then boot is used as the second argument For instance, to bring your Ethernet interface down and then up again after boot, you would type: ifup eth0 ifdown eth0 Managing the init Scripts This section discusses the following topics: ■■ Managing rc scripts by hand ■■ Managing rc scripts using chkconfig Init scripts determine which programs start up at boot time Red Hat and other Unix distributions have different runlevels, so there are a different set of programs that are started at each runlevel Examining the System Configuration Files Usually Red Hat Linux starts up in multiuser mode with networking turned on These are some of the other runlevels available: ■ ■ — Halt ■ ■ — Single-user mode ■ ■ — Multiuser mode, without networking ■ ■ — Full multiuser mode ■ ■ — Not used ■ ■ — Full multiuser mode (with an X-based login screen) ■ ■ — Reboot The system boots into the default runlevel set in /etc/inittab (See Listing 8-10.) N OT E In Red Hat Linux, the default boot level is for a non-GUI system When booting into an X-windows login, the default boot level is You can get more information about this topic in Chapter # # inittab # # # Author: # # This file describes how the INIT process should set up the system in a certain run-level Miquel van Smoorenburg, Modified for RHS Linux by Marc Ewing and Donnie Barnes # Default runlevel The runlevels used by RHS are: # - halt (Do NOT set initdefault to this) # - Single user mode # - Multiuser, without NFS (The same as 3, if you not have networking) # - Full multiuser mode # - unused # - X11 # - reboot (Do NOT set initdefault to this) # id:5:initdefault: # System initialization si::sysinit:/etc/rc.d/rc.sysinit l0:0:wait:/etc/rc.d/rc l1:1:wait:/etc/rc.d/rc l2:2:wait:/etc/rc.d/rc l3:3:wait:/etc/rc.d/rc l4:4:wait:/etc/rc.d/rc Listing 8-10 A default /etc/inittab file (continued) 197 198 Chapter l5:5:wait:/etc/rc.d/rc l6:6:wait:/etc/rc.d/rc # Things to run in every runlevel ud::once:/sbin/update # Trap CTRL-ALT-DELETE ca::ctrlaltdel:/sbin/shutdown -t3 -r now # When our UPS tells us power has failed, assume we have a few minutes # of power left Schedule a shutdown for minutes from now # This does, of course, assume you have powerd installed and your # UPS connected and working correctly pf::powerfail:/sbin/shutdown -f -h +2 “Power Failure; System Shutting Down” # If power was restored before the shutdown kicked in, cancel it pr:12345:powerokwait:/sbin/shutdown -c “Power Restored; Shutdown Cancelled” # Run gettys in standard runlevels 1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6 # Run xdm in runlevel # xdm is now a separate service x:5:respawn:/etc/X11/prefdm –nodaemon Listing 8-10 (continued) Managing rc Scripts by Hand If you want to configure which services are started at boot time, you need to edit the rc scripts for the appropriate runlevel The default runlevel is 3, which is full multiuser mode without a graphical interface and runlevel with a graphical interface So, to change the services that are started in the default runlevel, you should edit the scripts found in /etc/rc3.d, or /etc/rc5.d depending on your system When you look at a directory listing of the rc directories, notice that the files either start with S or K The files that start with S are startup files, and the files that start with K are kill files The S scripts are run in the numerical order listed in their filenames It should be mentioned that if a startup script is set to S15, the K script should be K85 (or in general, SN becomes SM with M = 100 - n; the idea being the last started service is the first killed) Examining the System Configuration Files Note that case is important Scripts that not start with a capital S not run upon startup One good way to keep scripts from starting up at boot time without deleting them is to rename the file with a small s at the beginning instead of a capital S This way you can always put the script back into the startup configuration by capitalizing the initial letter When the system starts up, it runs through the scripts in the rc directory of the runlevel it’s starting up in So when the system starts up in runlevel 3, it runs the scripts in the /etc/rc3.d directory Looking at the directory listing included in Figure 8-2, you can see that the first few services start in this order: kudzu, reconfig, iptables, and network That is so because their scripts are named S05kudzu, S06cpuspeed, S08iptables, and S10network, respectively Kudzu is called first because it detects new hardware cpuspeed runs to put into effect speed stepping for the CPU iptables then starts up the built-in firewall Network then brings up the system’s network interfaces As you can see, the order in which these services are started makes a lot of sense, and their order is enforced by the way their rc startup scripts are named All of the files in rc#.d are symbolic links to /etc/init.d scripts, and the names are used here only to affect what services start or stop and the ordering of those services Editing the rc3.d/httpd file will affect rc5.d/httpd The S scripts are started in this order until they have all been started When the system shuts down, the corresponding K or kill scripts are run to shut down the services started from the rc directory In general, every S script should have a corresponding K script to kill the service at shutdown If you can’t find the corresponding K script in the startup directory, it is probably located in the shutdown directory When the system is shut down, it enters runlevel So, most K scripts are in /etc/rc6.d A typical /etc/rc6.d directory listing is shown Figure 8-3 Figure 8-2 A directory listing of the r3.d directory 199 200 Chapter Figure 8-3 The file contents of the /etc/rc6.d directory If you ever need to restart a service that’s started from an rc directory, an easy way to it properly is to run its startup script with the restart option This procedure enables all the proper steps to be followed (configuration files read, lock files released, and so forth) when the service starts up again So, to restart syslog, for example, run the following command from the rc directory: [root@terry rc3.d]# /S12syslog restart Shutting down kernel logger: Shutting down system logger: Starting system logger: Starting kernel logger: [ [ [ [ OK OK OK OK ] ] ] ] Managing rc Scripts Using chkconfig Fedora Core and Red Hat Enterprise Linux come with a useful tool called chkconfig It helps the system administrator manage rc scripts and xinetd configuration files without having to manipulate them directly It is inspired by the chkconfig command included in the IRIX operating system Type chkconfig list to see all the services chkconfig knows about, and whether they are stopped or started in each runlevel An abridged example output is shown in the following listing The chkconfig output can be a lot longer than that listed here, so be prepared to pipe it through less or more The first column is the name of the installed service The next seven columns each represent a runlevel, and tell you whether that service is turned on or off in that runlevel Since xinetd is started on the system whose chkconfig output is excerpted, at the end of chkconfig’s report is a listing of what xinetd started services are Examining the System Configuration Files configured to begin at boot time The listing is abridged, since a lot of services can be started from xinetd, and there’s no need to show all of them Listing 8-11 shows how chkconfig can be an effective tool for handling all your network services and controlling which ones get started up at boot time This is the output of chkconfig list: atd rwhod keytable nscd syslog gpm kudzu kdcrotate lpd autofs sendmail rhnsd netfs network random rawdevices apmd ipchains 0:off 0:off 0:off 0:off 0:off 0:off 0:off 0:off 0:off 0:off 0:off 0:off 0:off 0:off 0:off 0:off 0:off 0:off 1:off 1:off 1:on 1:off 1:off 1:off 1:off 1:off 1:off 1:off 1:off 1:off 1:off 1:off 1:off 1:off 1:off 1:off xinetd based services: rexec: off rlogin: off rsh: off chargen: chargen-udp: daytime: daytime-udp: echo: off echo-udp: time: off time-udp: finger: off ntalk: off talk: off telnet: off wu-ftpd: rsync: off eklogin: gssftp: off klogin: off 2:off 2:off 2:on 2:off 2:on 2:on 2:off 2:off 2:on 2:off 2:on 2:off 2:off 2:on 2:on 2:off 2:on 2:off off off off off off off on off Listing 8-11 Output from chkconfig –list 3:on 3:off 3:on 3:off 3:on 3:off 3:on 3:off 3:on 3:on 3:off 3:on 3:off 3:on 3:on 3:on 3:off 3:off 4:on 4:off 4:on 4:off 4:on 4:off 4:on 4:off 4:on 4:on 4:off 4:on 4:off 4:on 4:on 4:on 4:off 4:off 5:on 5:off 5:on 5:off 5:on 5:off 5:on 5:off 5:on 5:on 5:off 5:on 5:off 5:on 5:on 5:on 5:off 5:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 6:off 201 202 Chapter To turn a service off or on using chkconfig, use this syntax: chkconfig -level[0-6](you must choose the runlevel) servicename off|on|reset So, to turn off the gpm daemon turned on previously, type: chkconfig level gpm off To turn on xinetd, type: chkconfig xinetd on Run chkconfig list again to see if the service you changed has been set to the state you desire Changes you make with chkconfig take place the next time you boot up the system You can always start, stop, or restart a service by running service (service name) from a terminal prompt Summary All systemwide configuration files are located in /etc So, if you want to change something across the system, look in /etc and its subdirectories first If you’re at a loss in terms of figuring out which configuration file you need to edit, try grepping for keywords in /etc To change configuration variables for one or a few users, you can usually edit configuration files within the individual users’ home directories Most configuration files in home directories start with a so you need to look for them with the ls -a command Be mindful of configuration file permissions to ensure that unauthorized parties cannot modify them Flat out instant root access for unauthorized parties is one possible outcome of a modified configuration file A more likely outcome is that a configuration file modification would make it easier for a system compromise to take place You can either edit startup files by hand or by using one of the system administration tools such as chkconfig You should at least know the format of the startup files and where they are, so that if automatic tools can’t the job for some reason, you can always change things yourself PA R T Two Network Services Chapter 9: Chapter 10: Chapter 11: Chapter 12: Chapter 13: Chapter 14: Chapter 15: Chapter 16: Chapter 17: Chapter 18: Managing the X Window System Configuring Printers TCP/IP Networking The Network File System The Network Information System Connecting to Microsoft and Novell Networks Configuring a Database Server Creating a VNC Server Providing Additional Network Services Optimizing Network Services ... and GPG keys for Red Hat Network No files in this directory should be edited by hand For more information on Red Hat Network, see the Red Hat Network Web site at https:// rhn.redhat.com Examining... Figure 8- 2, you can see that the first few services start in this order: kudzu, reconfig, iptables, and network That is so because their scripts are named S05kudzu, S06cpuspeed, S08iptables, and... Up a System or Moving the System Whenever you set up a system to work on a new network, either because you’ve just installed Red Hat or you’re moving the machine from one location to another, a

Ngày đăng: 07/07/2014, 09:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan