002-linux策略路由

linux 篇linux

netstat -rn 的做用,将网络路由表直接显示出来服务器

[root@Carlton ~]# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
172.18.16.0     0.0.0.0         255.255.240.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         172.18.31.253   0.0.0.0         UG        0 0          0 eth0


表示的意思是, 任何地址 经过该172.18.31.253 经过eth0 才可以访问
换句话:到达目标地址0.0.0.0,必须经过eth0 子网掩码是0.0.0.0将包发送到172.18.31.253网关
用表达式表示为:网络

route add -net 0.0.0.0 netmask 0.0.0.0 gw 172.18.31.253 eth1

只添加网关 spa

route add  default gw X.X.X.X 

若是遇到服务器运行命令ifconfig 为空时:code

ifconfig eth0 172.31.1.2 netmask 255.255.255.0 broadcast 172.31.1.255
route add default gw 172.31.1.254路由

而后重启网卡io

相关文章
相关标签/搜索