- 使用基本网络工具
当配置好网络之后,就可以使用系统提供的网络程序来访问网络,如使用ftp来从远程计算机上下载文件、telnet登录上远程系统等。freebsd下不但提供了这些普通的网络应用程序,而且还提供了相当丰富网络工具,帮助进行判断网络状态,发现网络故障。 最基本的查看本地网络设置的程序,包括前面提到的设置程序ifconfig、route,以及查看网络状态的程序netstat。还有另外的一些程序,可以用来判断网络连接状态。 前面提到的netstat的用法是使用-r参数来获得路由器的信息,而不使用这个参数启动netstat将报告当前的连接状态,包括tcp/ip连接和unix socket连接。
# netstat active internet connections proto recv-q send-q local address foreign address (state) tcp 0 2 wb.online.ha.cn.telne 1030 established tcp 0 0 wb.online.ha.cn.49157 wcarchive.cdrom..20 established tcp 0 0 wb.online.ha.cn.1139 wcarchive.cdrom..ftp established tcp 0 0 wb.online.ha.cn.telne 1029 established tcp 56 0 wb.online.ha.cn.1138 wcarchive.cdrom..ftp close_wait tcp 0 0 wb.online.ha.cn.telne 1028 established tcp 0 0 wb.online.ha.cn.telne 1027 established tcp 0 0 wb.online.ha.cn.1101 email.9999 established active unix domain sockets address type recv-q send-q inode conn refs nextref addr f458af00 dgram 0 0 0 f4571fc0 0 f458ae40 f458ae40 dgram 0 0 0 f4571fc0 0 f458af40 f458af40 dgram 0 0 0 f4571fc0 0 f458af80 f458af80 dgram 0 0 0 f4571fc0 0 f458afc0 f458afc0 dgram 0 0 0 f4571fc0 0 0 f4571fc0 dgram 0 0 f45705c0 0 f458af00 0 /var/run/log |
可以使用ping来判断与远程计算机是否能够连通。
$ ping ftp.freebsd.org ping wcarchive.cdrom.com (209.155.82.18): 56 data bytes 64 bytes from 209.155.82.18: icmp_seq=1 ttl=240 time=520.726 ms 64 bytes from 209.155.82.18: icmp_seq=2 ttl=240 time=773.465 ms ^c |
要想知道这台计算机是怎样和远程计算机相连接的,可以使用traceroute来获得从本机达到远程计算机所经过的路由器,以及到达各个路由器的开销等信息。
$ traceroute pku.edu.cn traceroute to sun1000e.pku.edu.cn (162.105.254.12), 30 hops max, 40 byte packets 1 202.102.245.1 (202.102.245.1) 1.078 ms 0.862 ms 0.850 ms 2 202.102.235.165 (202.102.235.165) 157.337 ms 157.957 ms 174.054 ms 3 202.97.26.217 (202.97.26.217) 134.037 ms 57.994 ms 55.602 ms 4 1s7-rtr1-r-1-hbwh.cn.net (202.97.26.165) 274.626 ms 120.154 ms 580.097 ms 5 202.97.10.113 (202.97.10.113) 623.421 ms 888.556 ms 794.748 ms 6 6a05-rtr2-c-1-bjbj.cn.net (202.97.1.189) 411.728 ms 247.819 ms 245.688 ms 7 202.97.9.1 (202.97.9.1) 762.538 ms 945.893 ms 920.904 ms 8 202.97.8.254 (202.97.8.254) 1181.508 ms 1107.783 ms 374.649 ms 9 1f0-rtr1-r-1-bjbj.cn.net (202.97.2.14) 960.674 ms 635.770 ms 700.182 ms 10 202.97.16.190 (202.97.16.190) 391.926 ms 214.433 ms 721.839 ms 11 * 202.112.63.100 (202.112.63.100) 313.066 ms * 12 * * * 13 * * beijing-rgw-lan.cernet.net (202.112.1.66) 434.928 ms 14 * * * 15 * 202.112.5.194 (202.112.5.194) 282.973 ms 340.009 ms 16 sun1000e.pku.edu.cn (202.112.7.12) 827.202 ms * * |
由于traceroute会在网络上产生大量的数据流,因此一般不要频繁使用这个命令,以免造成无谓的网络流量。 为了获得从一个计算机名字获得其ip地址,或者从ip地址得到计算机名字,可以直接使用nslookup来查询dns服务器。
$ nslookup ftp.freebsd.org server: ns.hazzptt.net.cn address: 202.102.224.68 non-authoritative answer: name: wcarchive.cdrom.com address: 209.155.82.18 aliases: ftp.freebsd.org $ nslookup 209.155.82.18 server: ns.hazzptt.net.cn address: 202.102.224.68 name: wcarchive.cdrom.com address: 209.155.82.18 |
nslookup不仅能用于查询普通的ip地址,还可以查询其他更复杂的dns信息,如某个域的名字服务器的地址,邮件服务器地址等。
发表评论