• 常用网络操作命令整理


    场景一:装完操作系统,一条命令重启全部网卡

    for item in `ip a | grep DOWN | awk '{print $2}'| sed 's/.$//'`;do ifconfig $item up;done

    命令解释:

    这个命令用到了 shell 的一些基本用法:

    for 循环:for...do...done

    变量的表示:$item

    awk:输出每行文本的第二段 

    sed:去除最后一个字符 sed 's/old/new/'

    正则表达:.$ ,点号表示通配符,$表示以此结尾,合在一起就是表示最后一个字符

    网卡启停命令: ifconfig eth0 up

     

    场景二:配置bond1模式

    vim /etc/network/interfaces #ubuntu系统
    
    auto lo
    iface lo inet loopback
    
    auto p7p1
    iface p7p1 inet manual
    bond-master bond0
    
    auto p6p1
    iface p6p1 inet manual
    bond-master bond0
    
    auto bond0
    iface bond0 inet static
      address 200.200.126.19
      netmask 255.255.255.0
      gateway 200.200.126.253
      bond-mode 1
      bond-miimon 100
      bond-slaves p7p1 p6p1

    命令解释:

    为2 张网卡绑定bond,命名为 bond0,模式为 bond1 主备模式。

    配置完成后 2 张网卡的 mac 会和 bond0 显示为一致,IP 会显示在 bond 0上。

     

    场景三:检查当前bond以及bond配置是否生效

    cat /proc/net/bonding/bond0

    Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

    Bonding Mode: fault-tolerance (active-backup)
    Primary Slave: None
    Currently Active Slave: p7p1
    MII Status: up
    MII Polling Interval (ms): 100
    Up Delay (ms): 0
    Down Delay (ms): 0

    Slave Interface: p6p1
    MII Status: up
    Speed: 10000 Mbps
    Duplex: full
    Link Failure Count: 1
    Permanent HW addr: 90:e2:ba:de:55:88
    Slave queue ID: 0

    Slave Interface: p7p1
    MII Status: up
    Speed: 10000 Mbps
    Duplex: full
    Link Failure Count: 0
    Permanent HW addr: 90:e2:ba:de:17:a8
    Slave queue ID: 0

    命令解释:

    查看当前bond 工作网卡 currently active slave

    查看网卡工作状态 MII Status

    查看连接出现的历史错误统计数 link failure

    场景四:抓包分析

    tcpdump -n -S -i eth0 host example.com -w example.pcap
    
        -n 打印 IP而不是 hostname
        -S 打印绝对时间戳
        -i 指定网卡
        host 抓和 example.com 交互的包
        -w 将抓到的包写入到文件

    抓包分析

    packet TCP flags,其中
    
    S 表示 syn 包
    . 表示 ack 包
    F 表示 fin 包
    P 表示 push 包(发送正常数据)
    
    TCP 三次握手分别是 [s][s.][.]
    TCP 四次挥手分别是 [F][.][F.][.]

    场景四:检查连通性

    ping
    
        -c 设置ping的次数
  • 相关阅读:
    虚拟机docker开启服务,本地无法进行访问
    make编译提示:make cc Command not found 解决办法
    yum -y install git 无法安装...提示There are no enabled repos.
    linux 安装mysql
    linux 配置环境变量
    HTML5第三天 无序有序列表、相对绝对路径
    JavaScript第一天
    HTML第二天
    mysql流程控制语句
    mysql存储过程和函数
  • 原文地址:https://www.cnblogs.com/handsomehuo/p/12510630.html
Copyright © 2020-2023  润新知