影响Linux系统网络中网关配置信息的3种方式

1.生效文件cat /etc/sysconfig/network-scripts/ifcfg-eth0

GATEWAY=10.0.0.254 <- 局域网上网网关地址

命令行优先,且临时生效

[root@host01 ~]# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0

10.0.1.0        10.0.0.11       255.255.255.0   UG    0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0

0.0.0.0         10.0.0.254      0.0.0.0         UG    0      0        0 eth0

[root@host01 ~]# netstat -nr

Kernel IP routing table

Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

10.0.0.0        0.0.0.0         255.255.255.0   U         0 0          0 eth0

10.0.1.0        10.0.0.11       255.255.255.0   UG        0 0          0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0

0.0.0.0         10.0.0.254      0.0.0.0         UG        0 0          0 eth0

route命令添加

[root@host01 ~]# route add default gw 10.0.0.253

[root@host01 ~]# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0

10.0.1.0        10.0.0.11       255.255.255.0   UG    0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0

0.0.0.0         10.0.0.253      0.0.0.0         UG    0      0        0 eth0

route命令删除

[root@host01 ~]# route del default gw 10.0.0.253

[root@host01 ~]# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0

10.0.1.0        10.0.0.11       255.255.255.0   UG    0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0

查看路由表信息 ----局域网----不用到网关(局域网)

避免为了没有DHCP服务器,如果没有dhcp后会吧自己模拟成169.254.0.0

[root@host01 ~]# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0

10.0.1.0        10.0.0.11       255.255.255.0   UG    0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0

0.0.0.0         10.0.0.254      0.0.0.0         UG    0      0        0 eth0

代表到达任意地址的时候,通过网关

默认的网关路由(没有这一条出不了外网)

0.0.0.0         10.0.0.254      0.0.0.0         UG    0      0        0 eth0

临时删除网关路由条目方法

[root@host01 ~]# route del default 10.0.0.254

SIOCDELRT: No such device

[root@host01 ~]# route del default gw 10.0.0.254

[root@host01 ~]# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0

10.0.1.0        10.0.0.11       255.255.255.0   UG    0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0

小结:

Ping域名的时候需要解析,wan

PingIP不需要解析:

Ping内网   在254内

Ping网关同的外网不行

[root@host01 ~]# ping 10.0.0.254

PING 10.0.0.254 (10.0.0.254) 56(84) bytes of data.

64 bytes from 10.0.0.254: icmp_seq=1 ttl=128 time=0.480 ms

64 bytes from 10.0.0.254: icmp_seq=2 ttl=128 time=0.252 ms

2.生效文件 /etc/sysconfig/network

GATEWAY=10.0.0.254 有地时候没有(工作可能有)

route 配置默认网关的更多相关文章

  1. CENTOS 7 下配置默认网关

    1. ip route 显示和设定路由 1.1 显示路由表 [root@linux-node1 ~]# ip route show default via 192.168.56.2 dev eth0 ...

  2. 路由器与交换机配置——交换机默认网关(实现跨网段telnet)

    一.实验目的:配置一台交换机,并配置默认网关,使不同网段的主机能够远程telnet登录连接到交换机 二.实验拓扑图如下: 二.实验步骤: 1.首先给PC1主机配置ip地址和网关(gateway) -- ...

  3. 理解Windows中的路由表和默认网关

    每一个Windows系统中都具有IP路由表,它存储了本地计算机可以到达的网络目的地址范围和如何到达的路由信息.路由表是TCP/IP通信的基础,本地计算机上的任何TCP/IP通信都受到路由表的控制. 理 ...

  4. 交换机的默认网关(跨网段telnet)

    实验要求:配置一台交换机,并配置默认网关,使不同网段的主机能够远程telnet连接到交换机 拓扑图如下: 交换机配置: enable 进入特权模式 configure terminal 进入全局模式 ...

  5. Linux学习笔记(11)linux网络管理与配置之一——配置路由与默认网关,双网卡绑定(5-6)

    Linux学习笔记(11)linux网络管理与配置之一——配置路由与默认网关,双网卡绑定(5-6) 大纲目录 0.常用linux基础网络命令 1.配置主机名 2.配置网卡信息与IP地址 3.配置DNS ...

  6. 一个奇怪的网络故障 默认网关为0.0.0.0(Windows)

    用IPCONFIG命令看到的情况是这样: Windows IP 配置 以太网适配器 本地连接 : 连接特定的 DNS 后缀 . . . . . . . : 本地链接 IPv6 地址. . . . . ...

  7. linux下ifconfig, DNS以及route配置

    转载:http://blog.csdn.net/wangjingfei/article/details/5283632/ 熟悉使用ifconfig 会非常方便. ifconfig eth0 新ip 然 ...

  8. Network基础(五):配置静态路由、配置浮动路由、配置多路由的静态路由、配置默认路由

    一.配置静态路由 目标: 配置路由接口IP地址并通过静态路由的配置实现全网的互通. 方案: 按如下网络拓扑配置接口IP地址并通过静态路由的配置实现全网的互通如下图所示: 步骤: 步骤一:配置静态路由 ...

  9. Centos双网卡配置默认路由

    Centos6.5 双网卡,我们只需要一个默认路由,如果两个都有或都没有会有一系列的问题 [root@centos]# vi /etc/sysconfig/network修改以下内容NETWORKIN ...

随机推荐

  1. tensorflow tfdbg 调试手段

    https://blog.csdn.net/gubenpeiyuan/article/details/82710163 TensorFlow 调试程序 tfdbg 是 TensorFlow 的专用调试 ...

  2. VMWare 下安装 MSDN版 MS-DOS 6.22

    最近有些怀旧,刚从孔夫子旧书网淘回一本<Borland 传奇>,里面讲到了很多DOS时代的经典软件,特别想尝试一下~比如:Turbo Pascal.SideKick.Borland C/C ...

  3. ArrayList代码学习

    ArrayList (数组链表)使用Object数组作为存储. /** * The array buffer into which the elements of the ArrayList are ...

  4. lsof 查看文件被哪个进程占用

    lsof 是什么意思? 答: list open files 查看某个文件被哪些进程在读写 lsof 文件名 查看某个进程打开了哪些文件lsof –c 进程名lsof –p 进程号 lsof用法小全 ...

  5. Webhook 实践 —— 自动部署

    https://segmentfault.com/a/1190000007892407 安装nodejs 安装nodejs建议直接下载二进制包,把官网上的64位二进制版本下载地址复制下来,执行 wge ...

  6. 基本够用的php.ini配置文件(CentOS7)

    [PHP] engine = On short_open_tag = Off asp_tags = Off precision = output_buffering = zlib.output_com ...

  7. jquery.cookie.js写入的值没有定义

    这个是插件的基本语法,你写的没错,错就错在你肯定是在本地测试的,cookie是基于域名来储存的.意思您要放到测试服务器上或者本地localhost服务器上才会生效.cookie具有不同域名下储存不可共 ...

  8. [HDFS Manual] CH4 HDFS High Availability Using the Quorum Journal Manager

    HDFS High Availability Using the Quorum Journal Manager HDFS High Availability Using the Quorum Jour ...

  9. bat搜集

    1. 删除文件夹下指定名称的所有子文件夹 @echo off ::设置要保留的文件夹名,多个文件夹之间用英文逗号隔开,如果包含空格或英文逗号,英文&以及其它一些特殊字符的名字,请把该完整名字用 ...

  10. C++ 智能指针七

    /* 智能指针weak_ptr */ #include <iostream> #include <string> #include <memory> /* weak ...