影響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 有地時候沒有(工作可能有)