练习一:内核模块管理

    1)查看当前系统中加载了哪些模块

[root@localhost ~]# lsmod

 

2)查看当前运行的内核是否支持FAT文件系统、是否支持蓝牙

[root@localhost ~]# modinfo vfatbluetooth

filename:      /lib/modules/2.6.32.61/kernel/fs/fat/vfat.ko

author:         Gordon Chaffee

description:    VFAT filesystem support

license:        GPL

srcversion:     3AF52E852722E36320C02AA

depends:        fat

vermagic:       2.6.32.61 SMP mod_unload modversions

 

3)了解内核模块ext4bluetooth的文件路径

[root@localhost~]# modinfo ext4

filename:       /lib/modules/2.6.32.61/kernel/fs/ext4/ext4.ko

 

[root@localhost~]# modinfo bluetooth

filename:      /lib/modules/2.6.18-348.el5/kernel/net/bluetooth/bluetooth

 

4)分别查看内核文件、模块目录占用的磁盘空间大小

[root@localhost~]# ls /boot/vmlinuz-2.6.18-348.el5 -lh

-rw-r--r--1 root root 2.1M 2012-11-29 /boot/vmlinuz-2.6.18-348.el5

 

[root@localhost~]# ls -ldh  /lib/modules/2.6.18-348.el5/

drwxr-xr-x7 root root 4.0K 06-25 00:24 /lib/modules/2.6.18-348.el5/

 

 

5)向当前运行的内核中插入ext4bluetooth模块

[root@localhost~]# modprobe ext4

[root@localhost~]# modprobe bluetooth

FATAL: Module bluetooth not found.

6)从当前运行的内核中移除ext4bluetooth模块

[root@localhost~]# modprobe -r  ext4

 

[root@localhost ~]# modprobe -r bluetooth

FATAL: Module bluetooth is in use.

 

7)查看当前是否加载了ext4模块

[root@localhost~]# lsmod | grep ext4

ext4                  303673  0

jbd2                   97865  1 ext4

crc16                  35137  1 ext4

8)挂载一个ext4文件系统,再检查ext4模块是否加载

[root@localhost~]# mkfs.ext4 /dev/sda5

-bash:mkfs.ext4: command not found

[root@localhost~]# modprobe -a ext4

[root@localhost~]# mkfs.ext4 /dev/sda5

-bash:mkfs.ext4: command not found

 

 

练习二:升级Linux内核

    1)查看initrd镜像文件的内容

         a)创建新目录imdir,并进入此目录

         b)释放:zcat /boot/initrd-*.img  |  cpio -idv

[root@localhost mydir]# ls

bin dev  etc  init lib  proc  sbin sys  sysroot

[root@localhost mydir]# zcat/boot/initrd-2.6.18-348.el5.img  | cpio-idv

 

         c)查看imdir目录下提供了哪些程序

[root@localhost~]# zcat /boot/initrd-2.6.18-348.el5.img | cpio –idv

 

 

    2)下载、安装kernel-2.6.32.61-5.x86_64.rpm

         a)查看新安装的内核程序

         b)查看新安装的内核模块目录

spacer.gif

 

3)为新内核制作initrd镜像文件

[root@localhost boot]# mkinitrd/boot/initrd-2.6.32.61.img 2.6.32.61

[root@localhost boot]# ls -lh/boot/initrd-2.6.32.61.img

-rw------- 1 root root 2.7M 07-10 16:16/boot/initrd-2.6.32.61.img

 

4)调整grub.conf引导配置,添加新内核的启动设置

[root@localhost boot]# vim /boot/grub/grub.conf

spacer.gif

 

         title Red Hat Enterprise Linux Server(2.6.32.61)

                     root (hd0,0)

                     kernel /新内核程序文件名 ro root=LABEL=/

                     initrd /initrd镜像文件名

    5)重启Linux主机,选择新内核进入系统

    6)检查当前的内核版本信息

 

练习三:环境准备

    1)准备3RHEL5.9虚拟机,内存均设为768M

    2)为其中一台虚拟机配置2块网卡

 

 

练习四:查看网络及ping测试

    1)分别查看本机的主机名、IP地址、MAC地址

[root@localhost mydir]# hostname

localhost.localdomain

[root@localhost mydir]# ifconfig eth0

eth0      Linkencap:Ethernet  HWaddr00:0C:29:4F:99:6B 

          inetaddr:172.30.7.3  Bcast:172.30.7.255  Mask:255.255.255.0

2)查看本机一共有哪些网络接口(包括不活动的)

[root@localhost mydir]# ifconfig a

eth0      Linkencap:Ethernet  HWaddr 00:0C:29:4F:99:6B

3)将网卡eth0设为禁用,查看其UP状态,重新设为激活,再查看状态

 

4)检查当前主机的网络连接状态

         a)有哪些正在监听(LISTEN)的系统服务

[root@localhost mydir]# netstat -anputl

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  

tcp        0      0 0.0.0.0:742                 0.0.0.0:*                   LISTEN      4376/rpc.statd     

 

         b)检查正在监听TCP 22端口的服务进程是什么,PID是多少

tcp      0  0 0.0.0.0:22        0.0.0.0:*            LISTEN      4562/sshd 

         c)检查sshd服务监听的是哪个端口

 

[root@localhostmydir]# netstat -anputl | grep sshd

tcp        0      0 0.0.0.0:22               0.0.0.0:*                   LISTEN      4562/sshd          

tcp        0     52 172.30.7.3:22          172.30.7.1:50706            ESTABLISHED 5414/sshd          

tcp        0      0 :::22                 :::*                        LISTEN      4562/sshd

 

         drsync服务设为开启,检查xinetd监听了哪些端口

[root@localhost mydir]# netstat-anput | grep xinetd

tcp      0     0 0.0.0.0:873        0.0.0.0:*      LISTEN      4575/xinetd    

 

 

    5)将Host1IP设为192.168.4.5/24Host2IP设为192.168.4.6/24

             a)查看本机的arp缓存表

arp-a

         b)向Host2发送4ping测试包,查看反馈结果

[root@localhost~]# arp -a

?(172.30.7.3) at 00:0c:29:4f:99:6b [ether] on eth0

?(172.30.7.1) at 00:50:56:c0:00:08 [ether] on eth0

         c)查看本机的arp缓存表,检查Host2MAC地址信息

         d)分别ping测试192.168.4.12310.0.0.10,查看测试结果

[root@localhost~]# ping -c 4    192.168.1.2

connect:Network is unreachable

[root@localhost~]# ping -c 4    10.0.0.10

connect:Network is unreachable

6)查看Host1的路由表记录,看是否有默认网关条目

[root@localhost ~]# route -n

Kernel IP routing table

Destination    Gateway         Genmask         Flags Metric Ref    Use Iface

172.30.7.0     0.0.0.0         255.255.255.0   U    0      0        0 eth0

169.254.0.0    0.0.0.0         255.255.0.0     U    0      0        0 eth0

[root@localhost ~]#

    a)将网卡eth0设为自动获取地址,重启network服务

     b)再检查路由表,看是否有默认网关条目

[root@hostname桌面]# route -n

KernelIP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

172.30.8.0      0.0.0.0         255.255.255.0   U    1      0        0 eth0

0.0.0.0         172.30.8.1      0.0.0.0         UG   0      0       0 eth0

         cping测试10.0.0.10,比较与第4-d步的结果的差异

 

root@hostname桌面]# ping -c 5 10.0.0.10

PING10.0.0.10 (10.0.0.10) 56(84) bytes of data.

 

---10.0.0.10 ping statistics ---

5packets transmitted, 0 received, 100% packet loss, time 14000ms

 

 

练习五:路由和域名测试

    1)重启network服务,检查IP地址、默认网关分别是多少

[root@localhost ~]# ifconfig

eth0      Linkencap:Ethernet  HWaddr00:0C:29:63:70:CE 

          inetaddr:172.30.7.2  Bcast:172.30.7.255  Mask:255.255.255.0

    2)使用host查询以下站点的IP地址是多少

    www.baidu.comwww.163.comtts6.tarena.com.cn

[root@hostname 桌面]# hosttts6.tarena.com.cn

tts6.tarena.com.cn has address 118.145.21.208

[root@hostname 桌面]# hostwww.163.com

www.163.com is an alias for www.163.com.lxdns.com.

www.163.com.lxdns.com is an alias for163.xdwscache.glb0.lxdns.com.

163.xdwscache.glb0.lxdns.com has address 125.39.35.178

163.xdwscache.glb0.lxdns.com has address 125.39.35.179

163.xdwscache.glb0.lxdns.com has address 124.202.166.57

163.xdwscache.glb0.lxdns.com has address 125.39.35.170

163.xdwscache.glb0.lxdns.com has address 125.39.35.171

163.xdwscache.glb0.lxdns.com has address 125.39.35.173

163.xdwscache.glb0.lxdns.com has address 125.39.35.174

163.xdwscache.glb0.lxdns.com has address 125.39.35.177

[root@hostname 桌面]# hostwww.baidu.com

www.baidu.com is an alias for www.a.shifen.com.

www.a.shifen.com has address 119.75.217.56

www.a.shifen.com has address 119.75.218.77

 

    3)使用nslookup查询以下站点的IP地址是多少

    www.sina.com.cnwww.google.cnwww.tmall.com

 

[root@hostname 桌面]# nslookupwww.tmall.com

Server:     172.30.1.16

Address:    172.30.1.16#53

 

Non-authoritative answer:

www.tmall.com   canonicalname = www.gslb.taobao.com.danuoyi.tbcache.com.

www.gslb.taobao.com.danuoyi.tbcache.com canonical name = scorpio.danuoyi.tbcache.com.

Name:   scorpio.danuoyi.tbcache.com

Address: 124.193.226.251

Name:   scorpio.danuoyi.tbcache.com

Address: 124.193.226.241

 

[root@hostname 桌面]# nslookupwww.goole.cn

Server:     172.30.1.16

Address:    172.30.1.16#53

 

Non-authoritative answer:

Name:   www.goole.cn

Address: 88.198.18.151

 

[root@hostname 桌面]# nslookupwww.baidu.com

Server:     172.30.1.16

Address:    172.30.1.16#53

 

Non-authoritative answer:

www.baidu.com   canonicalname = www.a.shifen.com.

Name:   www.a.shifen.com

Address: 119.75.218.77

Name:   www.a.shifen.com

Address: 119.75.217.56

 

    4)使用mtr跟踪从本机到以下站点的路由过程

    www.baidu.comtts6.tarena.com.cn

 

5)修改/etc/resolv.conf文件,注释掉nameserver

[root@hostname 桌面]# vim/etc/resolv.conf

[root@hostname 桌面]# mtrwww.baidu.com

Temporary failure in name resolution: No such process

    6)重复第23步测试,看是否还能够查询

    7)重复第23步测试,手动指定所用的DNS服务器地址

 

 

练习六:临时配置网络地址

    1)将第一台虚拟机的主机名改成host1.tarena.com

[root@localhost ~]# hostname host2.tarena.com

2)将IP地址改成192.168.10.128/24

[root@localhost ~]# ifconfig 192.168.10.128/24

3)将网卡eth0MAC地址的后四位改成 AB:CD,确认结果,然后再恢复

[root@localhost ~]# ifconfig eth0 hw ether 00:0C:29:77:AB:CD

4)使用ifdown禁用网卡eth0的配置,查看结果

[root@localhost ~]# ifdown eth0

设备 eth0含有MAC地址 00:0C:29:77:AB:CD,取代了已配置的地址00:0C:29:77:94:EB,忽略。

    5)使用ifup重新启用网卡eth0的配置,查看结果

[root@localhost ~]# ifup eth0

 eth0 设备的 MAC 地址与预想的不符,忽略。

练习七:主机互连

    1)将host1IP地址设置为192.168.4.128/24

    2)确保win7真机与host1可相互ping

    3)将虚拟机host3IP地址设为192.168.4.129/24,接入VMnet7网络

    4)调整host1的连接模式,确保与host3可相互ping

    5)为host1新增虚接口eth0:0IP设为10.0.0.128/24

    6)为host3新增虚接口eth0:1IP设为10.0.0.129/24,测试与host1通信

 

练习八:静态路由、默认网关

    1)将host1IP地址设置为192.168.4.128/24,接入仅主机模式

    2)为win7真机的VMnet1网卡添加三个IP地址:

         192.168.4.110/2410.0.0.110/24172.17.17.110/24

    3)在host1ping测试win7真机的上述三个IP地址

    4)为host1添加一条静态路由记录,并确认结果

         a)确保能ping10.0.0.110

         b)但是ping 172.17.17.110不通

    5)查看、删除第4步添加的静态路由记录

    6)重新添加一条默认网关记录,确保能ping通上述三个IP地址

    7)删除第6步添加的默认网关记录

 

练习九:arp绑定

    1)通过arp缓存查看192.168.4.110(可ping通的另一主机)的MAC地址

    2)设置arp静态绑定 192.168.4.110 --> 00:50:56:C0:12:34

    3)查看arp缓存记录,ping测试192.168.4.110,应该不通

    4)删除arp静态绑定,再测试可ping

 

练习十:hosts文件测试

    1)添加本地映射记录:

         本机的IP地址    www.qq.com  im.qq.com

 

    2)安装并启动httpd服务,创建一个测试网页:"我是qq.com"

         vim  /var/www/html/index.html

 

3)在浏览器访问http://www.qq.com/

 

 

练习十一:网络参数固定配置

    1)将主机名设置为host1.tarena.com

[root@host2~]# vim /etc/sysconfig/network

2)将网卡eth0IP地址设置为192.168.4.6/24

 

3)新增虚拟接口eth0:1,其IP地址为192.168.7.128/24

cp /etc/sysconfig/network-scripts/ifcfg-eth0/etc/sysconfig/network-scripts/ifcfg-eth0:0

4)将默认网关设置成192.168.4.111

 

5)在本机启用httpd网站服务,确认监听结果

[root@host2 ~]# netstat -anputl | grep httpd

tcp   0      0 :::80        :::*      LISTEN  12889/httpd 

6)从win7真机上访问http://192.168.4.6/

 

7)查看当前的DNS服务器地址设置,删除其中的记录

 

[root@localhost ~]# vim /etc/resolv.conf

 

练习十二(选做):Linux主机间路由

    1)准备3台虚拟机,实现静态路由互连(参见老师提供的幻灯片2

        三台主机:虚拟机1<------------------> 虚拟机2 <------------------> 虚拟机8

        连接类型:VMnet1                    VMnet1VMnet8                      VMnet8

        网段地址:             192.168.10.0/24                    192.168.80.0/24   

    2** 开启路由功能:

         临时开启:echo 1 >/proc/sys/net/ipv4/ip_forward

 

         固定配置:vim  /etc/sysctl.conf

                  net.ipv4.ip_forward = 1

                  ** 执行 sysctl  -p 可立即生效,不用重启

 

3)虚拟机1与虚拟机8能互相ping

spacer.gif

 

机器1 配置

DEVICE=eth0

BOOTPROTO=static

ONBOOT=yes

IPADDR=192.168.10.2

NETMASK=255.255.255.0

GATEWAY=192.168.10.3

 

 

机器2配置(双网卡)

DEVICE=eth0

BOOTPROTO=static

ONBOOT=yes

IPADDR=192.168.10.3

NETMASK=255.255.255.0

GATEWAY=192.168.10.3

~                       

DEVICE=eth1

BOOTPROTO=static

ONBOOT=yes

IPADDR=192.168.80.3

NETMASK=255.255.255.0

GATEWAY=192.168.80.3

~                          

vim /etc/sysctl.conf

net.ipv4.ip_forward = 1

 

机器3配置

 

DEVICE=eth0

BOOTPROTO=static

ONBOOT=yes

IPADDR=192.168.80.2

NETMASK=255.255.255.0

GATEWAY=192.168.80.3