修改Linux静态路由

 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

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 

source : google

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值