Linux学习笔记(8)Linux常用命令之网络命令

时间:2023-02-25 09:42:16

(1)write

write命令用于给指定用户发信息以Ctrl+D保存结束,所在路径为/usr/bin/write,其语法格式为:

write [用户名]

注:只能给在线用户发送

例:新建ws用户,root远程端向ws远程端发送hello信息。

root端:

[root@localhost cdrom]# write ws

hello

ws端:

[ws@localhost ~]$

Message from root@localhost.localdomain on pts/1 at 03:58 ...

helloEOF

其中EOF表示结束。

(2)wall

wall命令用于发送广播信息,英文原意为write all,所在路径为/usr/bin/wall,其语法格式为:

wall [message]

例:在root远程端向全体在线用户发送hello消息:

root端:

[root@localhost cdrom]# wall hello

[root@localhost cdrom]#

Broadcast message from root@localhost.localdomain (pts/1) (Fri Jan  2 04:05:08 2015):

hello

ws端:

[ws@localhost ~]$

Broadcast message from root@localhost.localdomain (pts/1) (Fri Jan  2 04:05:08 2015):

hello

(3)ping

ping命令用于测试网络连通性,所在路径为/bin/ping,其语法格式为:

ping 选项 IP地址

其中-c选项指定发送次数

例如:测试回环地址127.0.0.1,发送次数设定为3次:

[root@localhost cdrom]# ping -c 3 127.0.0.1

PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.

64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.274 ms

64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.072 ms

64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.070 ms

 

--- 127.0.0.1 ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 1999ms

rtt min/avg/max/mdev = 0.070/0.138/0.274/0.096 ms

(4)ifconfig

ifconfig命令用于查看和设置网卡信息,英文原意为interface configure,所在路径为/sbin/ifconfig,其语法格式为:

ifconfig 网卡 IP地址

注:ifconfig只是暂时的设置IP地址,等到下次重启系统时,该配置即消除

(5)mail

mail命令用于查看和发送电子邮件,特点是用户不在线也可以进行发送,所在路径为/bin/mail,其语法格式为:

mail [用户名]

例:root远程端向ws远程端发送邮件

root远程端:

[root@localhost cdrom]# mail ws

Subject: hello

hello i am wsEOT

[root@localhost cdrom]#

ws远程端:

[ws@localhost ~]$ mail

Heirloom Mail version 12.4 7/29/08.  Type ? for help.

"/var/spool/mail/ws": 1 message 1 new

>N  1 root                  Fri Jan  2 04:17  18/606   "hello"

&

输入1即可查看该邮件:

& 1

Message  1:

From root@localhost.localdomain  Fri Jan  2 04:17:44 2015

Return-Path: <root@localhost.localdomain>

X-Original-To: ws

Delivered-To: ws@localhost.localdomain

Date: Fri, 02 Jan 2015 04:17:43 +0800

To: ws@localhost.localdomain

Subject: hello

User-Agent: Heirloom mailx 12.4 7/29/08

Content-Type: text/plain; charset=us-ascii

From: root@localhost.localdomain (root)

Status: R

 

hello i am ws

 

&

(6)last

last命令列出目前与过去登入系统的用户信息,所在路径为/usr/bin/last,其语法格式为:

last

例:

[root@localhost cdrom]# last

ws      pts/0       110.13.4.109      Fri Jan  2 03:57   still logged in  

ws      pts/0       110.13.4.109      Fri Jan  2 03:56 - 03:57  (00:00)   

ws      pts/0       110.13.4.109      Thu Jan  1 22:59 - 00:03  (01:03)   

root     pts/1       110.13.4.109      Thu Jan  1 18:44   still logged in  

root     pts/0       110.13.4.109      Thu Jan  1 18:38 - 20:49  (02:11)   

root     tty1                         Thu Jan  1 18:36   still logged in  

reboot   system boot  2.6.32-431.el6.i Thu Jan  1 18:35 - 04:22  (09:47)   

root     pts/0       110.13.4.109      Thu Jan  1 17:43 - crash  (00:51)   

root     tty1                         Thu Jan  1 17:41 - crash  (00:54)   

reboot   system boot  2.6.32-431.el6.i Thu Jan  1 17:38 - 04:22  (10:43)    

root     pts/0       110.13.4.236      Tue Oct 21 20:24 - crash (71+21:13) 

root     tty1                        Tue Oct 21 20:23 - crash (71+21:15) 

reboot   system boot  2.6.32-431.el6.i Tue Oct 21 18:59 - 04:22 (72+09:22) 

root     pts/0       110.13.4.236      Tue Oct 21 06:31 - 06:32  (00:00)   

root     tty1                          Tue Oct 21 06:29 - crash  (12:30)   

reboot   system boot  2.6.32-431.el6.i Tue Oct 21 06:27 - 04:22 (72+21:54) 

 

wtmp begins Tue Oct 21 06:27:29 2014

(7)lastlog

lastlog命令用于检查某特定用户上次登录的时间,所在路径为/usr/bin/lastlog,其语法格式为:

lastlog

例:lastlog或last -u 500

[root@localhost cdrom]# lastlog -u 500

Username       Port     From             Latest

ws             pts/0   110.13.4.109      Fri Jan  2 03:57:07 +0800 2015

(8)traceroute

traceroute命令用于显示数据包到主机间的路径信息,所在路径为/bin/traceroute,其语法格式为:

traceroute 网址

(9)netstat

netstat命令用于显示网络相关信息,所在路径为/bin/netstat,其语法格式为:

netstat [选项]

其中,-t选项表示TCP协议,-u选项表示UDP协议,-l表示监听,-r表示路由,-n表示显示IP地址和端口号

如:查看本地监听端口-----netstat -tlun

    查看本机所有的网络连接-----netstat -an

    查看本机路由表-----netstat -rn

(10)setup

setup命令用于配置网络,其特点是永久生效,与ifconfig不同,所在路径为/usr/bin/setup,其语法格式为:

setup

注:该命令是红帽系列的专有命令

(11)mount

mount命令用于挂载,所在路径为/bin/mount,其语法格式为:

mount [-t 文件系统] 设备文件名 挂载点

例:在/mnt目录下创建cdrom文件夹作为挂载点,然后选择ISO镜像,然后进行挂载:

[root@localhost ~]# mkdir /mnt/cdrom

[root@localhost ~]# mount /dev/sr0 /mnt/cdrom/

mount: block device /dev/sr0 is write-protected, mounting read-only

[root@localhost ~]# ls /mnt/cdrom/

autorun.inf  casper  EFI   isolinux    pics  preseed           ubuntu

boot    dists   install  md5sum.txt  pool  README.diskdefines  wubi.exe

[root@localhost ~]# umount /dev/sr0