常用命令:
netstat -r
显示路由追踪,可以查看一些网关信息和子网掩码,内网信息
netstat -apn
显示所有进程,并显示端口,进程的pid,再次基础上,可以添加一个管道
添加管道的目的是要筛选查询内容
netstat -apn | grep ssh
此时查到我的ssh进程pid为4810
将这个进程关闭命令
kill -9 4180
其他的netstat命令自己去合理拼接就可以了
附录:netstat-h
usage: netstat [-vWeenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}
netstat [-vWnNcaeol] [<Socket> ...]
netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]
-r, --route display routing table
-I, --interfaces=<Iface> display interface table for <Iface>
-i, --interfaces display interface table
-g, --groups display multicast group memberships
-s, --statistics display networking statistics (like SNMP)
-M, --masquerade display masqueraded connections
-v, --verbose be verbose
-W, --wide don't truncate IP addresses
-n, --numeric don't resolve names
--numeric-hosts don't resolve host names
--numeric-ports don't resolve port names
--numeric-users don't resolve user names
-N, --symbolic resolve hardware names
-e, --extend display other/more information
-p, --programs display PID/Program name for sockets
-o, --timers display timers
-c, --continuous continuous listing
-l, --listening display listening server sockets
-a, --all display all sockets (default: connected)
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
-Z, --context display SELinux security context for sockets
<Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-S|--sctp} {-w|--raw}
{-x|--unix} --ax25 --ipx --netrom
<AF>=Use '-6|-4' or '-A <af>' or '--<af>'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
netstat-h翻译(来源fanyi.baidu.com):
用法:netstat[-vWeenNcCF][<From>]-r netstat{-V-124;--version[-vWeenNcCF;-help}
netstat[-vWnNcaeol][<Socket>…]
netstat{[-vWeenNac]-I[<Iface>]{124;[-veenNac]-I{-124;[-cnne]-M{124s;-s[-6tuw]}[delay]
-r、 ——路由显示路由表
-一、 --接口=<Iface>显示<Iface>的接口表
-i、 ——界面显示界面表
-g、 --组显示多播组成员身份
-s、 --如SNMP统计信息(显示网络统计信息)
-M、 --伪装显示伪装连接
-v、 --冗长
-W、 --宽不截断IP地址
-n、 --数字不解析名称
--数字主机不解析主机名
--数字端口不解析端口名
--数字用户不解析用户名
-N、 --符号解析硬件名称
-e、 --扩展显示其他/更多信息
-p、 --套接字的程序显示PID/程序名
-o、 --计时器显示计时器
-c、 ——连续上市
-l、 --监听显示监听服务器套接字
-a、 --all显示所有套接字(默认值:connected)
-F、 ——fib显示转发信息库(默认)
-C、 --缓存显示路由缓存而不是FIB
Z、 --context显示套接字的SELinux安全上下文
<Socket>={-t-1244;--tcp}{-u-1244;--udp}{-u-1244;--udplite}{-S-1244;--sctp}{-w-1244;--raw}
[x-x-124;--unix}--ax25--ipx--netrom
<AF>=使用'-6-124;-4'或'-A<AF>'或'--<AF>';默认值:inet
可能的地址系列列表(支持路由):
inet(DARPA Internet)inet6(IPv6)ax25(AMPR AX.25)
netrom(AMPR NET/ROM)ipx(Novell ipx)ddp(Appletalk ddp)
x25(CCITT X.25)
在Windows下,陈老师一直习惯上用到 netstat -ano 来帮我们解决Apache Tomcat 8080端口被占用的问题
win下关关闭进程命令
taskkill /f /pid xxxx
/f表示强制关闭