1. ping命令:测试网络连通性
ping 是常用的网络命令,主要通过 ICMP 协议进行网络探测,测试网络中主机的连通性。基本信息如下:
ping命令的常见选项:
1.1> ping IP/域名 ;在Linux中,ping命令会一直进行;使用"Ctrl+C"快捷键可以强行中止;
[root@redhat 桌面]# ping www.baidu.com
PING www.a.shifen.com (183.232.231.172) 56(84) bytes of data.
64 bytes from 183.232.231.172: icmp_seq=1 ttl=128 time=42.6 ms
64 bytes from 183.232.231.172: icmp_seq=2 ttl=128 time=40.1 ms
64 bytes from 183.232.231.172: icmp_seq=3 ttl=128 time=43.6 ms
64 bytes from 183.232.231.172: icmp_seq=4 ttl=128 time=42.4 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 11565ms
rtt min/avg/max/mdev = 40.107/42.195/43.656/1.311 ms
1.2> ping -c 次数 IP/域名,指定ping包的次数;
[root@redhat 桌面]# ping -c 3 www.baidu.com
PING www.a.shifen.com (183.232.231.172) 56(84) bytes of data.
64 bytes from 183.232.231.172: icmp_seq=1 ttl=128 time=145 ms
64 bytes from 183.232.231.172: icmp_seq=2 ttl=128 time=239 ms
64 bytes from 183.232.231.172: icmp_seq=3 ttl=128 time=221 ms
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2225ms
rtt min/avg/max/mdev = 145.643/202.089/239.584/40.628 ms
1.3>" -b"选项:后面加入广播地址,用于对整个网段进行探测;
PING 192.168.37.255 (192.168.37.255) 56(84) bytes of data.
64 bytes from 192.168.37.2: icmp_seq=1 ttl=128 time=0.617 ms
64 bytes from 192.168.37.2: icmp_seq=2 ttl=128 time=0.470 ms
64 bytes from 192.168.37.2: icmp_seq=3 ttl=128 time=0.474 ms
--- 192.168.37.255 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.470/0.520/0.617/0.070 ms
2. ifconfig命令:查看和设置网卡信息
ifconfig 是Linux中査看和临时修改 IP 地址的命令,基本信息如下:
2.1> 查看IP地址信息
[root@redhat 桌面]# ifconfig
eth1 Link encap:Ethernet HWaddr 00:0C:29:EF:E0:1D
inet addr:192.168.37.143 Bcast:192.168.37.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feef:e01d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2536 errors:0 dropped:0 overruns:0 frame:0
TX packets:1713 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:215114 (210.0 KiB) TX bytes:122177 (119.3 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:656 errors:0 dropped:0 overruns:0 frame:0
TX packets:656 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:60434 (59.0 KiB) TX bytes:60434 (59.0 KiB)
2.2> 临时配置IP地址:一旦主机重启,就会失效,如果需要长期有效,就需要修改配置文件;
[root@redhat 桌面]# ifconfig eth1 192.168.30.30
[root@redhat 桌面]# ifconfig eth1
eth1 Link encap:Ethernet HWaddr 00:0C:29:EF:E0:1D
inet addr:192.168.30.30 Bcast:192.168.30.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feef:e01d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2581 errors:0 dropped:0 overruns:0 frame:0
TX packets:1717 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:218111 (212.9 KiB) TX bytes:122513 (119.6 KiB)
2.3> 禁用或者重新激活网卡
[root@redhat 桌面]# ifconfig eth1 down
[root@redhat 桌面]# ifconfig eth1 up
3. mail命令:发送和接收电子邮件
mail 是Linux发送和接收电子邮件的命令,基本信息如下:
mail 收信方用户名,例如:给root用户写邮件,mail查看邮件;
[root@redhat 桌面]# mail root
Subject: test
nihao hello
EOT
[root@redhat 桌面]# mail
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/root": 8 messages 8 new
>N 1 Anacron Tue Mar 12 05:07 17/636 "Anacron job 'cron.dai"
N 2 Anacron Wed Mar 13 03:11 17/636 "Anacron job 'cron.dai"
N 3 Anacron Thu Mar 14 04:09 17/636 "Anacron job 'cron.dai"
N 4 Anacron Fri Mar 15 04:42 17/636 "Anacron job 'cron.dai"
N 5 Anacron Sat Mar 16 07:16 17/636 "Anacron job 'cron.dai"
N 6 Anacron Sat Mar 23 04:39 17/636 "Anacron job 'cron.dai"
N 7 Anacron Sun Mar 31 21:44 17/636 "Anacron job 'cron.dai"
N 8 root Tue Apr 2 20:00 18/588 "test"
& 8
Message 8:
From [email protected] Tue Apr 2 20:00:51 2019
Return-Path:
X-Original-To: root
Delivered-To: [email protected]
Date: Tue, 02 Apr 2019 20:00:50 +0800
To: [email protected]
Subject: test
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset=us-ascii
From: [email protected] (root)
Status: R
nihao hello
4. traceroute命令:显示数据包到主机之间的路径
traceroute命令可以显示数据包到主机间的路径,基本信息如下:
traceroute:路由跟踪命令,下图中*是目标禁止ping;
[root@redhat 桌面]# traceroute www.sina.com.cn
traceroute to www.sina.com.cn (183.232.24.222), 30 hops max, 60 byte packets
1 192.168.37.2 (192.168.37.2) 0.352 ms 0.776 ms 0.623 ms
2 * * *
3 * * *
4 * * *
5 * * *
6 * * *
7 * * *
8 * * *
5. netstat命令:查看网络状态
netstat 是网络状态查看命令,既可以查看到本机开启的端口,也可以查看有哪些客户端连接。netstat 命令的基本信息如下。
netstat命令常见的选项:
[root@redhat 桌面]# netstat -antl
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:37734 0.0.0.0:* LISTEN
tcp 0 0 :::111 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:631 :::* LISTEN
tcp 0 0 ::1:25 :::* LISTEN
tcp 0 0 :::32893 :::* LISTEN
查看本机路由表;
[root@redhat 桌面]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.37.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
0.0.0.0 192.168.37.2 0.0.0.0 UG 0 0 0 eth1
6. setup命令:配置网络
setup 命令的基本信息如下:
步骤如下:setup配置IP,网关信息(重启主机后,依然有效);
7. nslookup命令:进行域名与IP地址解析
nslookup命令的基本信息如下:
[root@redhat 桌面]# nslookup
> baidu.com
Server: 192.168.37.2
Address: 192.168.37.2#53
Non-authoritative answer:
Name: baidu.com
Address: 220.181.57.216
Name: baidu.com
Address: 123.125.114.144
> server
Default server: 192.168.37.2
Address: 192.168.37.2#53
8. route命令:查看路由表条目
route命令的基本信息如下:
[root@redhat 桌面]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.37.0 * 255.255.255.0 U 1 0 0 eth1
default 192.168.37.2 0.0.0.0 UG 0 0 0 eth1