一. 网络检查
1.1 网卡管理
- ifconfig用于
查看/修改IP
,查看MAC信息
,启动/关闭网卡
等。
| $ ifconfig |
| $ ifconfig eth0 down |
| $ ifconfig eth0 up |
| |
| $ ifconfig eth0 192.168.1.2 |
| $ ifconfig eth0 192.168.1.2 netmask 255.255.255.0 |
1.2 DNS解析
- dig是UNIX/BSD系统都自带的DNS诊断工具,功能强大。
- host是轻量级的dig,值返回dig的
ANSWER section
。
- nslookup功能类似,简单方便,但已弃用。
| $ host www.google.cn |
| |
| $ dig www.google.cn |
| $ dig www.google.cn +trace |
| $ dig -x 203.208.50.98 |
| |
| $ nslookup www.google.cn |
1.3 网关探测
| $ traceroute www.google.cn |
| $ traceroute -n www.google.cn |
1.4 网络状态
netstat命令用来打印Linux中网络系统的状态信息,可让你得知整个Linux系统的网络情况。
参数 |
说明 |
-r (route) |
显示路由表 |
-i (interfaces) |
显示网络接口 |
-s (statistice) |
显示统计表 |
-t (TCP) |
显示TCP传输协议的连线状况 |
-u (UDP) |
显示UDP传输协议的连线状况 |
-l (listening) |
显示监控中的Socket |
-n (numeric) |
使用ip地址 |
-p (programs/protocal) |
显示程序名称(Unix)/协议(mac) |
| $ netstat -i |
| $ netstat -r |
| |
| $ netstat -ts |
| $ netstat -us |
| |
| $ netstat -tln |
| $ netstat -uln |
| $ netstat -tulnp |
二. 网络工具
2.1 telnet
Telnet:TCP/IP协议族成员
,是Internet远程登录服务的标准协议
和主要方式,默认端口为23。
| $ telnet 10.0.0.11 |
| $ telnet 10.0.0.11 3306 |
2.2 netcat
netcat是网络工具中的瑞士军刀
,用作端口监听/端口扫描/远程传输/远程shell等
。
2.1.1 单工监听
| # server |
| $ nc -lp 2222 -e /bin/bash |
| # client |
| $ nc 192.168.1.10 2222 |
| > ...进入远程终端模式... |
2.1.2 双工对话
| # server(ip:192.168.1.10) |
| $ nc -lkp 2222 |
| $ nc -lkp 2222 -o a.txt |
| # client |
| $ nc 192.168.1.10 2222 |
| > ...进入双工对话模式... |
也可以直接使用http访问serverA: curl -X POST http://192.168.1.10:2222 -d '{"key":"apple"}'
2.1.3 信息探测
| # -n: 不进行DNS解析 ; |
| # -v:输出信息; |
| # -z:即zero,发送的数据包中不包含任何payload ; |
| $ nc -zvn 192.168.1.10 21-80 |
| $ nc -v 192.168.1.10 80 |
| $ echo " "|nc -vn -w1 192.168.1.10 80 |
2.1.4 文件传输:
适用于传输取证文件
或无法正常下载的敏感文件
。
| $ nc -lp 2222 >./outfile |
| $ nc 192.168.1.10 2222 < infile |
| $ nc -lp 2222 <./infile |
| $ nc 192.168.1.10 2222 > outfile |
2.1.5 目录传输
| $ nc -lp 2222 | tar zxf - |
| $ tar zcf - ./share_dir| nc 192.168.1.10 2222 |
| $ tar -c share_dir |nc -lp 2222 |
| $ nc 192.168.1.10 2222|tar -x |
| $ nc -w3 192.168.1.11 2222 |
2.1.6 磁盘复制
| # server |
| $ nc -lp port |dd of=/dev/sda |
| |
| # client |
| $ dd if=/dev/sda | nc -nc ip port -q 1 |
2.1.7 端口转发
2.3 curl
curl是用于通过URL传输数据的命令行工具和库。
2.3.1 查看过程
| #查看过程 |
| $ curl -I www.example.cn |
| $ curl -i www.example.cn |
| $ curl -v www.example.cn |
| $ curl --trace dump.txt www.example.cn |
2.3.2 设置头部
| USER_AGENT='Mozilla/5.0 AppleWebKit/600 Mobile MicroMessenger/6.0' |
| REFERER='http://www.referer.com' |
| |
| $ curl -H 'Authorization:Bearer xxx' http://example.com |
| $ curl -A $USER_AGENT http://example.com |
| $ curl -u "root:123456" example.com |
| $ curl -e $REFERER http://www.example.com |
2.3.3 请求方法
| $ curl -X HEAD http://example.com |
| $ curl -X GET http://example.com |
| $ curl -X POST http://example.com |
| $ curl -X DELETE http://example.com |
| $ curl -X PUT http://example.com |
| $ curl -X PATCH http://example.com |
| $ curl -X OPTION http://example.com |
| $ curl -X TRACE http://example.com |
| $ curl -X CONNECT http://example.com |
| $ curl -X LINK http://example.com |
| $ curl -X UNLINK http://example.com |
2.3.4 提交数据
| # -G: GET (Content-Type: text/plain; charset=utf-8) |
| # -d: POST(Content-Type: application/x-www-form-urlencoded) |
| # -F: POST(Content-Type: multipart/form-data;boundary=-----4a1a7a53) |
| |
| #内容格式 |
| $ curl -H 'Content-Type:text/plain' -d "hello" http://example.com |
| $ curl -H 'Content-Type:application/json' -d "{'name':Tom}" http://example.com |
| $ curl -H 'Content-Type:application/x-www-form-urlencoded' -d "name=tom" http://example.com |
| |
| #URL参数 |
| $ curl "http://localhost:8080?name=tom" |
| $ curl -G "http://localhost:8080?name=tom" |
| $ curl -G -d 'name=jack' -d 'age=20' http://localhost:8080 |
| |
| #BODY参数 |
| #-d:会将多个参数进行拼接,默认以Post(application/x-www-form-urlencode)提交数据 |
| $ curl -d "name=tom&age=22" http://localhost:8080 |
| $ curl -d "name=tom" -d "age=18" http://localhost:8080 |
| $ curl -d "@param.txt" http://localhost:8080 |
| |
| #数据类型(URL) |
| $ curl -G "http://localhost:8080?hobby=golang&hobby=java" |
| $ curl -G "http://localhost:8080?score[math]=88&score[han]=96" |
| |
| #数据类型(Form) |
| $ curl -d "hobby=golang&hobby=java" localhost:8080 |
| $ curl -d "score[math]=88&score[han]=96" http://localhost:8080 |
| $ curl -F "hobby=golang" -F "hobby=javascript" http://localhost:8080 |
| $ curl -F "score[math]=88" -F "score[han]=96" http://localhost:8080 |
2.3.5 上传文件
| #-F: 即Form,可指定多个MIME数据,一般用于提交文件数据 |
| # file:文件路径; type:文件MIME; filename:文件名 |
| $ curl -F "name=tom" -F "age=18" http://localhost:8080 |
| $ curl -F type="thumb" -F 'file=@logo.png' http://localhost:8080 |
| $ curl -F 'file=@logo.png;type=image/png;filename=a.png' http://localhost:8080 |
2.3.6 下载文件
| DOWNLOAD_URL=mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso |
| $ curl -o dump.html http://www.example.com/a.html |
| $ curl -O http://www.example.com/a.html |
| |
| $ curl - |
| $ curl - |
2.3.7 会话数据
| COOKIE='key1=hello; Path=/; Domain=www.abc.com; Expires=Tue, 02 Aug 2022 06:14:45 GMT;' |
| |
| # -b/--cookie <name=string/file> cookie字符串或文件读取位置 |
| # -c/--cookie-jar <file> 操作结束后把cookie写入到这个文件中 |
| $ curl -b "$COOKIE" http://example.com |
| curl -b cookies.txt -c newcookies.txt itbilu.com |
2.3.8 执行脚本
| #L: location; S: show-error; s: silent mode(静音模式) |
| $ curl -sSL http://test.sh|bash |
| $ bash <(curl -sSL http:xxx.sh) |
| |
| $ bash <(curl -Ls https://install.direct/go.sh) |
| $ curl -sSL https://get.docker.com|sh |
三. 防火墙
Centos7中默认使用Firewalld
取代了(通用的)Iptables
作为防火墙管理工具
。 iptables服务会把配置好的防火墙策略交由内核层面的netfilter网络过滤器
来处理,而firewalld服务则是把配置好的防火墙策略交由内核层面的nftables包过滤框架
来处理。它们的作用都是为了方便运维人员管理Linux系统的防火墙策略,而我们只要配置妥当其中一个就足够了。
3.1 firewalld
3.1.1 服务管理
| $ yum install firewalld systemd -y |
| $ firewall-cmd --state |
| |
| $ systemctl status firewalld |
| $ systemctl start firewalld |
| $ systemctl stop firewalld |
| $ systemctl restart firewalld |
| $ systemctl disable/enable firewalld |
| $ systemctl is-enabled firewalld.service |
| $ systemctl list-unit-files|grep enabled |
| $ systemctl --failed |
3.1.2 规则配置
| $ firewall-cmd --zone=public --query-port=80/tcp |
| $ firewall-cmd --zone=public --add-port=80/tcp --permanent |
| $ firewall-cmd --reload |
| $ firewall-cmd --zone=public --remove-port=80/tcp --permanent |
| $ firewall-cmd --zone=public --list-ports |
| |
| $ firewall-cmd -V |
| $ firewall-cmd -h |
3.2 iptables
3.2.1 服务管理
| $ yum install -y iptables iptables-services |
| $ service iptables status|start|stop|restart |
| $ chkconfig iptables off|on |
| $ service iptables save |
3.2.2 规则配置
参数 |
说明 |
ACCEPT |
接收/白名单 |
DROP |
丢弃/黑名单 |
-A |
附加到规则链 |
-P |
设置默认策略 |
--dport |
目标端口 |
--sport |
来源端口 |
| $ iptables -L -n |
| $ iptables -Z |
| $ iptables -F |
| $ iptables -X |
| |
| $ iptables -P OUTPUT ACCEPT |
| $ iptables -P INPUT ACCEPT |
| $ iptables -A INPUT -i lo -j ACCEPT |
| $ iptables -A OUTPUT -o lo -j ACCEPT |
| |
| $ iptables -A INPUT -p tcp --dport 3306 -j ACCEPT |
| $ iptables -A INPUT -p tcp -s 10.0.0.12 -j ACCEPT |
| |
| $ iptables -P INPUT DROP |
| $ iptables -P FORWARD DROP |
| $ iptables -I INPUT -s ***.***.***.*** -j DROP |
| $ iptables -D INPUT -s ***.***.***.*** -j DROP |
参考链接
https://www.linuxprobe.com/25-iptables-common-examples.html
https://blog.csdn.net/u012486840/article/details/52635263
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)