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 ...
随机推荐
- Git clone时出现fatal:the remote end hung up unexpectedly
以HTTPS方式进行git clone时出现如下错误: 方法1:增大缓存 git config http.postBuffer 524288000 尝试无效: 方法2:配置git的最低速度和最低速度时 ...
- 区块链入门到实战(38)之Solidity – 条件语句
Solidity支持条件语句,让程序可以根据条件执行不同的操作.条件语句包括: if if...else if...else if 语法 if (条件表达式) { 被执行语句(如果条件为真) } 示例 ...
- 传统servelt项目之分页操作
需求说明: • 演示最终分页效果 • 提供分页素材 • 分页的作用 • 数据量大,一页容不下 • 后台查询部分数据而不是全部数据 • 降低带宽使用,提高访问速度 • 分页的实现思路 • ...
- 项目介入EF Core
目前.Net主流的ORM有SqlSugar.Entity Framework.Dapper,其它的我就不列举了.其实和Java那边ibatis相比,他们都比较轻量.之前用ibatis开发,真的很麻烦, ...
- ShaderLab 枚举常量
public enum ZTest { Always = 0, Less = 2, Equal = 3, LEqual ...
- PHP check 的一些绕过技术
绕过空格 $_GET[str]=str_replace(" ","",$_GET[str]); ${IFS} 但不能写作 $IFS $IFS$ % 绕过ech ...
- JVM—01
目录 1.1 JVM系统架构图 2.1 类加载器 2.1.1 双亲委派机制 2.1.2 沙箱安全机制 3.1 Native 4.1 PC寄存器 1.1 JVM系统架构图 JVM是什么? JVM是Jav ...
- 分享一个后端专用login模板
给大家啊分享一个后端专用login模板 Java工程师再也不用这样啦---> html源码 <html lang="en"> <head> <m ...
- Wampserver报错、橙色、mysql打不开
Wampserver下的几个常见的问题 最近在弄Wampserver,发现有几个问题存留在这里,今天就来解决一下吧 首先就是关于报错的这个一个问题: 第二就是关于一直不变绿的原因 关于报错: 在我的电 ...
- leetcode刷题-66加一
题目 给定一个由整数组成的非空数组所表示的非负整数,在该数的基础上加一. 最高位数字存放在数组的首位, 数组中每个元素只存储单个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: ...