【聚杰网Linux】修改Linux静态路由
内网:有两个网段10.10.100.0/24和10.10.101.0/24,
服务器ip: a.b.c.d 外网网关e.f.g.h 服务器内网卡10.10.100.254
内网10.10.101.0/24网段的机器无法访问10.10.100.254这台机器。
登陆服务器查看路由表:
[root@www conf]# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.10.100.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth1
default e.f.g.h 0.0.0.0 UG 0 0 0 eth1
因此可以看到在10.10.100.254服务器上无法看到10.10.101.0/24的路由选择表路由条目,因此可以两种方法添加,
临时性的:
route add -net 10.10.101.0 netmask 255.255.255.0 gw 10.10.100.1
但重新启动后就会失效.因此在/etc/sysconfig/network-scripts/目录下建立文件。因为我们是做内网的路由,并且内网网卡为eth0,因此我们建立route-eth0文件如下:
[root@www network-scripts]# cat route-eth0
10.10.101.0/24 via 10.10.100.1 dev eth0
[root@www network-scripts]# /etc/rc.d/init.d/network restart启动生效
[root@www network-scripts]# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
10.10.101.0 10.10.100.1 255.255.255.0 UG 0 0 0 eth0
10.10.100.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth1
default e.f.g.h 0.0.0.0 UG 0 0 0 eth1
修改外网网关如下:
[root@www conf]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=www.test.cn
GATEWAY=e.f.g.h