centos 端口测试之nc使用
服务器端口测试是否正常,运维一般使用telnet来检查,但它有局限性,服务器的端口必须存在服务运行。
这时使用nc可以在服务端模拟开启一个端口,再通过nc测试此端口,好用!
nc是netcat工具的简称,一个网络工具,可以用来端口扫描、文件传输等功能。
centos上面安装也很简单:
yum install nc -y
nc常用功能
1、实现任意TCP/UDP端口的侦听,nc可以作为server以TCP或UDP方式侦听指定端口
2、端口的扫描,nc可以作为client发起TCP或UDP连接
3、机器之间传输文件
4、机器之间网络测速
一般nc只用来做TCP/UDP协议的端口测试,其它功能少用!
nc帮助说明
# nc --help
Ncat 7.50 ( https://nmap.org/ncat )
Usage: ncat [options] [hostname] [port]
Options taking a time assume seconds. Append 'ms' for milliseconds,
's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms).
-4 Use IPv4 only
-6 Use IPv6 only
-U, --unixsock Use Unix domain sockets only
-C, --crlf Use CRLF for EOL sequence
-c, --sh-exec <command> Executes the given command via /bin/sh
-e, --exec <command> Executes the given command
--lua-exec <filename> Executes the given Lua script
-g hop1[,hop2,...] Loose source routing hop points (8 max)
-G <n> Loose source routing hop pointer (4, 8, 12, ...)
-m, --max-conns <n> Maximum <n> simultaneous connections
-h, --help Display this help screen
-d, --delay <time> Wait between read/writes
-o, --output <filename> Dump session data to a file
-x, --hex-dump <filename> Dump session data as hex to a file
-i, --idle-timeout <time> Idle read/write timeout
-p, --source-port port Specify source port to use
-s, --source addr Specify source address to use (doesn't affect -l)
-l, --listen Bind and listen for incoming connections
-k, --keep-open Accept multiple connections in listen mode
-n, --nodns Do not resolve hostnames via DNS
-t, --telnet Answer Telnet negotiations
-u, --udp Use UDP instead of default TCP
--sctp Use SCTP instead of default TCP
-v, --verbose Set verbosity level (can be used several times)
-w, --wait <time> Connect timeout
-z Zero-I/O mode, report connection status only
--append-output Append rather than clobber specified output files
--send-only Only send data, ignoring received; quit on EOF
--recv-only Only receive data, never send anything
--allow Allow only given hosts to connect to Ncat
--allowfile A file of hosts allowed to connect to Ncat
--deny Deny given hosts from connecting to Ncat
--denyfile A file of hosts denied from connecting to Ncat
--broker Enable Ncat's connection brokering mode
--chat Start a simple Ncat chat server
--proxy <addr[:port]> Specify address of host to proxy through
--proxy-type <type> Specify proxy type ("http" or "socks4" or "socks5")
--proxy-auth <auth> Authenticate with HTTP or SOCKS proxy server
--ssl Connect or listen with SSL
--ssl-cert Specify SSL certificate file (PEM) for listening
--ssl-key Specify SSL private key (PEM) for listening
--ssl-verify Verify trust and domain name of certificates
--ssl-trustfile PEM file containing trusted SSL certificates
--ssl-ciphers Cipherlist containing SSL ciphers to use
--version Display Ncat's version information and exit
nc常用案例
TCP监听测试
- nc可作为server端
192.168.10.11启动一个tcp的监听
nc -l 80
- 客户端测试方法:直接telnet该机器ip+端口
telnet 192.168.10.11 80
或:nmap 192.168.10.11 -p 80
UDP监听测试
- nc作为server端启动一个udp的监听
nc -lu 80
通过netstat可以看到udp协议已经监听:
> # netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 0.0.0.0:80 0.0.0.0:* 15401/nc
- 客户端测试方法:(telnet只能测试tcp协议)
nc -vuz 192.168.10.11 80
(u表示udp端口,v表示可视化输出,z表示扫描时不发送数据)
使用nc传输文件
使用nc传输文件不用scp或rsync那种输入密码的操作,当然也存在一定安全性。
例如:要把A机器上的一个sql文件发送到B机器上
(需要先开启侦听B机器端口,再到A机器发送数据到该端口)
步骤1,先在B机器上启动一个接收文件的监听,格式如下
nc -l 888 > zabbix.sql
步骤2,在A机器上往B机器的888端口发送数据,把下面sql包发送过去
nc 192.168.10.11 888 < zabbix.sql
也可通过nc传输目录,但这里不推荐使用,暂不举例。
网络测试
这里也不推荐使用nc,直接使用speedtest,简单:
wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
chmod +x speedtest-cli
./speedtest-cli
解决telnet 无法断开问题
用CTRL+]键,这时会强制退到telnet命令界面下,再输入quit退出就行。
centos 端口测试之nc使用的更多相关文章
- Centos下安装nc命令工具安装以及使用
1)netcat(nc)是一个简单而有用的工具,被誉为网络安全界的“瑞士军刀”,不仅可以通过使用TCP或UDP协议的网络连接读写数据,同时还是一个功能强大的网络调试和探测工具,能够建立你需要的几乎所有 ...
- centos 端口开放及关闭
之前有讲过公司新买的服务器使用的是CentOS 5.5,部署好Tomcat之后却发现输入114.80.*.*:8080(即ip:8080)却无法显示Tomcat默认的首页.因为以前部署在Win Ser ...
- centos 端口开放及关闭 【转】
之前有讲过公司新买的服务器使用的是CentOS 5.5,部署好Tomcat之后却发现输入114.80.*.*:8080(即ip:8080)却无法显示Tomcat默认的首页.因为以前部署在Win Ser ...
- centos端口管理
centos 6.5 ###############配置filter表防火墙############### #清除预设表filter中的所有规则链的规则iptables -F #清除预设表filter ...
- Linux测试UDP端口(nc)
# nc -vuz serveripaddress 123 Connection to serveripaddress 123 port [udp/ntp] succeeded! 结果证明UDP 12 ...
- CentOS 端口和防火墙操作
Centos 7 端口和防火墙命令: 查看已经开放的端口:firewall-cmd --list-ports 开启端口:firewall-cmd --zone=public --add-port=80 ...
- Linux(centos)使用nc命令发送测试数据
安装 yum -y install nmap-ncat 简单使用 nc -lk 7777 # 开启一个本地7777的TCP协议端口,由客户端主动发起连接,一旦连接必须由服务端发起关闭 nc -vw 2 ...
- CentOS 端口映射
一个合作单位给我创建了十几台虚拟服务器做支撑.但是只给负载均衡绑定了公网IP.由于这个支撑的服务需要测试和调优,经常要往服务器上传class或者修改数据库.为了方便操作,我打算在负载均衡服务器上做端口 ...
- centos 端口iptables配置
1.安装iptables yum install iptables* -y 2.打开端口 iptables -I INPUT -p tcp --dport -j ACCEPT 3.查看本机关于IPTA ...
随机推荐
- c++: internal compiler error: Killed (program cc1plus)
转自https://blog.csdn.net/qq_27148893/article/details/88936044 这是在开发板上编译opencv的时候报了一个错,主要是在编译过程中,内存不够造 ...
- pandas 数据类型转换及描述统计
处理数据的时候往往需要对原始数据进行类型转换和预览等操作,下面介绍常用的处理预览和数据转换方法 预览:例: import pandas as pdsec_weather = pd.read_table ...
- sql 游标(理论)
游标是处理结果集的一种机制 --声明游标 --ISO 语法 DECLARE cursor_name [ INSENSITIVE ] [ SCROLL ] CURSOR FOR select_state ...
- 力扣Leetcode 680. 验证回文字符串 Ⅱ
验证回文字符串 Ⅱ 给定一个非空字符串 s,最多删除一个字符.判断是否能成为回文字符串. 示例 1: 输入: "aba" 输出: True 示例 2: 输入: "abca ...
- centos 7 对用过yum更新的软件服务进行降级
centos 7 执行 yum update 会对现有服务软件进行更新,但是如果把不该升级的软件升级,彼此软件不兼容,如何进行降级,比如:kibana 必须与 elasticsearch 大版本相同, ...
- MD5加密,java String 转变成MD5 String 详细代码,工具类Android开发必备
/** * MD5加码.32位 * @param inStr * @return */ public static String MD5(String inStr) { MessageDigest m ...
- P1306 斐波那契公约数(ksm+结论)
题目描述 对于Fibonacci数列:1,1,2,3,5,8,13......大家应该很熟悉吧~~~但是现在有一个很“简单”问题:第n项和第m项的最大公约数是多少? Update:加入了一组数据. 输 ...
- Mysql执行计划(大章)
Mysql的执行计划 执行计划是啥? 使用explain关键字可以模拟优化器执行SQL查询语句,从而知道Mysql是如何处理你的SQL语句的.分析你的查询语句或者表结构的性能瓶颈 语法 explain ...
- 给EmpMapper开放Restful接口
本文例程下载:https://files.cnblogs.com/files/xiandedanteng/gatling20200428-3.zip 接口控制器代码如下: 请求url和响应都写在了每个 ...
- leetcode刷题-64最小路径和
题目 给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小. 说明:每次只能向下或者向右移动一步. 示例: 输入:[ [1,3,1], [1,5, ...