正式班D26

2020.11.11星期三  正式班D26

14.2.2 ifconfig命令

  • ifconfig命令结果解释

    [root@ccc ~]# ifconfig eth0
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        # 从flags可知该接口已启用,支持广播、组播
        # mtu:1500(最大输出单元1500字节)
        # UP:表示接口已启用
        # BROADCAST:表示主机支持广播
        # RUNNING:表示接口在工作中
        # MULTICAST:表示主机支持多播
          inet 192.168.29.55  netmask 255.255.255.0  broadcast 192.168.29.255
            # ipv4地址			子网掩码				广播地址
          inet6 fe80::20c:29ff:fec0:5db3  prefixlen 64  scopeid 0x20<link>
            # ipv6地址					 掩码长度	作用域,link表示仅该接口有效
          ether 00:0c:29:c0:5d:b3  txqueuelen 1000  (Ethernet)
            # 网卡接口的MAC地址		输出队列长度		接口类型为Ethernet
          RX packets 1706  bytes 156657 (152.9 KiB)
        	# 表示开机后此接口累计接收的报文个数,总字节数
          RX errors 0  dropped 0  overruns 0  frame 0
        	# 表示开机后此接口累计接收的报文错误数,丢弃数,溢出数(速度过快而丢失的数据包数),冲突的帧数
          TX packets 1249  bytes 121636 (118.7 KiB)
        	# 表示开机后此接口累计发送的报文数,总字节数
          TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        	# 表示开机后此接口累计发送的报文错误数,丢弃数,溢出数(速度过快而丢失的数据包数)
            # carrier 载荷数(发生carrier错误而丢失的数据包数)
            # collisions 冲突数
    
  • 补充

    # 1、全双工与半双工(目前网卡一般采用全双工模式)
    全双工(Full-Duplex Transmissions)指交换机在发数据的同时也能接收数据,两者同步进行
    全双工延迟小、冲突少、速度快
    半双工指同一时间只有一个动作发生
    
    # CRC
    CRC即循环冗余校验码(Cyclic Redundancy Check)是数据通信领域常用的查错校验码
    特征:信息字段和校验字段的长度可以任意选定。接收设备执行类似的算法,以保证数据传输的正确性和完整性
        
    # 网卡工作原理
    网卡发包:
        1、ip包+14字节的mac头-->数据帧frame
        2、frame拷贝到网卡芯片内的缓冲区,由网卡处理
        3、网卡芯片为frame添加头部同步信息和CRC校验称为可发送的packet,发送该packet
    网卡收包:
        1、网卡包packet到达网卡,网卡先检查packet的CRC校验,保证其完整和正确性,去掉头得frame
        2、网卡将frame拷贝到网卡内部的FIFO缓冲区
        3、网卡驱动程序产生硬件中断,把frame从网卡拷贝到内存,剩下交给内核
        
    网卡丢包:
        1、内核通常要快速的将网络数据包拷贝到系统内存
        2、网卡上接收的网络数据包的缓存大小固定,相比系统内存小得多
        12其一被延迟都会造成网卡FIFO缓存溢出
        进入的数据包占满了网卡的缓存,后续的包只能被丢弃,是ifconfig中overrun的来源
    
  • 解决丢包问题

    # 丢包排查
    网卡工作在数据链路层,数据链路层会做一些校验,封装成帧。
    可以查看校验是否出错,确定传输是否有问题
    其次可以从软件方面,查看是否因为缓冲区太小而丢包
    
    # 1 检查硬件情况
    # 1.1 查看工作模式是否正常
    [root@ccc ~]# ethtool eth0 | egrep -i 'speed|duplex'
    	Speed: 1000Mb/s
    	Duplex: Full
    # 1.2 查看CRC校验是否正常
    [root@ccc ~]# ethtool -S eth0 | grep crc
         rx_crc_errors: 0
    # Speed、Duplex、CRC都没问题,基本排除物理层面的干扰
    
    # 2、通过ifconfig可以看到overruns是否一致增大,如果一直增大
    [root@ccc ~]# for i in `seq 1 100`; do ifconfig eth0 | grep RX | grep overruns; sleep 1;done
            RX errors 0  dropped 0  overruns 0  frame 0
            RX errors 0  dropped 0  overruns 0  frame 0
    
    # 3、调整网卡缓冲区
    [root@ccc ~]# ethtool -g eth0
    Ring parameters for eth0:
    Pre-set maximums:							# 最大可以设置的值
    RX:		4096
    RX Mini:	0
    RX Jumbo:	0
    TX:		4096
    Current hardware settings:					# 当前设置的值
    RX:		256
    RX Mini:	0
    RX Jumbo:	0
    TX:		256
    [root@ccc ~]# ethtool -G eth0 rx 2048		# 调大
    [root@ccc ~]# ethtool -G eth0 tx 2048		# 调大
    [root@ccc ~]# ethtool -g eth0
    Ring parameters for eth0:
    Pre-set maximums:
    RX:		4096
    RX Mini:	0
    RX Jumbo:	0
    TX:		4096
    Current hardware settings:
    RX:		2048
    RX Mini:	0
    RX Jumbo:	0
    TX:		2048
    
  • ethtool网卡降速

    [root@ccc ~]# ethtool -s eth0 speed 100 duplex full
    [root@ccc ~]# ethtool -s eth0 speed 100 duplex full autoneg off
    # 关闭自适应才能成功
    [root@ccc ~]# ethtool eth0		# 查看
    
    想要永久配置需将上述ethtool设置写入配置文件/etc/rc.local
    必须加x权限
    [root@ccc ~]# chmod +x /etc/rc.d/rc.local
    

14.3 路由route

14.3.1 交换与路由

  • 交换

    指同网络访问,两台交换机连接在同一个交换机上,配置同网段的不同IP就可以直接通讯。

  • 一台主机能被当成路由器的必要条件

    1、至少有两块网卡分别连接两个不同的网段

    2、开启路由转发功能

    ​ echo 1 > /proc/sys/net/ipv4/ip_forward

    3、在该linux主机上添加正确的路由规则/策略

    ​ route

    4、其他主机若想要上述linux主机帮自己转发数据包,必须将自己的gw指定成上述linux主机的ip地址

14.3.2 Linux处理数据包的过程

  • 向外界主机发送数据时,在他从网卡流入后需要对他做路由决策,根据其目标决定是流入本机的用户空间还是在内核空间就直接转发给其他主机

    # 1、是流入本机用户空间的数据
    数据会从内核空间流入用户空间(被应用程序接受并处理)
    # 2、不是流入本机用户空间的数据,只经过本机把数据包转发给其他主机
    需开启Linux主机的路由转发功能
    # 临时开启方式一
    echo 1 > /proc/sys/net/ipv4/ip_forward
    # 临时开启方式二
    sysctl -w net.ipv4.ip_forward=1
    # 永久开启改配置文件
    echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/ip_forward.conf
    

14.3.3 网关/路由

  • 主机路由:掩码位32位,Destination精确到某一台主机

    通常主机路由是直接指明到某台具体主机怎么走,主机路由也就是所谓的静态路由

  • 网络路由:掩码位小于32位,Destination精确到某一网段的主机

    网络路由指明到某类网络怎么走

  • 默认路由:掩码为0

    不走主机路由和网络路由的全都走默认路由

    操作系统设置的默认路由一般也称网关

    # 1、在Linux中,路由条目的优先级确定方式是先匹配掩码位长度,越长优先级越高
    # 2、路由条目掩码长度相同时,比较节点之间的管理距离(如metric),短的优先
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.29.1    0.0.0.0         UG    100    0        0 eth0
    192.168.29.0    0.0.0.0         255.255.255.0   U     100    0        0 eth0
    

14.3.4 route命令

  • route命令由于显示和管理路由表

  • route add 增加路由条目,route del 减少路由条目

  • route -n 显示路由表信息,-n选项表示不解析主机名

    route [add/del] [-host/-net/default] [address[/mask]] [netmask] [gw] [dev]
    
    add/del		# 增加或删除路由条目
    -net		# 增肌或删除的是一条网络路由
    -host		# 增加或删除的是一条主机路由
    default		# 增加或删除的是一条默认路由
    netmask		# 明确使用netmask关键字指定掩码,也可直接在地址上用cidr格式的掩码,即IP/MASK
    gw			# 指定下一跳的地址(下一跳的地址必须是能达到的,且一般是与本网段直连的接口)
    dev			# 强制将路由条目关联到指定的接口上(一般内核会自动判断路由条目应该关联到那个网络接口)
    
    # route命令添加的都是临时生效的
    
  • 添加和删除默认路由

    [root@ccc ~]# route add default gw 192.168.29.1
    [root@ccc ~]# route del default 
    [root@ccc ~]# route del default gw 192.168.29.1
    # 如果有多条默认路由,再加上gw可唯一删除指定条目
    # 默认路由的destination和gemask都是0.0.0.0因此可用default代替
    
  • 添加和删除网络路由

    [root@ccc ~]# route add -net 192.168.29.11/24 gw 192.168.29.55
    [root@ccc ~]# route add -net 192.168.29.11 netmask 255.255.255.255 gw 192.168.29.55
    [root@ccc ~]# route del -net 192.168.29.11/24
    [root@ccc ~]# route del -net 192.168.29.11 netmask 255.255.255.255 gw 192.168.29.55
    
  • 添加和删除主机路由

    [root@ccc ~]# route add -host 192.168.29.11/24 gw 192.168.29.55
    [root@ccc ~]# route add -host 192.168.29.11/24
    

14.3.5 配置永久路由

  • 创建配置文件

    /etc/sysconfig/network-scripts/route-ethX

    要从哪个接口出去X就是几

  • 配置文件内容

    DEST via nexthop

    # 默认路由
    default via 192.168.100.1
    # 网段路由
    192.168.10.0/24 via 192.168.100.1
    # 主机路由
    192.168.100.52/32 via 192.168.100.33 dev eth1
    

14.3.6 测试

  • 环境

    交换机 IP 交换机 IP
    交换机1 1.1.1.0 交换机2 2.2.2.0
    交换机3 3.3.3.0 交换机4 4.4.4.0
    主机名 网卡 IP 主机 网卡 IP
    主机1 eth0 1.1.1.6 主机2 eth0 1.1.1.2
    eth1 2.2.2.2
    主机3 eth0 2.2.2.3 主机4 eth0 3.3.3.4
    eth1 3.3.3.3 eth1 4.4.4.4
  • 主机1ping主机2网卡1:1.1.1.6------------->1.1.1.2

    =============================主机1==============================
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    [root@ccc ~]# ping 1.1.1.2
    PING 1.1.1.2 (1.1.1.2) 56(84) bytes of data.
    64 bytes from 1.1.1.2: icmp_seq=1 ttl=64 time=1.05 ms
    ^C
    --- 1.1.1.2 ping statistics ---
    3 packets transmitted, 3 received, 0% packet loss, time 2003ms
    rtt min/avg/max/mdev = 0.326/0.805/1.052/0.338 ms
    
  • 主机1ping主机2网卡2:1.1.1.6------------->2.2.2.2

    =============================主机1==============================
    [root@ccc ~]# ping -c 2 2.2.2.2
    connect: 网络不可达
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    [root@ccc ~]# route add -net 2.2.2.0/24 dev eth0
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     0      0        0 eth0
    [root@ccc ~]# ping -c 2 2.2.2.2
    PING 2.2.2.2 (2.2.2.2) 56(84) bytes of data.
    64 bytes from 2.2.2.2: icmp_seq=1 ttl=64 time=0.552 ms
    64 bytes from 2.2.2.2: icmp_seq=2 ttl=64 time=0.354 ms
    --- 2.2.2.2 ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1000ms
    rtt min/avg/max/mdev = 0.354/0.453/0.552/0.099 ms
    
  • 主机1ping主机3网卡1:1.1.1.6------------->2.2.2.3

    =============================主机1==============================
    [root@ccc ~]# ping -c 2 2.2.2.3
    PING 2.2.2.3 (2.2.2.3) 56(84) bytes of data.
    From 1.1.1.6 icmp_seq=1 Destination Host Unreachable
    From 1.1.1.6 icmp_seq=2 Destination Host Unreachable
    --- 2.2.2.3 ping statistics ---
    2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1001ms pipe 2
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     0      0        0 eth0
    [root@ccc ~]# route add -net 2.2.2.0/24 gw 1.1.1.2 dev eth0
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         1.1.1.2         255.255.255.0   UG    0      0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     0      0        0 eth0
    =============================主机2==============================
    [root@ccc ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
    =============================主机3==============================
    [root@ccc ~]# route add -net 1.1.1.0/24 gw 2.2.2.2 dev eth0
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         2.2.2.2         255.255.255.0   UG    0      0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    3.3.3.0         0.0.0.0         255.255.255.0   U     101    0        0 eth1
    =============================主机1==============================
    [root@ccc ~]# ping -c 2 2.2.2.3
    PING 2.2.2.3 (2.2.2.3) 56(84) bytes of data.
    64 bytes from 2.2.2.3: icmp_seq=1 ttl=63 time=1.60 ms
    64 bytes from 2.2.2.3: icmp_seq=2 ttl=63 time=0.657 ms
    --- 2.2.2.3 ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1000ms
    rtt min/avg/max/mdev = 0.657/1.129/1.602/0.473 ms
    
  • 主机1ping主机3网卡2:1.1.1.6------------->3.3.3.3

    =============================主机1==============================
    [root@ccc ~]# ping -c 2 3.3.3.3
    connect: 网络不可达
    [root@ccc ~]# route add -net 3.3.3.0/24 gw 1.1.1.2 dev eth0
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         1.1.1.2         255.255.255.0   UG    0      0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     0      0        0 eth0
    3.3.3.0         1.1.1.2         255.255.255.0   UG    0      0        0 eth0
    =============================主机2==============================
    [root@ccc ~]# route add -net 3.3.3.0/24 dev eth1
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     101    0        0 eth1
    3.3.3.0         0.0.0.0         255.255.255.0   U     0      0        0 eth1
    =============================主机3==============================
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         2.2.2.2         255.255.255.0   UG    0      0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    3.3.3.0         0.0.0.0         255.255.255.0   U     101    0        0 eth1
    =============================主机1==============================
    [root@ccc ~]# ping -c 2 3.3.3.3
    PING 3.3.3.3 (3.3.3.3) 56(84) bytes of data.
    64 bytes from 3.3.3.3: icmp_seq=1 ttl=63 time=1.44 ms
    64 bytes from 3.3.3.3: icmp_seq=2 ttl=63 time=0.797 ms
    --- 3.3.3.3 ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1002ms
    rtt min/avg/max/mdev = 0.797/1.121/1.446/0.326 ms
    
  • 主机1ping主机4网卡1:1.1.1.6------------->3.3.3.4

    =============================主机1==============================
    [root@ccc ~]# ping -c 2 3.3.3.4
    PING 3.3.3.4 (3.3.3.4) 56(84) bytes of data.
    From 1.1.1.2 icmp_seq=1 Destination Host Unreachable
    From 1.1.1.2 icmp_seq=2 Destination Host Unreachable
    --- 3.3.3.4 ping statistics ---
    2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1000ms
    pipe 2
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         1.1.1.2         255.255.255.0   UG    0      0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     0      0        0 eth0
    3.3.3.0         1.1.1.2         255.255.255.0   UG    0      0        0 eth0
    =============================主机2==============================
    [root@ccc ~]# route add -net 3.3.3.0/24 gw 2.2.2.3 dev eth1
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     101    0        0 eth1
    3.3.3.0         2.2.2.3         255.255.255.0   UG    0      0        0 eth1
    3.3.3.0         0.0.0.0         255.255.255.0   U     0      0        0 eth1
    =============================主机3==============================
    [root@ccc ~]# echo 1 > /proc/sys/net/ipv4/ip_forward
    =============================主机4==============================
    [root@ccc ~]# route add -net 1.1.1.0/24 gw 3.3.3.3 dev eth0
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         3.3.3.3         255.255.255.0   UG    0      0        0 eth0
    3.3.3.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    4.4.4.0         0.0.0.0         255.255.255.0   U     101    0        0 eth1
    =============================主机1==============================
    [root@ccc ~]# ping -c 2 3.3.3.4
    PING 3.3.3.4 (3.3.3.4) 56(84) bytes of data.
    64 bytes from 3.3.3.4: icmp_seq=1 ttl=62 time=1.71 ms
    64 bytes from 3.3.3.4: icmp_seq=2 ttl=62 time=1.16 ms
    
    --- 3.3.3.4 ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1002ms
    rtt min/avg/max/mdev = 1.162/1.440/1.718/0.278 ms
    
  • 主机1ping主机4网卡2:1.1.1.6------------->4.4.4.4

    =============================主机1==============================
    [root@ccc ~]# route add -net 4.4.4.0/24 gw 1.1.1.2 dev eth0
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         1.1.1.2         255.255.255.0   UG    0      0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     0      0        0 eth0
    3.3.3.0         1.1.1.2         255.255.255.0   UG    0      0        0 eth0
    4.4.4.0         1.1.1.2         255.255.255.0   UG    0      0        0 eth0
    =============================主机2==============================
    [root@ccc ~]# route add -net 4.4.4.0/24 gw 2.2.2.3 dev eth1
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     101    0        0 eth1
    3.3.3.0         2.2.2.3         255.255.255.0   UG    0      0        0 eth1
    3.3.3.0         0.0.0.0         255.255.255.0   U     0      0        0 eth1
    4.4.4.0         2.2.2.3         255.255.255.0   UG    0      0        0 eth1
    =============================主机3==============================
    [root@ccc ~]# route add -net 4.4.4.0/24 dev eth1
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         2.2.2.2         255.255.255.0   UG    0      0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    3.3.3.0         0.0.0.0         255.255.255.0   U     101    0        0 eth1
    4.4.4.0         0.0.0.0         255.255.255.0   U     0      0        0 eth1
    =============================主机4==============================
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         3.3.3.3         255.255.255.0   UG    0      0        0 eth0
    3.3.3.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    4.4.4.0         0.0.0.0         255.255.255.0   U     101    0        0 eth1
    =============================主机1==============================
    [root@ccc ~]# ping -c 2 4.4.4.4
    PING 4.4.4.4 (4.4.4.4) 56(84) bytes of data.
    64 bytes from 4.4.4.4: icmp_seq=1 ttl=62 time=1.77 ms
    64 bytes from 4.4.4.4: icmp_seq=2 ttl=62 time=0.972 ms
    --- 4.4.4.4 ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 1002ms
    rtt min/avg/max/mdev = 0.972/1.375/1.778/0.403 ms
    
  • 优化

    =============================主机1==============================
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         1.1.1.2         255.255.255.0   UG    0      0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     0      0        0 eth0
    3.3.3.0         1.1.1.2         255.255.255.0   UG    0      0        0 eth0
    4.4.4.0         1.1.1.2         255.255.255.0   UG    0      0        0 eth0
    [root@ccc ~]# route del -net 2.2.2.0/24 dev eth0
    [root@ccc ~]# route del -net 2.2.2.0/24 dev eth0
    [root@ccc ~]# route del -net 3.3.3.0/24 dev eth0
    [root@ccc ~]# route del -net 4.4.4.0/24 dev eth0
    [root@ccc ~]# route add default gw 1.1.1.2 dev eth0
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         1.1.1.2         0.0.0.0         UG    0      0        0 eth0
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    =============================主机2==============================
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     101    0        0 eth1
    3.3.3.0         2.2.2.3         255.255.255.0   UG    0      0        0 eth1
    3.3.3.0         0.0.0.0         255.255.255.0   U     0      0        0 eth1
    4.4.4.0         2.2.2.3         255.255.255.0   UG    0      0        0 eth1
    [root@ccc ~]# route del -net 3.3.3.0/24 dev eth1
    [root@ccc ~]# route del -net 3.3.3.0/24 dev eth1
    [root@ccc ~]# route del -net 4.4.4.0/24 dev eth1
    [root@ccc ~]# route add -net default gw 2.2.2.3 dev eth1
    [root@ccc ~]# route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         2.2.2.3         0.0.0.0         UG    0      0        0 eth1
    1.1.1.0         0.0.0.0         255.255.255.0   U     100    0        0 eth0
    2.2.2.0         0.0.0.0         255.255.255.0   U     101    0        0 eth1
    
原文地址:https://www.cnblogs.com/caojiaxin/p/13961505.html