13.网络系统(快乐的Linux命令行)

1.学习的指令

ping Send an ICMP ECHO_REQUEST to network hosts
traceroute Print the route packets trace to a network host
netstat Print network state
ftp Internet file transfer program
wget Non-interactive network downloader
ssh remote login program

2.小知识

知识点1:ping命令的具体过程

ping 命令发送网络数据包,叫做 ICMP ECHO_REQUEST,到指定的主机。多数接收这个的网络设备会回复它,来进行网络连接验证。

知识点2:traceroute命令的作用

traceroute 程序会显示从本地到指定主机,要经过的所有“跳数”的网络流量列表。

知识点3:ftp操作各选项的意义

ftp fileserver 唤醒 ftp 程序,让它连接到 FTP 服务器,fileserver。
anonymous 登录名。输入登录名后,将出现一个密码提示。可能是空密码,也可能是 “[email protected]”。
cd pub/cd_images/Ubuntu-8.04 跳转到远端系统中,要下载文件所在的目录下, 大多数文件都能在pub下找到
ls 列出远端系统中的目录。
lcd Desktop 跳转到本地系统中的 ~/Desktop 目录下。 这个命令把工作目录改为 ~/Desktop,多了个l
get ubuntu-8.04-desktop-i386.iso 告诉远端系统传送文件到本地。因为工作目录 已经更改到 ~/Desktop,所以会被下载到此目录。
bye 退出远端服务器,结束 ftp 程序会话。也可以使用命令 quit 和 exit。

 

知识点4:lftp与ftp的区别?

没什么区别就是lftp更高级,比如直接可以用Tab键进行补全代码。

知识点5:wget与ftp的区别?

答:wget可以在网络下进行下载,也可以在ftp下进行下载。所以很有用。

知识点6:若连接主机密码也就修改,如何通过SSH进行重新连接?

答:进入~/.ssh/known_hosts 删除 offend key 即废弃的钥匙,再进行连接

3.代码实操

 

[me@linuxbox ~]$ ping linuxcommand.org
[me@linuxbox ~]$ ping linuxcommand.org
PING linuxcommand.org (66.35.250.210) 56(84) bytes of data.
64 bytes from vhost.sourceforge.net (66.35.250.210): icmp\_seq=1
ttl=43 time=107 ms
64 bytes from vhost.sourceforge.net (66.35.250.210): icmp\_seq=2
ttl=43 time=108 ms
64 bytes from vhost.sourceforge.net (66.35.250.210): icmp\_seq=3
ttl=43 time=106 ms
64 bytes from vhost.sourceforge.net (66.35.250.210): icmp\_seq=4
ttl=43 time=106 ms
64 bytes from vhost.sourceforge.net (66.35.250.210): icmp\_seq=5
ttl=43 time=105 ms
...

[me@linuxbox ~]$ traceroute slashdot.org
traceroute to slashdot.org (216.34.181.45), 30 hops max, 40 byte
packets
1 ipcop.localdomain (192.168.1.1) 1.066 ms 1.366 ms 1.720 ms
2 * * *
3 ge-4-13-ur01.rockville.md.bad.comcast.net (68.87.130.9) 14.622
ms 14.885 ms 15.169 ms
4 po-30-ur02.rockville.md.bad.comcast.net (68.87.129.154) 17.634
ms 17.626 ms 17.899 ms
5 po-60-ur03.rockville.md.bad.comcast.net (68.87.129.158) 15.992
ms 15.983 ms 16.256 ms
6 po-30-ar01.howardcounty.md.bad.comcast.net (68.87.136.5) 22.835
...
注:从输出结果中,我们可以看到连接测试系统到 slashdot.org 网站需要经由16个路由器。对于那些提供标
识信息的路由器,我们能看到它们的主机名,IP 地址和性能数据,这些数据包括三次从本地到此路由器的往返
时间样本。对于那些没有提供标识信息的路由器(由于路由器配置,网络拥塞,防火墙等 方面的原因),我们
会看到几个星号

[me@linuxbox ~]$ netstat -ie
eth0    Link encap:Ethernet HWaddr 00:1d:09:9b:99:67
        inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
        inet6 addr: fe80::21d:9ff:fe9b:9967/64 Scope:Link
        UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
        RX packets:238488 errors:0 dropped:0 overruns:0 frame:0
        TX packets:403217 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:100 RX bytes:153098921 (146.0 MB) TX
        bytes:261035246 (248.9 MB) Memory:fdfc0000-fdfe0000

lo      Link encap:Local Loopback
        inet addr:127.0.0.1 Mask:255.0.0.0
...
[me@linuxbox ~]$ netstat -r
Kernel IP routing table
Destination     Gateway     Genmask         Flags    MSS  Window  irtt Iface

192.168.1.0     *           255.255.255.0   U        0    0          0 eth0
default         192.168.1.1 0.0.0.0         UG       0    0          0 eth0
注:-ie等同于ifconfig  -r 显示内核网络路由表


[me@linuxbox ~]$ ftp fileserver
Connected to fileserver.localdomain.
220 (vsFTPd 2.0.1)
Name (fileserver:me): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub/cd\_images/Ubuntu-8.04
250 Directory successfully changed.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-rw-r-- 1 500 500 733079552 Apr 25 03:53 ubuntu-8.04- desktop-i386.iso
226 Directory send OK.
ftp> lcd Desktop
Local directory now /home/me/Desktop
ftp> get ubuntu-8.04-desktop-i386.iso
local: ubuntu-8.04-desktop-i386.iso remote: ubuntu-8.04-desktop-
i386.iso
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for ubuntu-8.04-desktop-
i386.iso (733079552 bytes).
226 File send OK.
733079552 bytes received in 68.56 secs (10441.5 kB/s)
ftp> bye
注:从匿名 FTP 服务器,其名字是 fileserver, 的/pub/_images/Ubuntu-8.04的目录下,使用 ftp 程
序下载一个 Ubuntu 系统映像文件。

[me@linuxbox ~]$ wget http://linuxcommand.org/index.php
--11:02:51-- http://linuxcommand.org/index.php
        => `index.php'
Resolving linuxcommand.org... 66.35.250.210
Connecting to linuxcommand.org|66.35.250.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

  [ <                        => ]        3,120       --.--K/s

11:02:51 (161.75 MB/s) - 'index.php' saved [3120]

[me@linuxbox ~]$ ssh remote-sys
The authenticity of host 'remote-sys (192.168.1.4)' can't be
established.
RSA key fingerprint is
41:ed:7a:df:23:19:bf:3c:a5:17:bc:61:b3:7f:d9:bb.
Are you sure you want to continue connecting (yes/no)?
Warning: Permanently added 'remote-sys,192.168.1.4' (RSA) to the list
of known hosts.
me@remote-sys's password:
Last login: Sat Aug 30 13:00:48 2008
注:连接到remote-sys的远程主机

[me@linuxbox ~]$ ssh bob@remote-sys
bob@remote-sys's password:
Last login: Sat Aug 30 13:03:21 2008
注:使用不同的账号进行来连接remote-sys

[me@linuxbox ~]$ ssh remote-sys free
me@twin4's password:
            total   used       free     shared buffers cached

Mem:        775536  507184   268352          0  110068 154596

-/+ buffers/cache: 242520  533016
Swap: 0 1572856 0 110068 154596
注:通过远程操作free命令

[me@linuxbox ~]$ ssh remote-sys 'ls \*' > dirlist.txt
me@twin4's password:
注:将远程的结果导入到本地。若加单引号则传入到远程端,看下段代码。
[me@linuxbox ~]$ ssh remote-sys 'ls * > dirlist.txt'

[me@linuxbox ~]$ scp remote-sys:document.txt .
me@remote-sys's password:
document.txt
100%        5581        5.5KB/s         00:00
注:从 remote-sys 远端系统的家目录下复制文档 document.txt,到我们本地系统的当前工作目录下

[me@linuxbox ~]$ sftp remote-sys
Connecting to remote-sys...
me@remote-sys's password:
sftp> ls
ubuntu-8.04-desktop-i386.iso
sftp> lcd Desktop
sftp> get ubuntu-8.04-desktop-i386.iso
Fetching /home/me/ubuntu-8.04-desktop-i386.iso to ubuntu-8.04-
desktop-i386.iso
/home/me/ubuntu-8.04-desktop-i386.iso 100% 699MB 7.4MB/s 01:35
sftp> bye
注:SSH 文件复制程序是 sftp,顾名思义,它是 ftp 程序的安全替代品。
发布了59 篇原创文章 · 获赞 11 · 访问量 1万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章