码迷,mamicode.com
首页 > 系统相关 > 详细

linux 路由转发实验(软路由)

时间:2016-09-21 23:39:42      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:linux 路由转发

 一。实验网络拓扑

            (R1,R2由 Linux 虚拟机添加双网卡做软路由实现)

            技术分享

             技术分享

   

    二。环境准备:

          (虚拟机网卡需要设置为桥接模式)

          1. 关闭NetworkManager:

            service NetworkNanager stop

           禁止开机自启动:

            chkconfig NetworkNanager off

           清空iptables 条目:

            iptables -F

           开启路由转发功能:(0 :禁用, 1:启用)

            echo 1 > /proc/sys/net/ipv4/ip_forward

           检查路由转发功能开启情况:

            cat /proc/sys/net/ipv4/ip_forward

    

    三。配置网卡:

            配置文件:  /etc/sysconfig/network-scripts/ifcfg-eth#

            1. 删除ifcfg-eth#旧配置文件,并重新建立eth1、eth2配置

                R1:

                eth1(内网):   /etc/sysconfig/network-scripts/ifcfg-eth1

                DEVICE=eth1

                BOOTPROTO=none    #禁用dhcp

                IPADDR=192.168.48.1

                PREFIX=24

                GATEWAY=192.168.48.1


                eth2(外网):   /etc/sysconfig/network-scripts/ifcfg-eth2

                DEVICE=eth2

                BOOTPROTO=none    #禁用dhcp

                IPADDR=10.0.48.1

                PREFIX=8

                GATEWAY=10.0.48.1

               

               R2:

                eth1(内网):   /etc/sysconfig/network-scripts/ifcfg-eth1

                DEVICE=eth1

                BOOTPROTO=none    #禁用dhcp

                IPADDR=172.16.48.1

                PREFIX=16

                GATEWAY=172.16.48.1

                eth2(外网):   /etc/sysconfig/network-scripts/ifcfg-eth2

                DEVICE=eth2

                BOOTPROTO=none    #禁用dhcp

                IPADDR=10.0.48.2

                PREFIX=8

                GATEWAY=10.0.48.2

                配置完成后,需要重启网卡:

                service network restart

               

            2.添加路由信息:

                (直连网络不需要添加路由信息)

                (非直连网络,gw为邻近路由的最近端口IP)

                R1:

                route add -net 172.16.0.0/16 gw 10.0.48.2 dev eth2

                R2:

                route add -net 192.168.48.0/24 gw 10.0.48.1 dev eth2


               3. 测试:

                添加 192.168.48.0/24  与 172.16.48.0/16 网络内主机,互ping 测试即可

                


linux 路由转发实验(软路由)

标签:linux 路由转发

原文地址:http://195175108.blog.51cto.com/10167819/1855002

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!