• Linux 下用route命令修改默认网关,不用重启网络


    有时候在实际运维工作,需要修改主机网关又不想重启网卡服务(在低版本的linux偶尔遇到service network restart失败的情况),可以通过route 命令方式修改主机的默认网关(当然主机的配置文件也要随之修改,否则重启后网关就失效了

    查看当前的网关配置

    1
    2
    3
    4
    5
    6
    7
    # route -v  或 netstat -rn
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    192.168.10.0    *               255.255.255.224 U     0      0        0 bond0
    192.168.20.0    *               255.255.255.0   U     0      0        0 bond0
    link-local      *               255.255.0.0     U     1004   0        0 bond0
    default         192.168.20.1    0.0.0.0         UG    0      0        0 bond0

     上面显示的默认网关为192.168.20.1

    删除默认网关

    用如下命令删除默认网关:

    1
    #route del default gw xxx.xxx.xxx.xxx

    例如:

    1
    #route del default gw 192.168.20.1

    添加默认网关

    添加一条路由,输入:

    1
    #route add default gw 192.168.20.12

    查看网关配置

    1
    2
    3
    4
    5
    6
    7
    # netstat -rn
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
    192.168.10.0    0.0.0.0         255.255.255.224 U         0 0          0 bond0
    192.168.20.0    0.0.0.0         255.255.255.0   U         0 0          0 bond0
    169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 bond0
    0.0.0.0         192.168.20.12    0.0.0.0         UG        0 0          0 bond

     网关已经变更

  • 相关阅读:
    ps cc 2018安装
    eclipse 快速添加 set , get 方法
    电脑设置以太网
    C# 获取web.config配置文件内容
    C# @Page指令中的AutoEventWireup,CodeBehind,Inherits
    未能正确加载“Microsoft.VisualStudio.Implementation.EditorPackage”包
    C# 实现MD5加密
    mutex 简单介绍
    select @@IDENTITY
    C# vs2012创建报表
  • 原文地址:https://www.cnblogs.com/xzlive/p/14363326.html
Copyright © 2020-2023  润新知