Linux常用网络相关命令

ifconfig

ifconfig用于设置或显示网络设备信息

ifconfig
docker0   Link encap:Ethernet  HWaddr 6A:E6:66:31:F6:F1  
          inet addr:172.17.42.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::68e6:66ff:fe31:f6f1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 b)  TX bytes:468 (468.0 b)

eth0      Link encap:Ethernet  HWaddr 00:15:5D:3A:BB:7A  
          inet addr:10.201.83.207  Bcast:10.201.83.255  Mask:255.255.252.0
          inet6 addr: fe80::215:5dff:fe3a:bb7a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1111821741 errors:0 dropped:564 overruns:0 frame:0
          TX packets:88198368 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:99834908362 (92.9 GiB)  TX bytes:22017797332 (20.5 GiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:509170 errors:0 dropped:0 overruns:0 frame:0
          TX packets:509170 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:87619569 (83.5 MiB)  TX bytes:87619569 (83.5 MiB)
# 关闭eth0网卡
ifconfig eth0 down
#启动eth0网卡
ifconfig eth0 up
# 为eth0网卡增加ipv6地址
ifconfig eth0 add 33ffe:3240:800:1005::2/ 64
#为eth0网卡珊瑚ipv6地址
ifconfig eth0 del 33ffe:3240:800:1005::2/ 64 
# 为eth0网卡设置IP,子网掩码,广播地址
ifconfig eth0 192.168.1.19 netmask 255.255.255.0 broadcast 192.168.1.255

# 为eth0设置mac地址
ifconfig eth0 hw ether 00:15:5D:3A:BB:7A
# eth0网卡开启arp协议
ifconfig eth0 arp 
# eth0关闭arp协议
ifconfig eth0 -arp
netstat
 netstat  [address_family_options]  [--tcp|-t]  [--udp|-u]  [--raw|-w]  [--listening|-l]  [--all|-a]   [--numeric|-n]
       [--numeric-hosts][--numeric-ports][--numeric-ports] [--symbolic|-N] [--extend|-e[--extend|-e]] [--timers|-o] [--pro-
       gram|-p] [--verbose|-v] [--continuous|-c] [delay]

       netstat {
    
    --route|-r} [address_family_options] [--extend|-e[--extend|-e]] [--verbose|-v]  [--numeric|-n]  [--numeric-
       hosts][--numeric-ports][--numeric-ports] [--continuous|-c] [delay]

       netstat   {
    
    --interfaces|-I|-i}   [iface]   [--all|-a]  [--extend|-e]  [--verbose|-v]  [--program|-p]  [--numeric|-n]
       [--numeric-hosts][--numeric-ports][--numeric-ports] [--continuous|-c] [delay]

       netstat {
    
    --groups|-g} [--numeric|-n] [--numeric-hosts][--numeric-ports][--numeric-ports] [--continuous|-c] [delay]

       netstat {
    
    --masquerade|-M} [--extend|-e] [--numeric|-n]  [--numeric-hosts][--numeric-ports][--numeric-ports]  [--con-
       tinuous|-c] [delay]

       netstat {
    
    --statistics|-s} [--tcp|-t] [--udp|-u] [--raw|-w] [delay]

       netstat {
    
    --version|-V}

       netstat {
    
    --help|-h}

       address_family_options:
       [--protocol={
    
    inet,inet6,unix,ipx,ax25,netrom,ddp,  ...  }  ]  [--unix|-x]  [--inet|--ip] [--ax25] [--ipx] [--netrom]
       [--ddp]

参数列表:

  • -a或--all 显示所有连线中的Socket。
  • -A<网络类型>或–<网络类型> 列出该网络类型连线中的相关地址。
  • -c或–continuous 持续列出网络状态。
  • -C或–cache 显示路由器配置的快取信息。
  • -e或–extend 显示网络其他相关信息。
  • -F或–fib 显示路由缓存。
  • -g或–groups 显示多重广播功能群组组员名单。
  • -h或–help 在线帮助。
  • -i或–interfaces 显示网络界面信息表单。
  • -l或--listening 显示监控中的服务器的Socket。
  • -M或–masquerade 显示伪装的网络连线。
  • -n或--numeric 直接使用IP地址,而不通过域名服务器。
  • -N或–netlink或–symbolic 显示网络硬件外围设备的符号连接名称。
  • -o或–timers 显示计时器。
    --p或--programs 显示正在使用Socket的程序识别码和程序名称。
  • -r或–route 显示Routing Table。
  • -s或–statistics 显示网络工作信息统计表。
  • -t或--tcp 显示TCP传输协议的连线状况。
  • -u或–udp 显示UDP传输协议的连线状况。
  • -v或–verbose 显示指令执行过程。
  • -V或–version 显示版本信息。
  • -w或–raw 显示RAW传输协议的连线状况。
  • -x或–unix 此参数的效果和指定"-A unix"参数相同。
  • –ip或–inet 此参数的效果和指定"-A inet"参数相同。

tcpdump

 tcpdump [ -AdDefIKlLnNOpqRStuUvxX ] [ -B buffer_size ] [ -c count ]
               [ -C file_size ] [ -G rotate_seconds ] [ -F file ]
               [ -i interface ] [ -m module ] [ -M secret ]
               [ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]
               [ -W filecount ]
               [ -E spi@ipaddr algo:secret,...  ]
               [ -y datalinktype ] [ -z postrotate-command ] [ -Z user ]
               [ expression ]

arp

arp用来查询系统arp缓存信息

NAME
       arp - manipulate the system ARP cache

SYNOPSIS
       arp [-evn] [-H type] [-i if] -a [hostname]

       arp [-v] [-i if] -d hostname [pub]

       arp [-v] [-H type] [-i if] -s hostname hw_addr [temp]

       arp [-v] [-H type] [-i if] -s hostname hw_addr [netmask nm] pub

       arp [-v] [-H type] [-i if] -Ds hostname ifa [netmask nm] pub

       arp [-vnD] [-H type] [-i if] -f [filename]

NOTE
       This program is obsolete. For replacement check ip neighbor.

route

route用来设置和查询当前系统IP路由表

OUTE(8)                   Linux Programmer’s Manual                  ROUTE(8)

NAME
       route - show / manipulate the IP routing table

SYNOPSIS
       route [-CFvnee]

       route  [-v] [-A family] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss M] [window W] [irtt I] [reject] [mod] [dyn] [reinstate] [[dev] If]

       route  [-v] [-A family] del [-net|-host] target [gw Gw] [netmask Nm] [metric N] [[dev] If]

       route  [-V] [--version] [-h] [--help]

  • -A 设置地址类型( 默认IPv4)
  • -C 打印linux核心的路由缓存
  • -v 详细信息模式
  • -n 不执行DNS反向查找,直接显示数字形式的ip地址
  • -e netstat格式显示路由表
  • -net 到一个网络的路由表
  • -host 到一个主机的路由表
  • add 增加指定的路由记录
  • del 删除指定的路由记录
  • Target 目的网络或目的主机
  • gw 设置默认网关
  • mss 设置TCP的最大区块长度(MSS),单位MB
  • window 指定通过路由表的TCP连接的TCP窗口大小
  • dev 路由记录所表示的网卡,后面接网卡名称
    例如:
#添加路由
route add -net 1.1.1.2 netmask 255.255.255.0 eth0
#删除路由
 route del -net 192.168.60.11 netmask 192.168.60.1 dev ens192 

ping

通过ICMP协议测试主机与目标主机是否连通

SYNOPSIS
       ping  [ -LRUbdfnqrvVaAB]  [ -c count]  [ -i interval]  [ -l preload]  [ -p pattern]  [ -s packetsize]  [ -t ttl]  [ -w deadline]  [ -F flowlabel]  [ -I interface]  [ -M
       hint]  [ -Q tos]  [ -S sndbuf]  [ -T timestamp option]  [ -W timeout]  [ hop ...]  destination

DESCRIPTION
       ping uses the ICMP protocol’s mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway.  ECHO_REQUEST datagrams (‘‘pings’’) have an IP and
       ICMP header, followed by a struct timeval and then an arbitrary number of ‘‘pad’’ bytes used to fill out the packet.

  • -d 使用Socket的SO_DEBUG功能。
  • -c <完成次数> 设置完成要求回应的次数。
  • -f 极限检测。
  • -i<间隔秒数> 指定收发信息的间隔时间。
  • -I<网络界面> 使用指定的网络接口送出数据包。
  • -l<前置载入> 设置在送出要求信息之前,先行发出的数据包。
  • -n 只输出数值。
  • -p<范本样式> 设置填满数据包的范本样式。
  • -q 不显示指令执行过程,开头和结尾的相关信息除外。
  • -r 忽略普通的Routing Table,直接将数据包送到远端主机上。
  • -R 记录路由过程。
  • -s<数据包大小> 设置数据包的大小。
  • -t<存活数值> 设置存活数值TTL的大小。
  • -v 详细显示指令的执行过程。
  • -w 在 deadline 秒后退出。
  • -W 在等待 timeout 秒后开始执行。
    实例

Guess you like

Origin blog.csdn.net/LeoHan163/article/details/117217055