route 配置默认网关

影响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 有地时候没有(工作可能有)

转载于:https://www.cnblogs.com/zhaojingyu/p/9110961.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值