第一生效文件:/etc/sysconfig/network-scripts/ifcfg-eth0

[root@newname ~]# grep -i gate /etc/sysconfig/network-scripts/ifcfg-eth3GATEWAY=192.168.0.1

 

第二生效文件:/etc/sysconfig/network

[root@newname ~]# grep -i gate /etc/sysconfig/network
GATEWAY=192.168.0.1

 

查看路由命令:route -n,或netstat -rn

[root@oldboy ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.2.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 eth3
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1003   0        0 eth3
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth3
[root@oldboy ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.0.2.0        0.0.0.0         255.255.255.0   U         0 0          0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 eth3
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth3
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 eth3

其中,最后一行为默认网关,不管去哪个网络,都从默认网关192.168.0.1出去。

 

设置(添加和删除,屏蔽)路由:命令行优先,且临时生效:

添加默认网关 为10.0.0.1
root@text:~# route add default gw 10.0.0.1
删除默认网关
root@text:~# route del default gw 10.0.0.1

添加到主机的路由
root@text:~# route add -host 192.168.10.2 dev eth3
root@text:~# route -n
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.10.2     *               255.255.255.255 UH    0      0        0 eth3
删除到主机的路由
root@text:~# route del -host 192.168.10.2 dev eth3

添加到网络192.168.55.0的路由
root@text:~# route add -net 192.168.55.0 netmask 255.255.255.0 eth3
屏蔽到网路192.168.55.0的路由
route add -net 192.168.55.0 netmask 255.255.255.0 reject

删除到网络的路由
root@text:~# route del -net 192.168.55.0 netmask 255.255.255.0 eth3

 

posted on 2019-11-21 11:21  Zoe233  阅读(2634)  评论(0编辑  收藏  举报