Linux下实现不同网段之间的访问

本实例要说明的是:实现10.0.0.0/24网段与192.168.2.0/24网段相互访问。 
步骤1:查看本机IP地址 
[root@localhost root]# ifconfig 
eth0 Link encap:Ethernet HWaddr 00:0C:29:A7:6E:77 
inet addr:10.0.0.120 Bcast:10.0.0.255 Mask:255.255.255.0 
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 
RX packets:2418 errors:0 dropped:0 overruns:0 frame:0 
TX packets:1293 errors:0 dropped:0 overruns:0 carrier:0 
collisions:0 txqueuelen:100 
RX bytes:1000347 (976.9 Kb) TX bytes:192592 (188.0 Kb) 
Interrupt:10 Base address:0x2024 
步骤2:添加路由规则 
[root@localhost root]# route add -net 192.168.2.0/24 eth0 
步骤3:查看路由规则 
[root@localhost root]# route 
Kernel IP routing table 
Destination Gateway Genmask Flags Metric Ref Use Iface 
10.0.0.0 * 255.255.255.0 U 0 0 0 eth0 
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0 
169.254.0.0 * 255.255.0.0 U 0 0 0 eth0 
注:route规则中,必须同时存在两个网段,否则,一个网段的IP地址将无法访问到另一网段的IP地址。 
步骤4:检测本地机(IP:10.0.0.120)与远程机(IP:192.168.2.80)是否可互访。 
[root@localhost root]# ping 192.168.2.80 
PING 192.168.2.80 (192.168.2.80) 56(84) bytes of data. 
64 bytes from 192.168.2.80: icmp_seq=1 ttl=127 time=5.51 ms 
64 bytes from 192.168.2.80: icmp_seq=2 ttl=127 time=3.17 ms 
步骤5:删除路由规则 
[root@localhost root]# route del -net 192.168.2.0/24 eth0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值