Linux Quick Fix Notebook学习摘录(一)
时间:2005-11-28 来源:showrun
Linux Quick Fix Notebook(linux 快速维修手册)是由Peter Harrison编写,由出版的针对Linux工程师的手册。作者的写作目的是解决在日常linux应用过程中经常出现问题为目标,因此针对性比较强。这本书不仅可以在您的服务器出现问题时给您帮助,同样对于初学和中级学者来说也是一本不错的教材。
本来想把这本书完整的翻译出来,但是在尝试一段时间后,发现时间与精力都不允许,因此还是把这些信息定义为对此书的学习摘录。希望能够给大家的工作和学习带来益处。
第一部分
第二章
linux help
linux的帮助文件是通过man命令或者帮助手册(manual pages)来访问。在命令行格式下可以使用在man命令后跟相应的文件名来得到你想得到的帮助信息。比如如果你想得到关于ssh命令的帮助信息,你可以使用如下命令:man ssh
[root@bigboy tmp]# man ssh
如果你想通过关键字来查找帮助手册,你可以在man后边跟-k参数来执行,比如“man -k ssh”,将会给你一个所有包含ssh关键字命令的man pages:
[root@bigboy tmp]# man -k ssh
...
...
ssh (1) - OpenSSH SSH client (remote login program)
ssh [slogin] (1) - OpenSSH SSH client (remote login program)
ssh-agent (1) - authentication agent
ssh-keyscan (1) - gather ssh public keys
ssh_config (5) - OpenSSH SSH client configuration files
sshd (8) - OpenSSH SSH daemon
sshd_config (5) - OpenSSH SSH daemon configuration file
...
...
[root@bigboy tmp]#
第三章 linux 网络
怎样去设置你的网卡地址
你需要去知道所有关于怎样去在一个网卡上设置IP地址。比如购物网站的购物车程序(shopping cart applications)经常需要额外的IP地址分配给他们。您在处理数据备份时也需要在第二个网卡的添加IP地址。至少,你或许仅仅在与周边的服务器做实验时也需要懂得如何在网卡上配置IP地址才能互联。
这一章告诉你如何简便的配置服务器的IP地址以及相关的操作。
确定你的IP地址
大多数现代的PC机都有以太网口。当Linux被安装后,这个以太口的名称为eth0。你可以通过ifconfig命令来获取:
[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.0 b) TX bytes:0 (0.0 b)
Interrupt:11 Base address:0x1820
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.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.7 Kb) TX bytes:82644 (80.7 Kb)
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]#
在这个例子当中,eth0没有IP地址应为这台机器使用端口wlan0做为主要的端口。wlan0配置的ip地址为192.168.1.100,子网掩码为255.255.255.0。
你可以看到这个命令很好地给出每一个接口卡的中断、或者PCI的总线ID(PCI bus ID)。在特殊情况下你会发现你的NIC无法工作的原因是你的网卡中断信息和内存进入地址(memory access address)与其他设备冲突。你可以通过/proc/interrupts文件来获知系统中所有的中断信息。在下边的例子中你能够看到IRQ从0到15互相之间都没有冲突(conflicts)。设备eth0和eth1分别使用不同的中断号5和10。
[root@bigboy tmp]# cat /proc/interrupts
CPU0
0: 2707402473 XT-PIC timer
1: 67 XT-PIC i8042
2: 0 XT-PIC cascade
5: 411342 XT-PIC eth1
8: 1 XT-PIC rtc
10: 1898752 XT-PIC eth0
11: 0 XT-PIC uhci_hcd
12: 58 XT-PIC i8042
14: 5075806 XT-PIC ide0
15: 506 XT-PIC ide1
NMI: 0
ERR: 43
[root@bigboy tmp]#
如果存在冲突,你可以通过查找问题设备的手册来确定如何分配给他一个其他的中断或内存I/O地址。
改变你的IP地址
如果需要你可以通过ifconfig命令来改变eth0的ip地址:
[root@bigboy tmp]# ifconfig eth0 10.0.0.1 netmask 255.255.255.0 up
在命令后边的"up"是用来激活(active)网卡的参数。如果希望在每次启动时都执行该命令,您可以把这条命令添加在/etc/rc.local文件中,此文件中的命令会在每次启动的最后运行。
Fedora Linux同样有一个稍方便一些的配置文件放置在/etc/sysconfig/network-scripts目录下。端口eth0的配置文件为ifcfg-eth0,eth1使用ifcfg-eth1,以此类推。你可以把你的IP地址的信息配置在以上这些文件中,这些文件在每次启动时会自动配置你的网卡。Figure3.1就是两个端口eth0的例子。一个是假设端口使用固定的IP地址,另外一个需要端口通过DHCP获得IP地址。
Figure 3.1. File formats for network-scripts. Fixed IP Address
[root@bigboy tmp]# cd /etc/sysconfig/network-scripts
[root@bigboy network-scripts]# less ifcfg-eth0
DEVICE=eth0
IPADDR=192.168.1.100
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes
#
# The following settings are optional
#
BROADCAST=192.168.1.255
NETWORK=192.168.1.0
[root@bigboy network-scripts]#
Getting the IP Address Using DHCP
[root@bigboy tmp]# cd /etc/sysconfig/network-scripts
[root@bigboy network-scripts]# less ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
[root@bigboy network-scripts]#
就像您看到的,eth0将会在启动时激活,因为参数ONBOOT后的值为yes而不是no。
默认的red hat/Fedora的安装将会包含broadcast和network选项在network-scripts文件。他们是可选择的。
在您更改完网卡配置文件的值后,你必须完成禁用和激活的操作后,配置才能生效。ifdown和ifup命令可以用来做如下操作:
[root@bigboy network-scripts]# ifdown eth0
[root@bigboy network-scripts]# ifup eth0
你的服务器必须得要一个默认网关才能与互联网互通。如何配置将会在下边的章节中详述。
DHCP是如何影响DNS服务器的设置的
你的DHCP服务器不只分配给你服务器IP地址,同样指定DNS服务器。保证你的/etc/resolv.conf文件有关于servers的配置行被注释,否则将会有冲突的危险。
在一个网卡上配置多个IP地址
在前边“确定你的IP地址”的章节中,你可能注意到那儿有两个无线网卡:wlan0和wlan0:0。端口wlan0:0是作为端口wlan0的子端口存在的一个虚拟子端口,另外一个名称叫IP alias。ip别名是一个非常普遍的方法来创造在一个单独的端口上配置多个IP地址。别名命名规则为 父端口:X,X是你选择的子端口数。
创造一个IP别名(子端口)与配置一个真实的端口的方式非常相近:
1. 首先保证真实的父端口存在。
2. 你准备配置的IP别名与已有的不重复。在这里我们希望配置的名称为wlan0:0。
3. 通过ifconfig命令创造虚拟端口:
[root@bigboy tmp]# ifconfig wlan0:0 192.168.1.99 netmask 255.255.255.0 up
4. 你同样需要创造一个/etc/sysconfig/network-scripts/ifcfg-wlan0:0文件来保证别名可以通过ifup和ifdown来自动配置。以下是配置文件来作为范例:
DEVICE=wlan0:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.99
NETMASK=255.255.255.0
禁用和激活虚拟端口的命令如下:
[root@bigboy tmp]# ifup wlan0:0
[root@bigboy tmp]# ifdown wlan0:0
注意
关闭主端口的话,所有此主端口的别名端口都会跟着关闭。但是别名端口可以相对于其他端口而单独关闭。
IP地址在DSL连接上的分配
如果你配置固定的IP地址来使用DSL连接的话,那么配置方式与以上相同。您可以把您的以太网连接线接入DSL猫后,配置好由ISP提供的IP地址,子网掩码,广播地址和网关信息等,在重启之后即可,另外牢记,你同样要配置好您的DNS服务器。
如果你使用DSL连接通过DHCP来获得动态IP地址,那么步骤就有所不同。你的ISP将会提供你PPPOE的用户名和密码来允许你的电脑每次启动后连接到internet。Fedora Linux需要安装rp-pppoeRPM包来实现。
1. 备份ifcfg-eth0文件:
[root@bigboy tmp]#
[root@bigboy tmp]# cd /etc/sysconfig/network-scripts/
[root@bigboy network-scripts]# ls ifcfg-eth0
ifcfg-eth0
[root@bigboy network-scripts]# cp ifcfg-eth0 DISABLED.ifcfg-eth0
2. 配置你的ifcfg-eth0文件,使其不包含IP地址信息同时设置不随系统启动而激活
DEVICE=eth0 ONBOOT=no 3.关闭eth0端口
[root@bigboy network-scripts]# ifdown eth0 [root@bigboy network-scripts]# 4.使用adsl-configure配置工具
[root@bigboy network-scripts]# adsl-setup 将会提示你提供ISP的用户名,使用的网卡名称(eth0),以及你是否需要随机器启动连接等
Welcome to the ADSL client setup. First, I will run some checks on your system to make sure the PPPoE client is installed properly... LOGIN NAME Enter your Login Name (default root): bigboy-login@isp INTERFACE Enter the Ethernet interface connected to the ADSL modem For Solaris, this is likely to be something like /dev/hme0. For Linux, it will be ethX, where 'X' is a number. (default eth0): Do you want the link to come up on demand, 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. If you want the link to stay up permanently, enter 'no' (two letters, lower-case.) NOTE: Demand-activated links do not interact well with dynamic IP addresses. You may have some problems with demand-activated links. Enter the demand value (default no): 一会程序会提示您输入DNS服务器的信息,这一步是用来配置/etc/resolve.conf文件的。如果您想使用ISP提供的DNS信息,那么只需输入"server"即可。
DNS Please enter the IP address of your ISP's primary DNS server. If your ISP claims that 'the server will provide dynamic DNS addresses', enter 'server' (all lower-case) here. If you just press enter, I will assume you know what you are doing and not modify your DNS setup. Enter the DNS information here:
......
adsl-setup创建的文件
第一个文件为ifcfg-ppp0,用来描述链路层的连接状态。
[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
PING=.
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]#
另外两个相同的文件为/etc/ppp/pap-secrets和/etc/ppp/chapsecrets,是用来保存用户名和密码的
[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]#
简单的troubleshooting
可以使用adsl-status来决定您现在的adsl端口的连接状态:
[root@bigboy tmp]# adsl-status
Note: You have enabled demand-connection; adsl-status may be
inaccurate.
adsl-status: Link is attached to ppp0, but ppp0 is down
[root@bigboy tmp]#
在上边的例子中软件包(package)已经被安装,但是端口并没有被激活
在激活后,端口工作正常:
[root@bigboy tmp]# ifup ppp0
[root@bigboy tmp]# adsl-status
adsl-status: Link is up and running on interface ppp0
ppp0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1462 inet
...
...
...
[root@bigboy tmp]#