修改Linux 靜態路由

版主: stnet253

回覆文章
tony
文章: 585
註冊時間: 2012-02-26, 07:04
聯繫:

修改Linux 靜態路由

未閱讀文章 tony »

內網:有兩個網段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
回覆文章

誰在線上

正在瀏覽這個版面的使用者:Semrush [Bot] 和 1 位訪客