pingLinux简单命令行:文件/目录,sudo,包管理

命令行学习笔记:网络相关命令

2016-12-19  本文已影响110人  z嘉嘉嘉

学习内容

网络相关:ping, telnet, curl, netstat,修改hosts

个人总结


命令格式:
ping [参数] [主机名或IP地址]

功能:

如果主机正在运行并连在网上,它就对回送信号进行响应。每个回送信号请求包含一个网际协议(IP)和 ICMP 头,后面紧跟一个 tim 结构,以及来填写这个信息包的足够的字节。缺省情况是连续发送回送信号请求直到接收到中断信号(Ctrl-C)。

参数:

-d 使用Socket的SO_DEBUG功能。
-f  极限检测。大量且快速地送网络封包给一台机器,看它的回应。
-n 只输出数值。
-q 不显示任何传送封包的信息,只显示最后的结果。
-r 忽略普通的Routing Table,直接将数据包送到远端主机上。通常是查看本机的网络接口是否有问题。
-R 记录路由过程。
-v 详细显示指令的执行过程。
<p>-c 数目:在发送指定数目的包后停止。
-i 秒数:设定间隔几秒送一个网络封包给一台机器,预设值是一秒送一次。
-I 网络界面:使用指定的网络界面送出数据包。
-l 前置载入:设置在送出要求信息之前,先行发出的数据包。
-p 范本样式:设置填满数据包的范本样式。
-s 字节数:指定发送的数据字节数,预设值是56,加上8字节的ICMP头,一共是64ICMP数据字节。
-t 存活数值:设置存活数值TTL的大小。

实例:

➜  ~ ping 192.168.1.99
PING 192.168.1.99 (192.168.1.99) 56(84) bytes of data.
From 192.168.1.196 icmp_seq=1 Destination Host Unreachable
From 192.168.1.196 icmp_seq=2 Destination Host Unreachable
From 192.168.1.196 icmp_seq=3 Destination Host Unreachable
From 192.168.1.196 icmp_seq=4 Destination Host Unreachable
From 192.168.1.196 icmp_seq=5 Destination Host Unreachable
From 192.168.1.196 icmp_seq=6 Destination Host Unreachable
From 192.168.1.196 icmp_seq=7 Destination Host Unreachable
From 192.168.1.196 icmp_seq=8 Destination Host Unreachable
From 192.168.1.196 icmp_seq=9 Destination Host Unreachable
^C
--- 192.168.1.99 ping statistics ---
12 packets transmitted, 0 received, +9 errors, 100% packet loss, time 11064ms
pipe 3
➜  ~ ping 192.168.1.123
PING 192.168.1.123 (192.168.1.123) 56(84) bytes of data.
64 bytes from 192.168.1.123: icmp_seq=1 ttl=128 time=1.65 ms
64 bytes from 192.168.1.123: icmp_seq=2 ttl=128 time=0.844 ms
64 bytes from 192.168.1.123: icmp_seq=3 ttl=128 time=0.959 ms
64 bytes from 192.168.1.123: icmp_seq=4 ttl=128 time=0.736 ms
64 bytes from 192.168.1.123: icmp_seq=5 ttl=128 time=0.732 ms
^C
--- 192.168.1.123 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4002ms
rtt min/avg/max/mdev = 0.732/0.984/1.653/0.346 ms
➜  ~ ping -b 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.211 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.225 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.222 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=0.182 ms
64 bytes from 192.168.1.1: icmp_seq=5 ttl=64 time=0.464 ms
64 bytes from 192.168.1.1: icmp_seq=6 ttl=64 time=0.224 ms
^C
--- 192.168.1.1 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 4999ms
rtt min/avg/max/mdev = 0.182/0.254/0.464/0.096 ms

➜  ~ ping -c 3 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.22 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.360 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.382 ms

--- 192.168.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.360/0.654/1.221/0.401 ms
➜  ~ ping -i 0.5 192.168.1.123
PING 192.168.1.123 (192.168.1.123) 56(84) bytes of data.
64 bytes from 192.168.1.123: icmp_seq=1 ttl=128 time=1.14 ms
64 bytes from 192.168.1.123: icmp_seq=2 ttl=128 time=0.999 ms
64 bytes from 192.168.1.123: icmp_seq=3 ttl=128 time=0.822 ms
64 bytes from 192.168.1.123: icmp_seq=4 ttl=128 time=0.952 ms
64 bytes from 192.168.1.123: icmp_seq=5 ttl=128 time=0.847 ms
64 bytes from 192.168.1.123: icmp_seq=6 ttl=128 time=0.957 ms
64 bytes from 192.168.1.123: icmp_seq=7 ttl=128 time=0.848 ms
^C
--- 192.168.1.123 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 3001ms
rtt min/avg/max/mdev = 0.822/0.938/1.141/0.103 ms

➜  ~ ping -c5 -i 0.5 192.168.1.123
PING 192.168.1.123 (192.168.1.123) 56(84) bytes of data.
64 bytes from 192.168.1.123: icmp_seq=1 ttl=128 time=0.775 ms
64 bytes from 192.168.1.123: icmp_seq=2 ttl=128 time=0.941 ms
64 bytes from 192.168.1.123: icmp_seq=3 ttl=128 time=0.888 ms
64 bytes from 192.168.1.123: icmp_seq=4 ttl=128 time=0.761 ms
64 bytes from 192.168.1.123: icmp_seq=5 ttl=128 time=0.991 ms

--- 192.168.1.123 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.761/0.871/0.991/0.092 ms

➜  ~ ping -c 5 www.sina.com
PING cernetnews.sina.com.cn (121.194.0.239) 56(84) bytes of data.
64 bytes from 121.194.0.239: icmp_seq=1 ttl=50 time=21.3 ms
64 bytes from 121.194.0.239: icmp_seq=2 ttl=50 time=18.7 ms
64 bytes from 121.194.0.239: icmp_seq=3 ttl=50 time=17.8 ms
64 bytes from 121.194.0.239: icmp_seq=4 ttl=50 time=19.7 ms
64 bytes from 121.194.0.239: icmp_seq=5 ttl=50 time=18.3 ms

--- cernetnews.sina.com.cn ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4007ms
rtt min/avg/max/mdev = 17.860/19.218/21.344/1.248 ms

➜  ~ ping -i 0.5 -c 5 -s 512 -t 255 192.168.1.123
PING 192.168.1.123 (192.168.1.123) 512(540) bytes of data.
520 bytes from 192.168.1.123: icmp_seq=1 ttl=128 time=1.64 ms
520 bytes from 192.168.1.123: icmp_seq=2 ttl=128 time=1.05 ms
520 bytes from 192.168.1.123: icmp_seq=3 ttl=128 time=1.68 ms
520 bytes from 192.168.1.123: icmp_seq=4 ttl=128 time=1.45 ms
520 bytes from 192.168.1.123: icmp_seq=5 ttl=128 time=1.66 ms

--- 192.168.1.123 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 2004ms
rtt min/avg/max/mdev = 1.051/1.500/1.683/0.239 ms


命令格式
telnet [参数][主机]

功能
执行 telnett 命令开启终端机器阶段作业,并登入远端主机。

参数

-8 允许使用8位字符资料,包括输入与输出。
-a 尝试自动登入远端系统。
-b<主机别名> 使用别名指定远端主机名称。
-c 不读取用户专属目录里的.telnetrc文件。
-d 启动排错模式。
-e<脱离字符> 设置脱离字符。
-E 滤除脱离字符。
-f 此参数的效果和指定"-F"参数相同。
-F 使用Kerberos V5认证时,加上此参数可把本地主机的认证数据上传到远端主机。
-k<域名> 使用Kerberos认证时,加上此参数让远端主机采用指定的领域名,而非该主机的域名。
-K 不自动登入远端主机。
-l<用户名称> 指定要登入远端主机的用户名称。
-L 允许输出8位字符资料。
-n<记录文件> 指定文件记录相关信息。
-r 使用类似rlogin指令的用户界面。
-S<服务类型> 设置telnet连线所需的IP TOS信息。
-x 假设主机有支持数据加密的功能,就使用它。
-X<认证形态> 关闭指定的认证形态。

实例

zhyingjia@zhyingjia-Inspiron-5437:~$ telnet 192.168.1.243 22
Trying 192.168.1.243...
Connected to 192.168.1.243.
Escape character is '^]'.
SSH-2.0-OpenSSH_5.3

Protocol mismatch.
Connection closed by foreign host.


➜  newDir ls
➜  newDir curl -o shouhui.html http://www.jianshu.com/p/5dcce74fc415
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 41120  100 41120    0     0  82488      0 --:--:-- --:--:-- --:--:-- 82404
➜  newDir ls
shouhui.html
➜  newDir 

➜  newDir curl -O http://www.jianshu.com/p/5ead3cfb630b                 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 47028  100 47028    0     0    97k      0 --:--:-- --:--:-- --:--:--   97k
➜  newDir ls
5ead3cfb630b  shouhui.html
➜  newDir 

➜  newDir curl -c ./cookie_c.txt -F log=aaaa -F pwd=****** http://www.2cto.com /wp-login.php
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx</center>
</body>
</html>
curl: (3) <url> malformed

➜  newDir ls
5ead3cfb630b  shouhui.html
➜  newDir curl -O -# http://www.jianshu.com/p/230efbd68016
######################################################################## 100.0%
➜  newDir ls
230efbd68016  5ead3cfb630b  shouhui.html
➜  newDir 


实例:

netstat

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      1 192.168.1.197:38870     www.google.com.gr:https SYN_SENT   
tcp        1      1 192.168.1.197:48054     121.194.7.192:http      LAST_ACK   
tcp        0      1 192.168.1.197:38854     www.google.com.gr:https SYN_SENT   
tcp        0      1 192.168.1.197:38860     www.google.com.gr:https SYN_SENT   
tcp        0      1 192.168.1.197:38856     www.google.com.gr:https SYN_SENT   
tcp        0      1 192.168.1.197:34186     prg03s05-in-f14.1:https SYN_SENT   
tcp        1      1 192.168.1.197:36790     121.194.7.19:http       LAST_ACK   
tcp        0      1 192.168.1.197:38858     www.google.com.gr:https SYN_SENT   
tcp        0      1 192.168.1.197:38880     www.google.com.gr:https SYN_SENT   
tcp        0      1 192.168.1.197:38852     www.google.com.gr:https SYN_SENT   
tcp        0      1 192.168.1.197:38864     www.google.com.gr:https SYN_SENT   
tcp        0      1 192.168.1.197:38884     www.google.com.gr:https SYN_SENT   
tcp        1      1 192.168.1.197:45486     23.248.163.147:http     LAST_ACK   
tcp        0      0 192.168.1.197:50202     hn.kd.ny.adsl:82        ESTABLISHED
 
   ... ... 
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ]         DGRAM                    22602    /run/user/1000/systemd/notify
unix  8      [ ]         DGRAM                    568      /run/systemd/journal/socket
unix  17     [ ]         DGRAM                    11639    /run/systemd/journal/dev-log
unix  2      [ ]         DGRAM                    11642    /run/systemd/journal/syslog
unix  3      [ ]         SEQPACKET  CONNECTED     31602    @0001b
unix  2      [ ]         DGRAM                    17911    /run/wpa_supplicant/wlp6s0
unix  3      [ ]         DGRAM                    556      /run/systemd/notify
unix  3      [ ]         SEQPACKET  CONNECTED     27350    
unix  3      [ ]         STREAM     CONNECTED     26055    /run/systemd/journal/stdout
unix  3      [ ]         STREAM     CONNECTED     24124    
unix  3      [ ]         STREAM     CONNECTED     23298    @/tmp/dbus-sYzUcwM148
unix  3      [ ]         STREAM     CONNECTED     25062    @/tmp/dbus-sYzUcwM148
unix  3      [ ]         STREAM     CONNECTED     22310    
unix  3      [ ]         STREAM     CONNECTED     29561    
unix  3      [ ]         STREAM     CONNECTED     23338    @/tmp/dbus-NFWQkgLokd
unix  3      [ ]         STREAM     CONNECTED     24598    @/tmp/.X11-unix/X0
... ... 

说明:
netstat 命令输出结果分为两部分:

1. Active Internet connections : 有源 TCP 连接 
          Recv-Q : 接受队列
          Send-Q : 发送队列 (这两列一般情况下为0,如果为1,则表示有软件包在队列中堆积)
2.Active UNIX domain sockets : 有源UNIX域套接口(和网络套接字一样,但是只能用于本机通信,性能可以提高一倍)
       Proto  : 显示连接使用的协议
      RefCnt  :    表示连接到本套接口上的进程号
       Types  :    显示套接口的类型
       State   : 显示套接口当前的状态
         Path  : 表示连接到套接口的其它进程使用的路径名

状态字段说明

LISTEN:侦听来自远方的TCP端口的连接请求
SYN-SENT:再发送连接请求后等待匹配的连接请求(如果有大量这样的状态包,检查是否中招了)
SYN-RECEIVED:再收到和发送一个连接请求后等待对方对连接请求的确认(如有大量此状态,估计被flood攻击了)
ESTABLISHED:代表一个打开的连接
FIN-WAIT-1:等待远程TCP连接中断请求,或先前的连接中断请求的确认
FIN-WAIT-2:从远程TCP等待连接中断请求
CLOSE-WAIT:等待从本地用户发来的连接中断请求
CLOSING:等待远程TCP对连接中断的确认
LAST-ACK:等待原来的发向远程TCP的连接中断请求的确认(不是什么好东西,此项出现,检查是否被攻击)
TIME-WAIT:等待足够的时间以确保远程TCP接收到连接中断请求的确认
CLOSED:没有任何连接状态
➜  ~ netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 localhost:mysql         *:*                     LISTEN     
tcp        0      0 zhyingjia-Inspir:domain *:*                     LISTEN     
tcp        0      0 *:ssh                   *:*                     LISTEN     
tcp        0      1 192.168.1.197:39094     www.google.com.gr:https SYN_SENT   
tcp        0      0 192.168.1.197:56872     106.75.2.241:http       ESTABLISHED
tcp        0      1 192.168.1.197:39088     www.google.com.gr:https SYN_SENT   
tcp        0      1 192.168.1.197:39092     www.google.com.gr:https SYN_SENT   
tcp        1      1 192.168.1.197:45848     23.248.163.147:http     LAST_ACK   
tcp        0      1 192.168.1.197:39098     www.google.com.gr:https SYN_SENT  

实例:

➜  ~ ssh -l root 192.168.1.222
root@192.168.1.222's password: 


BusyBox v1.20.2 () built-in shell (ash)
Enter 'help' for a list of built-in commands.

this board is EasyARM-iMX283
root@EasyARM-iMX28x ~# 

➜  ~ ssh root@192.168.1.222
root@192.168.1.222's password: 


BusyBox v1.20.2 () built-in shell (ash)
Enter 'help' for a list of built-in commands.

this board is EasyARM-iMX283
root@EasyARM-iMX28x ~# 

➜  ~ ssh -l root -p 22 192.168.1.222
root@192.168.1.222's password: 


BusyBox v1.20.2 () built-in shell (ash)
Enter 'help' for a list of built-in commands.

this board is EasyARM-iMX283
root@EasyARM-iMX28x ~# 

➜  ~ ssh -p 22 root@192.168.1.222
root@192.168.1.222's password: 


BusyBox v1.20.2 () built-in shell (ash)
Enter 'help' for a list of built-in commands.

this board is EasyARM-iMX283
root@EasyARM-iMX28x ~# 


➜  ~ sudo vim /etc/ssh/sshd_config
//  修改端口
修改 Port 22  ->  Port 23   :wq 保存并退出
➜  ~ cat /etc/ssh/sshd_config
# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 23
# Use these options to restrict which interfaces/protocols sshd will bind to
  ... ... 
➜  ~ service sshd restart           
➜  ~ ssh root@192.168.1.222
root@192.168.1.222's password: 


BusyBox v1.20.2 () built-in shell (ash)
Enter 'help' for a list of built-in commands.

this board is EasyARM-iMX283
root@EasyARM-iMX28x ~# 


 //  发送方
[root@hadoop1 ~]# scp client1.c zhyingjia@192.168.1.196:
The authenticity of host '192.168.1.196 (192.168.1.196)' can't be established.
RSA key fingerprint is b4:8a:27:96:37:e5:27:4b:67:9f:6f:bc:51:c3:9e:f3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.196' (RSA) to the list of known hosts.
zhyingjia@192.168.1.196's password: 
client1.c                                     100% 5320     5.2KB/s   00:00  


[root@hadoop1 ~]# scp -r testDir/ zhyingjia@192.168.1.196:
zhyingjia@192.168.1.196's password: 
[root@hadoop1 ~]# ls

// 接收前
➜  /home ls 
zhyingjia
➜  /home cd zhyingjia 
➜  ~ ls
Book              IdeaProjects        Public            Videos
client1.c         logs                Ruby              WebstormProjects
Desktop           Music               RubymineProjects  wince3+1
Documents         newDir              sshd.txt
Downloads         newRamlProject      Templates
Pictures     
     
// 接收后
➜  /home ls 
zhyingjia
➜  /home cd zhyingjia 
➜  ~ ls
Book              IdeaProjects        Public            Videos
client1.c         logs                Ruby              WebstormProjects
Desktop           Music               RubymineProjects  wince3+1
Documents         newDir              sshd.txt
Downloads         newRamlProject      Templates
Pictures          testDir

// 文件夹已经传送过来。

参考

上一篇下一篇

猜你喜欢

热点阅读