Post

linux(CentOS7) 网络管理

网络基础知识以及网络管理内容

网络管理协议

好多概念知识,会拿出时间来讲解这张预留的空白

TCP/IP 协议概述

好多概念知识,会拿出时间来讲解这张预留的空白

OSI 参考模型

好多概念知识,会拿出时间来讲解这张预留的空白

包(packet)

好多概念知识,会拿出时间来讲解这张预留的空白

网络字节顺序

好多概念知识,会拿出时间来讲解这张预留的空白

地址解析协议(ARP)

好多概念知识,会拿出时间来讲解这张预留的空白

UTP 与 ICMP 协议简介

好多概念知识,会拿出时间来讲解这张预留的空白

网络管理命令

ping

  • 测试是否通
1
2
3
4
5
6
7
8
9
[root@Cc ~]# ping lichaocheng.top
PING lichaocheng.top (60.205.176.110) 56(84) bytes of data.
64 bytes from 60.205.176.110 (60.205.176.110): icmp_seq=1 ttl=64 time=0.621 ms
64 bytes from 60.205.176.110 (60.205.176.110): icmp_seq=2 ttl=64 time=0.671 ms
64 bytes from 60.205.176.110 (60.205.176.110): icmp_seq=3 ttl=64 time=0.659 ms
--- lichaocheng.top ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.621/0.650/0.671/0.029 ms
[root@Cc ~]#
  • ping 指定次数
1
2
3
4
5
6
7
8
9
[root@Cc ~]# ping -c 2 lichaocheng.top
PING lichaocheng.top (60.205.176.110) 56(84) bytes of data.
64 bytes from 60.205.176.110 (60.205.176.110): icmp_seq=1 ttl=64 time=0.636 ms
64 bytes from 60.205.176.110 (60.205.176.110): icmp_seq=2 ttl=64 time=0.659 ms

--- lichaocheng.top ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.636/0.647/0.659/0.027 ms
[root@Cc ~]#
  • 指定时间间隔次数限制
1
2
3
4
5
6
7
8
9
[root@Cc ~]# ping -c 2 -i 0.01 lichaocheng.top
PING lichaocheng.top (60.205.176.110) 56(84) bytes of data.
64 bytes from 60.205.176.110 (60.205.176.110): icmp_seq=1 ttl=64 time=0.771 ms
64 bytes from 60.205.176.110 (60.205.176.110): icmp_seq=2 ttl=64 time=0.647 ms

--- lichaocheng.top ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 10ms
rtt min/avg/max/mdev = 0.647/0.709/0.771/0.062 ms
[root@Cc ~]#

配置网络显示网络状态【ifconfig

  • 查看
    • 第二行依次
      • 网卡 IP(云服务应该是内网 IP)
      • 子网掩码
      • 广播地址
1
2
3
4
5
6
7
8
9
[root@Cc ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.24.40.83  netmask 255.255.192.0  broadcast 172.24.63.255
        ether 00:16:3e:0c:d1:d9  txqueuelen 1000  (Ethernet)
        RX packets 4270799  bytes 923464936 (880.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4640135  bytes 1228322385 (1.1 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@Cc ~]#
  • 模拟添加一个网卡
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@Cc network-scripts]# cd /etc/sysconfig/network-scripts/
[root@Cc network-scripts]# cp ifcfg-eth0 ifcfg-eth1
[root@Cc network-scripts]# vim ifcfg-eth1
[root@Cc network-scripts]# vim ifcfg-eth1
[root@Cc network-scripts]# cat ifcfg-eth1
# 网卡名字
DEVICE=eth1LccTest
# ip地址
IPADDR=192.168.1.199
# 子网掩码
NETMASK=255.255.255.0
# 开机自启
ONBOOT=yes
# 网关地址
GATEWAY=172.24.63.253
[root@Cc network-scripts]#

最后systemctl restart networkservice network restart 失败 ,报了文件错误,那直接修改主网卡 eth0

  • 修改(需谨慎,高能操作修改前请先系统快照)

执行完成后直接退出 sshd 远程 ,最后 up 是开启的意思

1
2
[root@Cc network-scripts]# ifconfig eth0 172.24.40.88 netmask 255.255.192.0 up
连接断开

翻车 阿里云连接也失败找不到 ,只能快照或者联系阿里云技术服务,ping 服务器 超时,重启服务器

  • 最后还是没有修改成功,反而立马远程不了
    • 失败原因可能是我模拟添加网卡造成失败
    • 可能改了网卡地址,在阿里云我公网ip对应不到修改阿里云内网ip
    • 重启服务器之后,需要密钥才能登录,可能触发阿里云安全防控机制,阿里做了系统配置,我实例id 与 hostname,充值了网卡 其余的没有找到
    • 然之 需要密钥,我的做法是修改了密码,重启,之后远程登陆
    • 谨慎操作修改网卡地址
    • 可能修改成功了,也有可能是模拟网卡配置导致错误
1
2
3
4
5
6
7
8
9
10
[root@iz2zeb00z6vr5gix5utl11z lichaocheng.top.server]# ifconfig  eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.24.40.83  netmask 255.255.192.0  broadcast 172.24.63.255
        ether 00:16:3e:0c:d1:d9  txqueuelen 1000  (Ethernet)
        RX packets 5310  bytes 575889 (562.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6178  bytes 1043414 (1018.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@iz2zeb00z6vr5gix5utl11z lichaocheng.top.server]#
  • 我修改另一个网卡
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@Cc ~]# ifconfig docker
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 0.0.0.0
        ether 02:42:5f:3a:85:e0  txqueuelen 0  (Ethernet)
        RX packets 34  bytes 2663 (2.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15  bytes 7621 (7.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@Cc ~]# ifconfig docker0 172.24.40.88 netmask 255.255.192.0 up
[root@Cc ~]# ifconfig docker
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.24.40.88  netmask 255.255.192.0  broadcast 172.24.63.255
        ether 02:42:5f:3a:85:e0  txqueuelen 0  (Ethernet)
        RX packets 34  bytes 2663 (2.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15  bytes 7621 (7.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@Cc ~]# ifconfig docker0 hw ether 02:30:30:3f:5f:3a
[root@Cc ~]# ifconfig docker
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.24.40.88  netmask 255.255.192.0  broadcast 172.24.63.255
        ether 02:30:30:3f:5f:3a  txqueuelen 0  (Ethernet)
        RX packets 34  bytes 2663 (2.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15  bytes 7621 (7.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@Cc ~]#
  • 禁用与启用
1
2
[root@Cc ~]# ifconfig docker0 down
[root@Cc ~]# ifconfig docker0 up

路由表显示与修改【route

route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway][metric Metric]] [if Interface]]

参数说明
  • Command 指定您想运行的命令 (Add/Change/Delete/Print)
  • Destination 指定该路由的网络目标
  • mask Netmask 指定与网络目标相关的网络掩码(也被称作子网掩码)
  • Gateway 指定网络目标定义的地址集和子网掩码可以到达的前进或下一跃点 IP 地址
  • metric Metric 为路由指定一个整数成本值标(从 1 至 9999),当在路由表(与转发的数据包目标地址最匹配)的多个路由中进行选择时可以使用
  • if Interface 为可以访问目标的接口指定接口索引。若要获得一个接口列表和它们相应的接口索引,使用 route print 命令的显示功能。可以使用十进制或十六进
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-c 显示更多信息
-n 不解析名字
-v 显示详细的处理信息
-F 显示发送信息
-C 显示路由缓存
-f 清除所有网关入口的路由表。
-p 与add 命令一起使用时使路由具有永久性。

add:添加一条新路由。
del:删除一条路由。
-net:目标地址是一个网络。
-host:目标地址是一个主机。
netmask:当添加一个网络路由时,需要使用网络掩码。
gw:路由数据包通过网关。注意,你指定的网关必须能够达到。
metric:设置路由跳数。
显示示例
1
2
3
4
5
6
7
8
[root@Cc ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.24.63.253   0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 eth0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 docker0
[root@Cc ~]#
添加路由

注:如果服务器添加时 添加路由可以看到但是ping不通

  • 主机号 155.28.138.45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[root@Lgr ~]# curl ip.sb
115.28.138.45
[root@Lgr ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.31.220.39  netmask 255.255.240.0  broadcast 172.31.223.255
        ether 00:16:3e:08:80:34  txqueuelen 1000  (Ethernet)
        RX packets 4840062  bytes 2017732415 (1.8 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4449497  bytes 952525473 (908.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@Lgr ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.31.223.253  0.0.0.0         UG    0      0        0 eth0
10.200.192.0    0.0.0.0         255.255.240.0   U     0      0        0 mpgre0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.31.208.0    0.0.0.0         255.255.240.0   U     0      0        0 eth0
[root@Lgr ~]# route add -net 172.24.0.0 netmask 255.255.192.0 gw 172.31.223.225
[root@Lgr ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.31.223.253  0.0.0.0         UG    0      0        0 eth0
10.200.192.0    0.0.0.0         255.255.240.0   U     0      0        0 mpgre0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.24.0.0      172.31.223.225  255.255.192.0   UG    0      0        0 eth0
172.31.208.0    0.0.0.0         255.255.240.0   U     0      0        0 eth0
[root@Lgr ~]# route add -net 172.24.0.0 netmask 255.255.192.0 dev eth0
[root@Lgr ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.31.223.253  0.0.0.0         UG    0      0        0 eth0
10.200.192.0    0.0.0.0         255.255.240.0   U     0      0        0 mpgre0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 eth0
172.31.208.0    0.0.0.0         255.255.240.0   U     0      0        0 eth0
[root@Lgr ~]# ping 172.24.40.83
PING 172.24.40.83 (172.24.40.83) 56(84) bytes of data.
From 172.31.220.39 icmp_seq=1 Destination Host Unreachable
From 172.31.220.39 icmp_seq=2 Destination Host Unreachable
From 172.31.220.39 icmp_seq=3 Destination Host Unreachable
From 172.31.220.39 icmp_seq=4 Destination Host Unreachable
^C
--- 172.24.40.83 ping statistics ---
5 packets transmitted, 0 received, +4 errors, 100% packet loss, time 4000ms
pipe 4
[root@Lgr ~]#
# 可能是哪里配错了
  • 主机号 60.205.176.110
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[root@Cc ~]# curl ip.sb
60.205.176.110
[root@Cc ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.24.40.83  netmask 255.255.192.0  broadcast 172.24.63.255
        ether 00:16:3e:0c:d1:d9  txqueuelen 1000  (Ethernet)
        RX packets 158625  bytes 26310297 (25.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 161713  bytes 44000608 (41.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@Cc ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.24.63.253   0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 eth0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 docker0
[root@Cc ~]# route add -net 172.31.208.0  netmask 255.255.240.0 gw 172.24.63.225
[root@Cc ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.24.63.253   0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 docker0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 eth0
172.31.208.0    172.24.63.225   255.255.240.0   UG    0      0        0 docker0
[root@Cc ~]# route add -net 172.31.208.0  netmask 255.255.240.0 dev eth0
[root@Cc ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.24.63.253   0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 docker0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 eth0
172.31.208.0    0.0.0.0         255.255.240.0   U     0      0        0 eth0
[root@Cc ~]# ping 172.31.220.39
PING 172.31.220.39 (172.31.220.39) 56(84) bytes of data.
From 172.24.40.83 icmp_seq=1 Destination Host Unreachable
From 172.24.40.83 icmp_seq=2 Destination Host Unreachable
From 172.24.40.83 icmp_seq=3 Destination Host Unreachable
From 172.24.40.83 icmp_seq=4 Destination Host Unreachable
^C
--- 172.31.220.39 ping statistics ---
5 packets transmitted, 0 received, +4 errors, 100% packet loss, time 4000ms
pipe 4
[root@Cc ~]#
# 可能是哪里配错了
  • 两台服务器内网互通

两台服务器还是没有互通,可能要去响应云厂商,控制台添加,重启网卡服务service network restarty 还是没有

删除路由

注: 删除时不需要网关

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@Cc ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.24.63.253   0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 eth0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 docker0
172.31.208.0    172.24.40.83    255.255.240.0   UG    0      0        0 eth0
[root@Cc ~]# route del -net 172.31.208.0 netmask 255.255.240.0
[root@Cc ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.24.63.253   0.0.0.0         UG    0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 eth0
172.24.0.0      0.0.0.0         255.255.192.0   U     0      0        0 docker0
[root@Cc ~]#

[root@Lgr ~]# route del -net 172.24.0.0 netmask 255.255.192.0
屏蔽路由

[root@Lgr ~]# route add -net 10.10.10.128 netmask 255.255.255.128 reject

添加默认网关

[root@Cc ~]# route del default gw 192.168.40.2

添加某个 ip 路由

[root@Cc ~]# route add -host 192.168.40.1dev eth0

复制文件至其他系统【scp

1
2
3
4
5
[root@Cc ~]# scp
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2
[root@Cc ~]#
示例
  • Cc 主机
1
2
3
4
[root@Cc 10]# curl ip.sb;pwd
60.205.176.110
/root/RedHad/10
[root@Cc 10]#
  • Lgr 主机
1
2
3
4
[root@Lgr 10]# curl ip.sb;pwd
115.28.138.45
/root/RedHad/10
[root@Lgr 10]#
  • 在 Cc 主机创建和文件夹和查看 Lgr 主机状态
1
2
3
4
5
6
7
8
9
10
[root@Cc 10]# curl ip.sb;pwd;tree
60.205.176.110
/root/RedHad/10
.
├── scp
│   └── scpInTst.txt
└── scp.txt

1 directory, 2 files
[root@Cc 10]#
1
2
3
4
5
[root@Lgr 10]# curl ip.sb;pwd;tree
115.28.138.45
/root/RedHad/10
-bash: tree: command not found
[root@Lgr 10]#
  • Cc 复制到 Lgr【文件】
1
2
3
4
5
6
7
8
9
10
11
[root@Cc 10]# rm -r /root/.ssh/known_hosts
rm: remove regular file ‘/root/.ssh/known_hosts’? y
[root@Cc 10]# scp scp.txt root@115.28.138.45:/root/RedHad/10
The authenticity of host '115.28.138.45 (115.28.138.45)' can't be established.
ECDSA key fingerprint is SHA256:3yMka431yjt0thBqIeSCWPCfsy46wknMMJrO8QQe4cw.
ECDSA key fingerprint is MD5:30:23:91:24:0a:ca:b3:3c:d8:ec:a0:fe:cd:b5:43:0d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '115.28.138.45' (ECDSA) to the list of known hosts.
root@115.28.138.45's password:
scp.txt                                                    100%    0     0.0KB/s   00:00
[root@Cc 10]#
1
2
3
4
[root@Lgr 10]# ll
total 0
-rw-r--r-- 1 root root 0 Mar 29 13:46 scp.txt
[root@Lgr 10]#
  • 其他的就不操作了,看下面叫要说明
1
2
3
4
5
6
7
8
9
scp root@107.172.27.254:/home/test.txt .   //下载文件

scp test.txt root@107.172.27.254:/home  //上传文件

scp -r root@107.172.27.254:/home/test .  //下载目录

scp -r test root@107.172.27.254:/home   //上传目录

scp -P 9922 -r root@47.244.225.92:/home // 指定端口

复制文件至其他系统【rsync

rsyncLinux 系统下常用的数据镜像备份工具,不同主机之间同步文件,除了文件意外,还可以镜像保存整个目录树和文件系统,可以增量同步,并保持文件原来属性(权限、时间戳……),而且传输过程中是加密,保证了数据安全性

  • help
1
2
3
4
5
6
7
Usage: rsync [OPTION]... SRC [SRC]... DEST
  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST:DEST
  or   rsync [OPTION]... SRC [SRC]... [USER@]HOST::DEST
  or   rsync [OPTION]... SRC [SRC]... rsync://[USER@]HOST[:PORT]/DEST
  or   rsync [OPTION]... [USER@]HOST:SRC [DEST]
  or   rsync [OPTION]... [USER@]HOST::SRC [DEST]
  or   rsync [OPTION]... rsync://[USER@]HOST[:PORT]/SRC [DEST]
  • rsync 后续添加

显示网络连接、路由表或接口 【netstart

  • 显示 tpc
  • 显示 udp
  • 显示核心路由
  • 显示网络接口列表
  • 常用显示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
[root@Cc ~]# netstat -at
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:https           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:aequus          0.0.0.0:*               LISTEN
tcp        0      0 localhost:32000         0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:8836            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:http            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN
tcp        0      0 Cc:53354                100.100.30.26:http      ESTABLISHED
tcp        0      0 Cc:ssh                  113.118.200.16:7069     ESTABLISHED
tcp        0      0 localhost:31000         localhost:32000         ESTABLISHED
tcp        0      0 localhost:32000         localhost:31000         ESTABLISHED
tcp6       0      0 [::]:filenet-tms        [::]:*                  LISTEN
tcp6       0      0 [::]:cslistener         [::]:*                  LISTEN
tcp6       0      0 [::]:mysql              [::]:*                  LISTEN
tcp6       0      0 [::]:8180               [::]:*                  LISTEN
[root@Cc ~]# netstat -au
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
udp        0      0 0.0.0.0:bootpc          0.0.0.0:*
udp        0      0 Cc:ntp                  0.0.0.0:*
udp        0      0 Cc:ntp                  0.0.0.0:*
udp        0      0 localhost:ntp           0.0.0.0:*
udp        0      0 0.0.0.0:ntp             0.0.0.0:*
udp6       0      0 [::]:ntp                [::]:*
[root@Cc ~]# netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         gateway         0.0.0.0         UG        0 0          0 eth0
10.0.0.0        0.0.0.0         255.255.255.0   U         0 0          0 eth0
link-local      0.0.0.0         255.255.0.0     U         0 0          0 eth0
172.24.0.0      0.0.0.0         255.255.192.0   U         0 0          0 docker0
172.24.0.0      0.0.0.0         255.255.192.0   U         0 0          0 eth0
172.31.208.0    0.0.0.0         255.255.240.0   U         0 0          0 eth0
[root@Cc ~]# netstat -i
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
docker0          1500       34      0      0 0            30      0      0      0 BMRU
eth0             1500   660702      0      0 0        790356      0      0      0 BMRU
lo              65536    50832      0      0 0         50832      0      0      0 LRU
vethbb7d0dd      1500        8      0      0 0            23      0      0      0 BMRU
vethf4f0960      1500       26      0      0 0            38      0      0      0 BMRU
[root@Cc ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      923/nginx: master p
tcp        0      0 0.0.0.0:23456           0.0.0.0:*               LISTEN      1425/sshd
tcp        0      0 127.0.0.1:32000         0.0.0.0:*               LISTEN      1199/java
tcp        0      0 0.0.0.0:8836            0.0.0.0:*               LISTEN      923/nginx: master p
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      824/redis-server 0.
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      923/nginx: master p
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1425/sshd
tcp6       0      0 :::32768                :::*                    LISTEN      1731/docker-proxy-c
tcp6       0      0 :::9000                 :::*                    LISTEN      1746/docker-proxy-c
tcp6       0      0 :::3306                 :::*                    LISTEN      1508/mysqld
tcp6       0      0 :::8180                 :::*                    LISTEN      3090/./server
[root@Cc ~]#

探测至目的地址的路由信息【traceroute

显示本机到 baidu.com 所经过的路由

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@Cc ~]# traceroute -n baidu.com
traceroute to baidu.com (220.181.38.148), 30 hops max, 60 byte packets
 1  * * *
 2  * * *
 3  11.220.31.154  1.371 ms 11.220.30.130  0.920 ms 11.220.30.138  3.912 ms
 4  11.218.196.254  1.254 ms 11.204.180.122  1.597 ms 11.218.196.254  1.435 ms
 5  116.251.117.10  1.938 ms 42.120.243.82  1.842 ms 116.251.117.2  2.458 ms
 6  116.251.112.153  1.454 ms 116.251.94.17  2.001 ms 116.251.112.205  13.491 ms
 7  36.110.169.221  2.931 ms 36.110.169.101  3.467 ms 106.38.196.253  3.093 ms
 8  * 36.110.244.57  3.801 ms 36.110.244.49  3.765 ms
 9  220.181.182.178  3.718 ms * *
10  220.181.17.90  3.963 ms  4.313 ms 220.181.182.170  3.559 ms
11  * * *
14  * * *
………………………………
29  * * *
30  * * *
[root@Cc ~]#

域名不可达,最大 30 跳

测试登录、控制远程【telnet

找不到命令 ,可以连接互联网情况下使用yum install telnet安装

  • 成功
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@Cc ~]# telnet 115.28.138.41 22
Trying 115.28.138.41...
Connected to 115.28.138.41.
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4
test sshd
Protocol mismatch.
Connection closed by foreign host.
[root@Cc ~]# telnet baidu.com 80
Trying 39.156.69.79...
\Connected to baidu.com.
Escape character is '^]'.
Connection closed by foreign host.
[root@Cc ~]#
  • 失败
[root@Cc ~]# telnet 192.168.1.12 22
Trying 192.168.1.12...

下载网络文件【wget

  • 下载文件

wget [地址]

  • 断点续传

wget -c

  • 批量下载

下载文件中 一些列网址 wget -i download.txt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
[root@Cc ~]# wget --help;
GNU Wget 1.14,非交互式的网络文件下载工具。
用法: wget [选项]... [URL]...

长选项所必须的参数在使用短选项时也是必须的。

启动:
  -V,  --version           显示 Wget 的版本信息并退出。
  -h,  --help              打印此帮助。
  -b,  --background        启动后转入后台。
  -e,  --execute=COMMAND   运行一个“.wgetrc”风格的命令。

日志和输入文件:
  -o,  --output-file=FILE    将日志信息写入 FILE。
  -a,  --append-output=FILE  将信息添加至 FILE。
  -d,  --debug               打印大量调试信息。
  -q,  --quiet               安静模式 (无信息输出)-v,  --verbose             详尽的输出 (此为默认值)-nv, --no-verbose          关闭详尽输出,但不进入安静模式。
       --report-speed=TYPE   Output bandwidth as TYPE.  TYPE can be bits.
  -i,  --input-file=FILE     下载本地或外部 FILE 中的 URLs。
  -F,  --force-html          把输入文件当成 HTML 文件。
  -B,  --base=URL            解析与 URL 相关的
                             HTML 输入文件 (-i -F 选项指定)--config=FILE         Specify config file to use.

下载:
  -t,  --tries=NUMBER            设置重试次数为 NUMBER (0 代表无限制)--retry-connrefused       即使拒绝连接也是重试。
  -O,  --output-document=FILE    将文档写入 FILE。
  -nc, --no-clobber              skip downloads that would download to
                                 existing files (overwriting them).
  -c,  --continue                断点续传下载文件。
       --progress=TYPE           选择进度条类型。
  -N,  --timestamping            只获取比本地文件新的文件。
  --no-use-server-timestamps     不用服务器上的时间戳来设置本地文件。
  -S,  --server-response         打印服务器响应。
       --spider                  不下载任何文件。
  -T,  --timeout=SECONDS         将所有超时设为 SECONDS 秒。
       --dns-timeout=SECS        设置 DNS 查寻超时为 SECS 秒。
       --connect-timeout=SECS    设置连接超时为 SECS 秒。
       --read-timeout=SECS       设置读取超时为 SECS 秒。
  -w,  --wait=SECONDS            等待间隔为 SECONDS 秒。
       --waitretry=SECONDS       在获取文件的重试期间等待 1..SECONDS 秒。
       --random-wait             获取多个文件时,每次随机等待间隔
                                 0.5*WAIT...1.5*WAIT 秒。
       --no-proxy                禁止使用代理。
  -Q,  --quota=NUMBER            设置获取配额为 NUMBER 字节。
       --bind-address=ADDRESS    绑定至本地主机上的 ADDRESS (主机名或是 IP)--limit-rate=RATE         限制下载速率为 RATE。
       --no-dns-cache            关闭 DNS 查寻缓存。
       --restrict-file-names=OS  限定文件名中的字符为 OS 允许的字符。
       --ignore-case             匹配文件/目录时忽略大小写。
  -4,  --inet4-only              仅连接至 IPv4 地址。
  -6,  --inet6-only              仅连接至 IPv6 地址。
       --prefer-family=FAMILY    首先连接至指定协议的地址
                                 FAMILY 为 IPv6,IPv4 或是 none。
       --user=USER               将 ftp 和 http 的用户名均设置为 USER。
       --password=PASS           将 ftp 和 http 的密码均设置为 PASS。
       --ask-password            提示输入密码。
       --no-iri                  关闭 IRI 支持。
       --local-encoding=ENC      IRI (国际化资源标识符) 使用 ENC 作为本地编码。
       --remote-encoding=ENC     使用 ENC 作为默认远程编码。
       --unlink                  remove file before clobber.

目录:
  -nd, --no-directories           不创建目录。
  -x,  --force-directories        强制创建目录。
  -nH, --no-host-directories      不要创建主目录。
       --protocol-directories     在目录中使用协议名称。
  -P,  --directory-prefix=PREFIX  以 PREFIX/... 保存文件
       --cut-dirs=NUMBER          忽略远程目录中 NUMBER 个目录层。

HTTP 选项:
       --http-user=USER        设置 http 用户名为 USER。
       --http-password=PASS    设置 http 密码为 PASS。
       --no-cache              不在服务器上缓存数据。
       --default-page=NAME     改变默认页
                               (默认页通常是“index.html”)-E,  --adjust-extension      以合适的扩展名保存 HTML/CSS 文档。
       --ignore-length         忽略头部的‘Content-Length’区域。
       --header=STRING         在头部插入 STRING。
       --max-redirect          每页所允许的最大重定向。
       --proxy-user=USER       使用 USER 作为代理用户名。
       --proxy-password=PASS   使用 PASS 作为代理密码。
       --referer=URL           在 HTTP 请求头包含‘Referer: URL’。
       --save-headers          将 HTTP 头保存至文件。
  -U,  --user-agent=AGENT      标识为 AGENT 而不是 Wget/VERSION。
       --no-http-keep-alive    禁用 HTTP keep-alive (永久连接)--no-cookies            不使用 cookies。
       --load-cookies=FILE     会话开始前从 FILE 中载入 cookies。
       --save-cookies=FILE     会话结束后保存 cookies 至 FILE。
       --keep-session-cookies  载入并保存会话 (非永久) cookies。
       --post-data=STRING      使用 POST 方式;把 STRING 作为数据发送。
       --post-file=FILE        使用 POST 方式;发送 FILE 内容。
       --content-disposition   当选中本地文件名时
                               允许 Content-Disposition 头部 (尚在实验)--content-on-error      output the received content on server errors.
       --auth-no-challenge     发送不含服务器询问的首次等待
                               的基本 HTTP 验证信息。

HTTPS (SSL/TLS) 选项:
       --secure-protocol=PR     choose secure protocol, one of auto, SSLv2,
                                SSLv3, TLSv1, TLSv1_1 and TLSv1_2.
       --no-check-certificate   不要验证服务器的证书。
       --certificate=FILE       客户端证书文件。
       --certificate-type=TYPE  客户端证书类型,PEM 或 DER。
       --private-key=FILE       私钥文件。
       --private-key-type=TYPE  私钥文件类型,PEM 或 DER。
       --ca-certificate=FILE    带有一组 CA 认证的文件。
       --ca-directory=DIR       保存 CA 认证的哈希列表的目录。
       --random-file=FILE       带有生成 SSL PRNG 的随机数据的文件。
       --egd-file=FILE          用于命名带有随机数据的 EGD 套接字的文件。

FTP 选项:
       --ftp-user=USER         设置 ftp 用户名为 USER。
       --ftp-password=PASS     设置 ftp 密码为 PASS。
       --no-remove-listing     不要删除‘.listing’文件。
       --no-glob               不在 FTP 文件名中使用通配符展开。
       --no-passive-ftp        禁用“passive”传输模式。
       --preserve-permissions  保留远程文件的权限。
       --retr-symlinks         递归目录时,获取链接的文件 (而非目录)。

WARC options:
       --warc-file=FILENAME      save request/response data to a .warc.gz file.
       --warc-header=STRING      insert STRING into the warcinfo record.
       --warc-max-size=NUMBER    set maximum size of WARC files to NUMBER.
       --warc-cdx                write CDX index files.
       --warc-dedup=FILENAME     do not store records listed in this CDX file.
       --no-warc-compression     do not compress WARC files with GZIP.
       --no-warc-digests         do not calculate SHA1 digests.
       --no-warc-keep-log        do not store the log file in a WARC record.
       --warc-tempdir=DIRECTORY  location for temporary files created by the
                                 WARC writer.

递归下载:
  -r,  --recursive          指定递归下载。
  -l,  --level=NUMBER       最大递归深度 (inf 或 0 代表无限制,即全部下载)--delete-after       下载完成后删除本地文件。
  -k,  --convert-links      让下载得到的 HTML 或 CSS 中的链接指向本地文件。
  --backups=N   before writing file X, rotate up to N backup files.
  -K,  --backup-converted   在转换文件 X 前先将它备份为 X.orig。
  -m,  --mirror             -N -r -l inf --no-remove-listing 的缩写形式。
  -p,  --page-requisites    下载所有用于显示 HTML 页面的图片之类的元素。
       --strict-comments    用严格方式 (SGML) 处理 HTML 注释。

递归接受/拒绝:
  -A,  --accept=LIST               逗号分隔的可接受的扩展名列表。
  -R,  --reject=LIST               逗号分隔的要拒绝的扩展名列表。
       --accept-regex=REGEX        regex matching accepted URLs.
       --reject-regex=REGEX        regex matching rejected URLs.
       --regex-type=TYPE           regex type (posix|pcre).
  -D,  --domains=LIST              逗号分隔的可接受的域列表。
       --exclude-domains=LIST      逗号分隔的要拒绝的域列表。
       --follow-ftp                跟踪 HTML 文档中的 FTP 链接。
       --follow-tags=LIST          逗号分隔的跟踪的 HTML 标识列表。
       --ignore-tags=LIST          逗号分隔的忽略的 HTML 标识列表。
  -H,  --span-hosts                递归时转向外部主机。
  -L,  --relative                  只跟踪有关系的链接。
  -I,  --include-directories=LIST  允许目录的列表。
  --trust-server-names             use the name specified by the redirection
                                   url last component.
  -X,  --exclude-directories=LIST  排除目录的列表。
  -np, --no-parent                 不追溯至父目录。

请将错误报告或建议寄给 <bug-wget@gnu.org>。
[root@Cc ~]#

网络配置

查看某网卡配置

1
2
3
4
5
[root@Cc ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
[root@Cc ~]#

设置主机名

设置主机名之后需要重新的启动,我这里是切换用户登录,查看效果

1
2
3
4
5
[root@Cc ~]# hostname Hyper
[root@Cc ~]# su testUser
[testUser@Hyper root]$ su root
密码:
[root@Hyper ~]#

设置默认网关

  • 方法一

[root@Hyper ~]# route add default wg 172.24.63.255

如果是虚拟机就可以试试设置网关,在这网络配置还是要小心为妙,我这里就没有执行这一行

  • 方法二
1
2
3
4
5
6
[root@Hyper ~]# cat /etc/sysconfig/network
# Created by anaconda
NETWORKING_IPV6=no
PEERNTP=no
GATEWAY=172.24.63.255
[root@Hyper ~]#
  • 重新启动网卡
1
2
3
[root@Hyper ~]# /etc/rc.d/init.d/network restart
Restarting network (via systemctl):                        [  确定  ]
[root@Hyper ~]#

设置 DNS 服务

1
2
3
4
5
6
[root@Hyper ~]# cat /etc/resolv.conf
options timeout:2 attempts:3 rotate single-request-reopen
; generated by /usr/sbin/dhclient-script
nameserver 100.100.2.136
nameserver 100.100.2.138
[root@Hyper ~]#

动态主机配置协议 DHCP

好多概念知识,会拿出时间来讲解这张预留的空白

Linux 域名服务 DNS

好多概念知识,会拿出时间来讲解这张预留的空白

配置精确时间协议

好多概念知识,会拿出时间来讲解这张预留的空白

监控网卡流量

1
#预留
This post is licensed under CC BY 4.0 by the author.