linux跨服务器跨网段配置,linux添加跨网段网关

1.eth0的ip地址为10.1.1.1/24

路由信息如下

# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.150.0   0.0.0.0         255.255.255.0   U     0      0        0 mgmt

10.1.1.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     1007   0        0 mgmt

0.0.0.0         192.168.150.254 0.0.0.0         UG    0      0        0 mgmt

2.直接添加路由网关和出接口相同网段会失败

# route add -net 2.0.0.0/8 gw 20.1.1.1 eth0

SIOCADDRT: No such process

3.正确配置方式:

#route add -net 0.0.0.0 eth0

#route add -net 2.0.0.0/8 gw 20.1.1.1 eth0

4.显示路由信息,配置成功

# route -n

Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

192.168.150.0   0.0.0.0         255.255.255.0   U     0      0        0 mgmt

10.1.1.0        0.0.0.0         255.255.255.0   U     0      0        0 eth0

169.254.0.0     0.0.0.0         255.255.0.0     U     1007   0        0 mgmt

2.0.0.0         20.1.1.1        255.0.0.0       UG    0      0        0 eth0

0.0.0.0         0.0.0.0         0.0.0.0         U     0      0        0 eth0

0.0.0.0         192.168.150.254 0.0.0.0         UG    0      0        0 mgmt

ps

一种使用场景:

拓扑:

linux1-eth0——–eth0-linux2-eth1

linux1:

eth0 10.1.1.1/24

linux2:

eth0 20.1.1.1/24

eth1 2.2.2.2/24

1.linux1

route add -net 0.0.0.0 eth0

route add -net 2.0.0.0/8 gw 20.1.1.1 eth0

2.linux2

route add -net 0.0.0.0 eth0

route add -net 10.0.0.0/8 gw 10.1.1.1 eth0

3配置如上后linux1 ping 2.2.2.2可通

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值