zoukankan      html  css  js  c++  java
  • linux网络配置、设备和状态管理:ifconfig,ethtool,iftop,tcpdump

    配置文件

    网卡配置

    vi /etc/sysconfig/network-scripts/ifcfg-eth0

    DEVICE=eth0 #描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth0
    BOOTPROTO=static #设置网卡获得ip地址的方式,可能的选项为static,dhcp或bootp,分别对应静态指定的 ip地址,通过dhcp协议获得的ip地址,通过bootp协议获得的ip地址
    BROADCAST=192.168.0.255 #对应的子网广播地址
    HWADDR=00:07:E9:05:E8:B4 #对应的网卡物理地址
    IPADDR=12.168.1.2 #如果设置网卡获得 ip地址的方式为静态指定,此字段就指定了网卡对应的ip地址
    IPV6INIT=no
    IPV6_AUTOCONF=no
    NETMASK=255.255.255.0 #网卡对应的网络掩码
    NETWORK=192.168.1.0 #网卡对应的网络地址
    ONBOOT=yes #系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备

    网关配置

    vi /etc/sysconfig/network
    
    NETWORKING=yes
    HOSTNAME=Aaron
    GATEWAY=192.168.1.1
    NETWORKING_IPV6=no
    PEERNTP=no

    DNS配置

    vi /etc/resolv.conf
    
    nameserver 8.8.8.8 
    nameserver 8.8.4.4 

    重启网配置

    //方法1:
    service network restart
    
    //方法2:
    ifconfig eth0 down #换成相应的网卡名,eth0表示第1块网卡
    ifconfig eth0 up

    测试宽带

    [root@01 ~]# wget https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
    chmod +rx speedtest.py
    [root@01 ~]# sudo mv speedtest.py /usr/local/bin/speedtest-cli
    [root@01 ~]# sudo chown root:root /usr/local/bin/speedtest-cli
    [root@01 ~]# speedtest-cli

    ifconfig

    参考:

    https://www.runoob.com/linux/linux-comm-ifconfig.html

    可设置网络设备的状态,或是显示目前的设置。

    ifconfig  #显示网络设备信息
    
    ifconfig eth0 down #关闭指定网卡
    ifconfig eth0 up #打开指定网卡
    
    ifconfig eth0 add 33ffe:3240:800:1005::2/ 64 #为网卡设置IPv6地址
    ifconfig eth0 del 33ffe:3240:800:1005::2/ 64 #为网卡删除IPv6地址
    
    ifconfig eth0 down //关闭网卡
    ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址
    ifconfig eth0 up //启动网卡
    
    ifconfig eth0 arp  #开启arp协议
    ifconfig eth0 -arp  #关闭arp协议
    
    ifconfig eth0 mtu 1500 #设置最大传输单元

    ethtool

    参考:

    https://www.cnblogs.com/danxi/p/6591885.html

    ethtool eth0       //查询ethx网口基本设置,其中 x 是对应网卡的编号,如eth0、eth1等等
    ethtool –h        //显示ethtool的命令帮助(help)
    ethtool –i eth0    //查询eth0网口的相关信息
    ethtool –d eth0    //查询eth0网口注册性信息
    ethtool –r eth0    //重置eth0网口到自适应模式
    ethtool –S eth0    //查询eth0网口收发包统计
    ethtool –s eth0 [speed 10|100|1000] [duplex half|full]  [autoneg on|off]        //设置网口速率10/100/1000M、设置网口半/全双工、设置网口是否自协商
    ethtool -k eth0

    iftop

    参考:

    https://blog.csdn.net/mimi_csdn/article/details/79377344

    常用参数:

    -i设定监测的网卡,如:# iftop -i eth1

    -B 以bytes为单位显示流量(默认是bits),如:# iftop -B

    -n使host信息默认直接都显示IP,如:# iftop -n

    -N使端口信息默认直接都显示端口号,如: # iftop -N

    -F显示特定网段的进出流量,如# iftop -F 10.10.1.0/24或# iftop -F 10.10.1.0/255.255.255.0

    -h(display this message),帮助,显示参数信息

    -p使用这个参数后,中间的列表显示的本地主机信息,出现了本机以外的IP信息;

    -b使流量图形条默认就显示;

    -f这个暂时还不太会用,过滤计算包用的;

    -P使host信息及端口信息默认就都显示;

    -m设置界面最上边的刻度的最大值,刻度分五个大段显示,例:# iftop -m 100M

    yum install -y iftop
    iftop
    
    #参数解释: 中间的<
    = =>这两个左右箭头,表示的是流量的方向。 TX:发送流量 RX:接收流量 TOTAL:总流量 Cumm:运行iftop到目前时间的总流量 peak:流量峰值 rates:分别表示过去 2s 10s 40s 的平均流量

    tcpdump

    参考:

    https://www.jianshu.com/p/d9162722f189

    tcpdump [ -DenNqvX ] [ -c count ] [ -F file ] [ -i interface ] [ -r file ]
            [ -s snaplen ] [ -w file ] [ expression ]
    
    tcpdump -i ens33
    
    tcpdump -c 10 -q #精简模式显示 10个包
    
    tcpdump -i ens33 -c 10 net 192.168 #本机与192.168网段通信的数据包
    
    tcpdump -c 10 -nn -i ens33 tcp dst port 22
  • 相关阅读:
    cnpm 安装和 command not found
    C#-弄懂泛型和协变、逆变
    2019年阅读
    ES5和ES6数组方法
    ASP.NET MVC中的捆绑和压缩技术
    markdown解析与着色
    Oauth2.0
    同源策略和跨域的解决方案
    windows常用命令
    Java 9 在win10环境搭建
  • 原文地址:https://www.cnblogs.com/tkzc2013/p/14440111.html
Copyright © 2011-2022 走看看