1. 第一生效文件
[root@oldboy ~]# grep -i gate /etc/sysconfig/network-scripts/ifcfg-eth0
GATEWAY=172.16.2.254
2. 第二生效文件
[root@kali ~]# grep -i gate /etc/sysconfig/network
GATEWAY=172.16.2.254
3. 命令行优先,且临时生效—添加默认网关
[root@kali ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.77.0 0.0.0.0 255.255.255.0 U 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 192.168.77.2 0.0.0.0 UG 0 0 0 eth0
[root@kali ~]# **route add default gw 192.168.77.254**
[root@kali ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.77.0 0.0.0.0 255.255.255.0 U 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 192.168.77.254 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.77.2 0.0.0.0 UG 0 0 0 eth0
4 第四:删除默认网关
[root@kali ~]# route del default gw 192.168.77.2
[root@kali ~]# ping www.linux.ac.cn
ping: unknown host www.linux.ac.cn
[root@kali ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.77.0 0.0.0.0 255.255.255.0 U 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 192.168.77.254 0.0.0.0 UG 0 0 0 eth0