route add -net 10.10.101.0 netmask 255.255.255.0 gw 10.10.100.1
cat route-eth0
10.10.101.0/24 via 10.10.100.1 dev eth0
/etc/rc.d/init.d/network restart
netstat -r
[root@1314it network-scripts]# cat /etc/sysconfig/network-scripts/route-eth0
123.123.123.0 via 156.156.156.156 dev eth0
[root@1314it network-scripts]#
已測試成功 重新開機網絡會執行此檔案
= = =
内網:有兩個網段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
[root@www network-scripts]# /etc/rc.d/init.d/network restart啟動生效
[root@www network-scripts]# netstat -r
10.10.101.0 10.10.100.1 255.255.255.0 UG 0 0 0 eth0
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
source : google