centos设置默认网关

第一生效文件

[root@oldboy ~]# grep -i gate /etc/sysconfig/network-scripts/ifcfg-eth0
GATEWAY=192.168.1.1

第二生效文件

[root@oldboy ~]# grep -i gate /etc/sysconfig/network

GATEWAY=192.168.1.1

第三:命令行有限,且临时生效

查看网关命令:route-n和netstat -n(两个命令都是查看网关的)

[root@oldboy ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.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.1.1     0.0.0.0         UG    0      0        0 eth0
[root@oldboy ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.1.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         0 0          0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth0

route add default gw 192.168.1.1

route del default gw 192.168.1.1

route功能很多,不仅仅配置默认网关,网络(静态)路由。

标签:Centos 发布于:2019-11-17 02:32:55