zoukankan      html  css  js  c++  java
  • 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

     网关已经变更

  • 相关阅读:
    C# 调用AForge类库操作摄像头
    Composer简介及使用实例
    asp.net mvc 接入美圣短信 验证码发送
    敏捷模式下携程的接口自动化平台演变
    17个Python的牛逼骚操作,你都OK吗?
    如何打造一份优雅的简历?
    谈谈少儿编程
    打基础一定要吃透这12类 Python 内置函数
    求职日记丨秋招面试零失败,我拿下宝洁、华为、壳牌等offer
    我只想找个测试岗,你却百般刁难我!
  • 原文地址:https://www.cnblogs.com/xzlive/p/14363326.html
Copyright © 2011-2022 走看看