network command
network related command
net-tools
deprecated
https://github.com/ecki/net-tools
$ sudo apt-get install net-tools
ifconfig
查看本地网络接口状态和流量
ifconfig # 查看up的interface
ifconfig -a # 查看所有的interface
ifconfig <interface> # 查看指定的interface
ifconfig <bridge>/<interface> up/down
netstat
用于查看网络连接、路由表、接口统计等信息.
netstat
-a, --all, --listening # 显示所有socket, 默认只显示connected
-l, --listening # 显示listening
-n, --numeric
-p, --programs # 显示pid或程序名称
# socket选项:
-t, --tcp
-u, --udp
-w, --raw
-x, --unix
--ax25
--ipx
--netrom
# 常用
netstat -anp # 查看哪些端口是打开的.
sudo netstat -anp | grep port # 查看端口是否被使用
sudo netstat -tulnp # 查看tcp&udp端口是否被监听
arp
arp # 用于确定IP地址的网卡物理地址
route
Flags:
- U: route is up
- H: target is a host
- G: use gateway
- !: reject route
Genmask: netmask for destination net.
Metric: 到target距离, hops.
Ref: 该路由引用次数
Use: 查找路由的次数
route -n
rarp
hostname
domainname
dnsdomainname
iproute2
https://github.com/shemminger/iproute2
$ sudo apt-get install iproute2
ss
取代netstat, 用于查看socket连接状态.
ss -s # 查看socket统计信息
ss -tuln # 查看tcp和udp的监听端口
ss -tulnp # 查看tcp和udp的监听端口和对应的程序
ip
取代ifconfig, route, arp等命令的集合.
ip link show
# 创建vlan
ip link add link eth1 name eth1.10 type vlan id 10
# 添加ip
ip addr add 192.168.100.1/24 brd 192.168.100.255 dev eth1.10
# 启动vlan
ip link set dev eth1.10 up
# 关闭vlan
ip link set dev eth1.10 down
# 删除vlan
ip link delete eth1.10
addr/address
ip addr show <interface> # 查看指定interface的ip地址
route
ip route show # 查看路由表
rule
ip rule showa # 查看规则
devlink
ifstat
bridge
用于管理bridge, 取代brctl.
$ bridge link show # 查看bridge的接口
iputils
https://github.com/iputils/iputils
$ sudo apt-get install iputils-ping
ping
round-trip time/RTT: 往返时间, 即从发送数据包到接收数据包的时间.
ping # 用于确定网络的连通性
ping -c 5 <host> # 发送5个包
arping
tracepath
clockdiff
traceroute
sudo apt install traceroute
路由跟踪与跳数检查
traceroute <host> # 跟踪到host的路由
# 通过指定端口号来跟踪
traceroute -p <port> <host>
# 使用tcp协议
traceroute -T <host>
# 使用udp协议
traceroute -U <host>
tcpdump
sudo apt-get install tcpdump
tcpdump
tcpdump tcp port <port> # 抓tcp 在port端口的包
tcpdump udp port <port> #抓udp 在port端口的包
tcpdump -i <interface> # 抓取指定interface的包
tcpdump host <ip> and port <port> # 抓取指定ip和端口的包
tcpdump net <network> # 抓取指定网络的包
nc/netcat
// 有的系统默认安装netcat-traditional
$ sudo apt-get install netcat-traditional
// 安装netcat-openbsd
$ sudo apt-get install netcat-openbsd
// 设置默认值
$ sudo update-alternatives --config nc
$ sudo update-alternatives --set nc /bin/nc.openbsd
nc -z IP PORT # 查看指定tcp://ip:port是否监听
nc -zu IP PORT # 查看udp://ip:port是否监听
// 通过nc监听端口
nc -l PORT
// 通过nc发送请求.
echo -e '{"method":"test","params":["test"],"id":1}' | nc IP PORT
dnsutils
sudo apt-get install dnsutils
nslookup
nslookup # 查询IP地址和对应的域名
dig
dig # 查询DNS记录
dig @<dns-server> <domain> # 指定dns服务器查询域名
dig <domain> A # 查询A记录
dig <domain> MX # 查询MX记录
dig <domain> NS # 查询NS记录
dig <domain> TXT # 查询TXT记录
dig <domain> ANY # 查询所有记录
# 反向解析IP地址
dig -x <ip-address>
nsupdate
host
ethtool
sudo apt-get install ethtool
ethtool # 查询网络设备信息
ethtool <interface> # 查询指定网络设备信息
iftop
http://www.ex-parrot.com/~pdw/iftop/
$ sudo apt-get install iftop
sudo iftop # 查看网络流量
sudo iftop -i <interface> # 查看指定网络接口的流量
iperf3
wget
wget [option] [URL]
-a, --append-output=FILE 输出重定向到日志
-o, --output-file=FILE
-q, --quiet 不输出
-b, --background
-nv, --no-verbose
--header "authorization:c2FuZGJveDpTMG5pY3dhbGwK"
-t, --tries=NUMBER 超时重连次数, 0表示不限制, 默认20
-nc, --no-clobber 不覆盖原有文件
-N, --timestamping 只下载比本地新的文件
-c, --continue 断点续传,会覆盖-N
-T, --timeout=SECONDS 超时时间, 默认900s
-w, --wait=SECONDS 重连之间的等待时间
-O, --output-document=FILE, 重命名下载文件
-nH, --no-host-directories 不创建站点的根目录
-x, --force-directories 创建和服务器一样的结构下载
-P, --directory-prefix=PREFIX 指定下载的目录
-R, --reject=LIST 排除下载的文件
-r, --recursive 迭代下载
-np, --no-parent 不下载父目录的内容
# 同步目录
wget -Nc -r -np -nH --cut-dirs=3 -R "index.*, *.js, *.css, *.html, *.jpg, *.png, *.gif" -P /path/to/source/ http://host/path/to/dest/
# ssl + basic auth
wget --no-check-certificate --user <user> --password <pw> -nv -N -P <dest-folder> <src-url>
$ wget -q -N -P /folder url
$ wget -q -c -O /path/to/file.ext url
curl
curl
-X/--request post/patch/delte/get/...
-H/--header 'content-type: application/json'
-d/--data '{"key": "value"}'
--data-raw DATA HTTP POST data, '@' allowed (H)
--data-ascii DATA HTTP POST ASCII data (H)
--data-binary DATA HTTP POST binary data (H)
--data-urlencode DATA HTTP POST data url encoded (H)
-G, --get Send the -d data with a HTTP GET (H)
-k/--insecure ignore ssl check.
-u/--user <user:password>
-s/--silent Silent mode