一. 網路檢查
1.1 網卡管理
- ifconfig用于
查看/修改IP,查看MAC資訊,啟動/關閉網卡等,
$ ifconfig #網卡資訊
$ ifconfig eth0 down #關閉
$ ifconfig eth0 up #開啟
$ ifconfig eth0 192.168.1.2 #修改IP
$ 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 #DNS決議
$ dig www.google.cn #DsNS決議
$ dig www.google.cn +trace #跟蹤決議
$ dig -x 203.208.50.98 #反向決議
$ nslookup www.google.cn #已棄用
1.3 網關探測
- traceroute 命令用于探測報文經過的所有網關/路由器,默認四層使用UDP協議發送資料包,
$ traceroute www.google.cn #IP和域名
$ traceroute -n www.google.cn #僅IP探測
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 #顯示TCP統計
$ netstat -us #顯示UDP統計
$ netstat -tln #列出tcp埠
$ netstat -uln #列出udp埠
$ 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 #監聽2222埠
# client
$ nc 192.168.1.10 2222 #連接到server
> ...進入遠程終端模式...
2.1.2 雙工對話
# server(ip:192.168.1.10)
$ nc -lkp 2222 #啟動監聽(k為連續監聽)
$ nc -lkp 2222 -o a.txt #將對話內容寫入檔案
# client
$ nc 192.168.1.10 2222 #連接到server
> ...進入雙工對話模式...
也可以直接使用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 #掃描21到80埠
$ nc -v 192.168.1.10 80 #80埠是否開放
- banner資訊
$ echo " "|nc -vn -w1 192.168.1.10 80
2.1.4 檔案傳輸:
適用于傳輸
取證檔案或無法正常下載的敏感檔案,
- 場景一:服務器接收檔案
$ nc -lp 2222 >./outfile #server
$ nc 192.168.1.10 2222 < infile #client
- 場景二:服務器(暴露)分發檔案
$ nc -lp 2222 <./infile #server
$ nc 192.168.1.10 2222 > outfile #client
2.1.5 目錄傳輸
- 場景一:服務器作為接受者
$ nc -lp 2222 | tar zxf - #server
$ tar zcf - ./share_dir| nc 192.168.1.10 2222 #client(先斷開客戶端)
- 場景二:服務器作為發送者
$ tar -c share_dir |nc -lp 2222 #server
$ nc 192.168.1.10 2222|tar -x #client
- 避免連接服務端時端
假死
$ nc -w3 192.168.1.11 2222 #cleint:等待3秒(此處訪問一個不存在的ip來模擬超時)
2.1.6 磁盤復制
# server
$ nc -lp port |dd of=/dev/sda #of是output filter
# client
$ dd if=/dev/sda | nc -nc ip port -q 1 #if是input filter
2.1.7 埠轉發
- 參考:https://blog.csdn.net/weixin_34309435/article/details/91732318
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 #內容HEAD
$ 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 #洗掉URI資源
$ curl -X PUT http://example.com #修改資源/傳輸檔案,引數是一個完整的物件
$ curl -X PATCH http://example.com #與PUT類似(強調區域修改),引數可包含物件的部分欄位
$ curl -X OPTION http://example.com #詢問URI資源支持的方法
$ 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 #Json
$ curl -H 'Content-Type:application/x-www-form-urlencoded' -d "name=tom" http://example.com #Form
#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 '[email protected]' http://localhost:8080 #MIME:multipart/form-data
$ curl -F '[email protected];type=image/png;filename=a.png' http://localhost:8080 #檔案/MIME/名稱
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 -# -O $DOWNLOAD_URL # 下載檔案(-#:顯示進度)
$ curl -# -O -C - $DOWNLOAD_URL # 斷點續傳(-C <offset>:偏移量)
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 #設定Cookie
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) #示例1:下載安裝V2.ray
$ curl -sSL https://get.docker.com|sh #示例2:下載安裝docker
三. 防火墻
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 #信任IP
$ 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/291977.html
標籤:其他
上一篇:Linnux網路常用命令和工具
