|NO.Z.00003|——————————|LinuxNetwork|——|Linux&路由端口.V02|——|端口协议|

一、常见网络协议和端口
### --- 网络地址和物理地址

~~~     #网络地址:
~~~     互联网协议地址(IP地址)为互联网上每一个网络或主机分配一个逻辑地址,IP地址工作在网络层。
~~~     #IP的分类:IPV4 IPV6:
~~~     IPV6:已在20年前就已经开发完成了,只是没有找到IPV4/IPV6之间通信的方式方法。
### --- IPV4地址分类:

~~~     10.0.0.0~10.255.255:局域网地址
~~~     172.16.0.0~172.31.255.255:私有地址
~~~     192.168.0.0~192.168.255.255:局域网地址
~~~     物理地址:物理地址(MAC地址)为每一个设备设置一个固定的硬件地址,
### --- MAC地址工作在链路层

~~~     #MAC地址:00-23-5A-15-99-42:
~~~     十六定制位组成;一个十六进制代表4个二进制为,
~~~     总共是48个二进制位的进制数,比IPV4多:IPV是32个二进制位数,物理定制数是48个。
二、TCP/IP五层常见协议
### --- TCP/IP五层常见协议

~~~     应用层协议:FTP/HTTP/SMTP/Telent/DNS等
~~~     传输层协议:TCP/UDP等
~~~     网络层协议:IP/ICMP/ARP等
~~~     数据链路层协议:PPP协议等
~~~     物理层:不常用
~~~     标准协议:四层协议:把物理层和数据链路层合并了,网络兼容层。
三、常见网络端口
端口配置文件: /etc/service 说明
20/21 ftp服务 文件共享
22 ssh服务 安全远程管理
23 Telnet服务 不安全远程管理
25 SMTP:简单邮件传输协议 发信
465 smtp(ssl) 发信
110 pop3:邮局协议 收信
143 IMAP4 收信
993 IMAP4(ssl) 收信
80 www服务(http://) 网页访问
443 www服务(https://) 加密网页访问
3306 mysql端口 数据库连接端口
53 DNS端口 域名解析端口

一、Linux下网关路由配置:网关和路由
### --- 网关和路由总结

~~~     路由:不同网段数据转发:路由选择
~~~     网关:不同网段数据转发,路由选择,默认路由,NAT转换
### --- 网关和路由设置

~~~     route -n  查看系统中的路由表信息
~~~     临时:网关:添加:route add default gw ip
~~~     删除:route del default gw ip
~~~     永久:网关:添加:/etc/sysconfig/network-scripts/ifcfg-eth0
### --- 查看路由表

[root@localhost ~]# route -n                                
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    100    0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0
### --- 添加一条新的路由

[root@localhost ~]# route add default gw 192.168.1.10       
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.10    0.0.0.0         UG    0      0        0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG    100    0        0 eth0
### --- 删除网路由

[root@localhost ~]# route del default gw 192.168.1.10           
[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    100    0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     100    0        0 eth0
### --- 配置文件修改网关

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0   
 GATEWAY=192.168.1.1
二、Linux下网络管理命令
### --- DNS配置命令:

~~~     nslookup:域名解析测试命令
~~~     配置文件:
~~~     局部:/etc/sysconfig/network-scripts/ifcfg-eth0
DNS=ip
~~~     全局:/etc/resolv.conf
nameserver.ip
~~~     相关配置文件:/etc/hosts
### --- 网卡配置文件添加DNS                                 // 局部配置,针对指定网卡的配置

[root@centos7 ~]#  vim /etc/sysconfig/network-scripts/ifcfg-eth0
DNS1=114.114.114.114
DNS2=8.8.8.8
[root@centos7 ~]#  systemctl restart network.service        // 就可以直接生效
### --- 验证域名解析测试

[root@centos7 ~]#  nslookup www.baidu.com
Server:     114.114.114.114
Address:    114.114.114.114#53
Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
Name:   www.a.shifen.com
Address: 180.101.49.12
Name:   www.a.shifen.com
Address: 180.101.49.11
### --- 静态的dns配置地址:优先级最高
 
[root@centos7 ~]# vim /etc/hosts
114.114.114.114     www.yanqi1.com
8.8.8.8             www.yanqi2.com
三、网络查看命令:
### --- 网络查看命令:
### --- netstat查看系统的网络连接状态,路由信息,接口等
### --- 常用选项:

~~~     -a:显示所有活动连接
~~~     -n:以数字的形式显示
~~~     -t:查看TCP协议相关信息
~~~     -u:查看UDP协议相关信息
~~~     -p:显示PID和进程名
~~~     -l:监听
### --- 查询tcp连接包括监听的进程号

[root@centos7 ~]# netstat -tunlp                                
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      601/rpcbind  
### --- 查询TCP/UDP都有哪些端口
 
[root@centos7 ~]# netstat -tlun                             
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN     
### --- 可以查询所有的端口包括哪些正在连接

[root@centos7 ~]# netstat -an                           
四、网络查看命令:
### --- 网络查看命令:

~~~     traceroute:测试从当前主机到目的主机经过的网络节点数,用于追踪数据包在网络上传输时的全部路径,它默认发送的数据包大小是40字节,默认使用ICMP协议
~~~     常用选项:
~~~     -p:使用UDP端口进行测试,默认端口为33434
~~~     -q 3    指定测试时发送的数据包个数(即测试次数)
~~~     -n  以IP的方式进行连接测试,避开的解析
~~~     注意:该命令在使用NAT模式时无法实现效果,请切换桥接模式(官方回复)
### --- 路由追踪,在生产环境中会禁止使用,没办法使用。

[root@atyanqi ~]# traceroute 192.168.1.60                               
traceroute to 192.168.1.60 (192.168.1.60), 30 hops max, 60 byte packets
 1  atyanqi.com (192.168.1.55)  3025.668 ms !H  3025.626 ms !H  3025.613 ms !H
[root@atyanqi ~]# traceroute www.baidu.com
traceroute to www.baidu.com (180.101.49.12), 30 hops max, 60 byte packets
 1  gateway (192.168.1.1)  0.752 ms  0.701 ms  0.629 ms
 2  192.168.99.1 (192.168.99.1)  0.549 ms  0.536 ms  0.848 ms
 3  gateway (192.168.1.1)  1.486 ms  1.413 ms  1.392 ms
 4  115.196.72.1 (115.196.72.1)  4.468 ms  4.412 ms  4.391 ms
 5  * * *
 6  115.233.20.29 (115.233.20.29)  6.840 ms 220.191.198.197 (220.191.198.197)  3.288 ms 115.233.20.9 (115.233.20.9)  5.898 ms
 7  202.97.76.6 (202.97.76.6)  11.611 ms 202.97.33.117 (202.97.33.117)  10.784 ms 202.97.33.177 (202.97.33.177)  21.405 ms
 8  58.213.95.110 (58.213.95.110)  15.167 ms 58.213.94.82 (58.213.94.82)  13.113 ms 58.213.94.98 (58.213.94.98)  17.650 ms
 9  * * *
10  58.213.96.54 (58.213.96.54)  13.005 ms 58.213.96.118 (58.213.96.118)  13.604 ms 58.213.96.94 (58.213.96.94)  15.480 ms
11  * * *
五、网络连通测试命令
### --- 网络连通测试命令

~~~     ping:测试网络连通性
~~~     常见选项:
~~~     -i  指定间隔时间
~~~     -c  指定ping的次数
~~~     -s  指定数据包的大小
### --- 网络连通测试命令

[root@atyanqi ~]# ping www.baidu.com
PING www.a.shifen.com (180.101.49.11) 56(84) bytes of data.
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=1 ttl=51 time=13.7 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=2 ttl=51 time=13.7 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=3 ttl=51 time=13.7 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=4 ttl=51 time=13.6 ms
[root@atyanqi ~]# ping -c 2 www.baidu.com               //ping 2次
PING www.a.shifen.com (180.101.49.11) 56(84) bytes of data.
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=1 ttl=51 time=13.9 ms
64 bytes from 180.101.49.11 (180.101.49.11): icmp_seq=2 ttl=51 time=13.7 ms
六、地址解析命令
### --- 地址解析命令

~~~     arp:地址解析协议,将ip地址解析成MAC地址
~~~     常见选项:
~~~     -a  查看所有
~~~     -d  ip地址,删除某条ARP记录
### --- 查询到已知设备的mac地址
[root@atyanqi ~]# arp -a                    
? (192.168.1.60) at <incomplete> on enp0s3
? (192.168.1.102) at d8:50:e6:0a:28:70 [ether] on enp0s3
? (192.168.1.101) at 90:dd:5d:4c:44:50 [ether] on enp0s3
gateway (192.168.1.1) at 50:3a:a0:4b:78:ec [ether] on enp0s3

### --- 删除多对应的解析ARP记录
[root@atyanqi ~]# arp -d                                        
七、网络探测命令
### --- 网络探测命令

~~~     nmap:网络探测扫描命令;此命令默认未安装
~~~     -sP 探测某网段内有哪些主机是存活的
~~~     -sT 探测某主机上开启了哪些TCP端口
### --- 探测某网段内有哪些主机是存活的

[root@atyanqi ~]# nmap -sP 192.168.1.0/24   
Starting Nmap 6.40 ( http://nmap.org ) at 2020-12-16 04:00 CST
Nmap scan report for 192.168.1.1
Host is up (0.0014s latency).
MAC Address: 50:3A:A0:4B:78:EC (Unknown)
Nmap scan report for 192.168.1.100
Host is up (0.69s latency).
MAC Address: D4:4B:B6:19:FB:93 (Unknown)
Nmap scan report for 192.168.1.102
Host is up (0.0010s latency).
MAC Address: D8:50:E6:0A:28:70 (Unknown)
Nmap scan report for 192.168.1.55
Host is up.
Nmap done: 256 IP addresses (4 hosts up) scanned in 14.06 seconds
### --- 探测某主机上开启了哪些TCP端口

[root@atyanqi ~]# nmap -sT 192.168.1.100            

Starting Nmap 6.40 ( http://nmap.org ) at 2020-12-16 04:01 CST
Nmap scan report for 192.168.1.100
Host is up (0.011s latency).
All 1000 scanned ports on 192.168.1.100 are closed
MAC Address: D4:4B:B6:19:FB:93 (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 3.24 seconds
八、远程连接工具
### --- 远程连接工具

~~~     windows——>Linux:Xshell SecureCRT
~~~     Linux——>Windows:rdesktop命令(图形界面)
~~~     Linux——>Linux:ssh命令

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

posted on   yanqi_vip  阅读(49)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示