vyatta软件路由器配置指南11

来源:百度文库 编辑:神马文学网 时间:2024/03/28 17:57:23
 

vyatta软件路由器配置指南

路由器, vyatta, 指南, 软件  Vyatta是linux下知名的开源路由器项目,在其官方的测试中性能甚至超过了cisco 7200系列路由器,可以支持RIP、OSPF、BGP等路由协议以及VPN、NAT、HA等特性。

  我们的测试是希望在ESXi中安装Vyatta的虚拟机来替代cisco 1800和2800系列的路由器,或者作为cisco路由器的一个备份,测试的内容只有nat和trunk的支持。

  1、首先从[url]http://www.vyatta.com[/url]下载vyatta的安装ISO文件,在ESXi中新建一个虚拟机,分配2块网卡,将下载的ISO文件挂载为光驱。

  2、在ESXi的配置中,将第2块网卡port group的vlan id改为4095

  3、启动虚拟机,用缺省的用户名/密码 root/vyatta登陆系统

  4、安装vyatta到硬盘上

  install-system

  5、进入配置模式

  configure

  6、配置系统名称

  set system host-name vyatta-1

  7、设置DNS

  set system name-server x.x.x.x

  8、设置缺省网关

  set system gateway-address 10.0.0.1

  9、定义外网接口IP地址

  set interfaces ethernet eth0 address 10.0.0.2/24

  10、定义内网口IP地址

  set interfaces ethernet eth1 vif 6 address 192.168.6.1/24

  set interfaces ethernet eth1 vif 7 address 192.168.7.1/24

  set interfaces ethernet eth1 vif 8 address 192.168.8.1/24

  11、设置NAT策略

  set service nat rule 1 source address 192.168.0.0/16

  set service nat rule 1 outbound-interface eth0

  set service nat rule 1 type masquerade

  12、保存和启用配置

  commit

  save



vyatta最新的版本是VC5.12,如果要学习juniper的命令行,可用该软件搭建实验环境。下文为本人2007年所写,如果是通过CLI配置,可参考本文。

vyatta软件路由器配置指南
早在2006年8月就看到vyatta的报道了,当时马上去down了ISO文件下来,并刻录到光盘,但后来因为工作忙,一直没时间去研究,结果一晃就到了2007年。
    最近因工作需要,开始研究软路由的性能和功能,于是从柜子里拿出布满灰尘的刻录光盘,在家里那台PIII 733/256M/40G兼容PC上做实验。

第一部分、准备工作
    网卡两张,分别是8139和3com 905。
    安装很简单,将ISO文件通过nero刻录到光盘;然后进入CMOS设置为CDROM为第一启动设备(注意:如果用VMWARE则不必刻录,可以直接以ISO文件做启动文件,vmware上安装vyatta不在本次讨论之中)
   
第二部分、安装系统

   系统引导完毕后,将出现:
        vyatta login:
   输入root:
        vyatta login: root
        Password: vyatta
   输入vyatta,此时看到~ #出现:
        ~ #
   接着输入xorpsh,将进入shell模式:
        root@vyatta>
   进入了shell模式了,是不是就大功告成了呢?当然不是,网卡是否安装成功还不知道吧?如何判断两张网卡是否安装好了呢?输入命令root@vyatta>show interface ethernet ?,注意要有个问号,回车之后,系统将有如下显示:
   root@vyatta>show interfaces ethernet ?
   Possible completions:
     eth0    show ethernet interface information
     eht1    show ethernet interface information
   上面出现eth0和eth1字样,可以作为两张网卡安装成功的依据(通过上述方法判断是我自己总结的一个土方法,在notebook上只有一张8139的网卡,通过VMWARE环境试验时,验证过该方法同样管用)。

   输入configure进入配置模式:   
   root@vyatta>configure
   root@vyatta#

第三部分、IP地址的配置
    假设将eth0作为外网口,eth1作为内网口。由于本人用的小区宽带且分配的是私有IP网段:192.168.10.x,故本文中将192.168.10.x作为公网ip地址。
     外网eth0的IP为192.168.10.20,其网关是192.168.10.1
     内网eth1的IP为192.168.1.1
1、配置eth0

   root@vyatta#set interfaces ethernet eth0 address 192.168.10.20 prefix-length 24
  上面的命令设置eth0接口的ip地址为192.168.10.20 掩码255.255.255.0写为24,表示24位掩码。
  
2、配置eth1
   root@vyatta#set interfaces ethernet eth1 address 192.168.1.1 prefix-length 24
   上面的命令设置eth1接口的ip地址为192.168.1.1 掩码255.255.255.0写为24,表示24位掩码。
3、添加静态路由
   root@vyatta#set set protocols static route 0.0.0.0/0 next-hop 192.168.10.1
  上面的命令设置静态路由,0.0.0.0/0 next-hop 192.168.10.1表示到达外网任意地址,都通过网关192.168.10.1出去。
4、设置NAT
root@vyatta# create service nat rule 1
[edit]
root@vyatta# edit service nat rule 1
[edit service nat rule 1]
root@vyatta# set type source
[edit service nat rule 1]
root@vyatta# set translation-type masquerade
    指定NAT转换的模式为隐藏内网模式,通俗点讲就是所有内网地址都可通过这种方式访问外网。
[edit service nat rule 1]
root@vyatta# set outbound-interface eth0
    指定外网口为eth0
[edit service nat rule 1]
root@vyatta# set protocols all
[edit service nat rule 1]
root@vyatta# set source network 192.168.1.0/24
    表示源网络为192.168.1.x网段的所有地址
[edit service nat rule 1]
root@vyatta# set destination network 0.0.0.0/0
    表示目的网络为任意地址
[edit service nat rule 1]
root@vyatta# top
[edit]
root@vyatta#commit

用另外一台电脑的网卡和eth1口连接上,设置成192.168.1.2或其它IP,网关指向192.168.1.1,DSN设置成当地电信公布的DNS。
先ping 192.168.1.2,看网卡是否正常。
再ping 192.168.1.1,看网关(即路由器的内网口)是否正常。
接着ping 192.168.10.20,看路由器的外网口是否正常。
最后ping 192.168.10.1,看(电信)出口是否正常。
如果上述都ping通,如果你DNS设置正确,你的路由器正式运行了。

--------------------------------------------------------------
    后记:
    安装成功后,马上用僵尸DDOS攻击工具做TCP、UDP、ICMP攻击,以验证系统的健壮性,VYATTA的抗攻击能力比ROS要强,遗憾的是,结果和ROS一样,还是不能抵挡高强度的DDOS攻击,路由器很快崩溃,键盘没反应,需要重新启动电脑才行。
    回头专门写个攻击实验的帖子放上来。

    附录:常用命令

1、查看配置信息
        vyatta@vyatta# show
2、提交配置
        vyatta@vyatta# commit
3、退出不保存
        vyatta@vyatta# exit discard
4、打开web管理功能
        vyatta@vyatta#set service http port 80
5、打开telnet管理功能
        vyatta@vyatta#set service telnet port 23
6、退出
        vyatta@vyatta# exit或者root@vyatta# quit
7、up或者top退出命令
        root@vyatta# up  /逐层退出,类似于exit或quit
        root@vyatta# top /一步退出,类似于DOS命令下的cd \命令
8、退出show模式
I’m a sell out, it’s official. I’ve had such an overwhelming response, according to my stats, on the Vyatta router story that I had to do another. So let’s grab some documentation and get started. By the way here’s the quick start guide, and the command reference for your convenience. I do this because to get the command reference they want you to register and give your e-mail address, unless you know the direct link. Ok, so back at the barn….. I set my test board back up but hooked to my KVM on my main machine and plugged into my network. My main box is running DHCP with Dynamic DNS updates to my in house DNS server on the same box and getting routed out the house through the same box via a NAT firewall through my 8Mb/512Kb cable modem. The main machine is a AMD FX2 3800 with 2GB and dual onboard Gigabit NICs. The test board is from a thin client (got it off an auction) and just a little oversized from a standard mini-itx, which has internal 100Mb NIC and basic IO including audio, video, serial, usb, etc. It is running an unknown VIA 1Ghz processor with 512MB ram and a 1GB CF card for storage, as well as being loaded with a second D-link 100Mb NIC in the single PCI slot. Now that we have specs out of the way, let’s fire this thing off.

So I started booting the test board and then pulled up the docs on a different screen to learn how to setup a few basics. Skimming the docs I learned that they seem to have taken a lesson from the routing industry and have created a Command Line Interface similar to popular commercial routers. You can have different users with different privileges and then there are different modes for working in the router. The first mode is called “Operational Mode” which allows you to run basic utilities for diagnostics and show settings for troubleshooting. To set anything you need to enter the “Configuration Mode” with the command configure, which allows you to change and commit settings. We’ll hit that in a minute. First let’s login. Default credentials are root with a password of vyatta for your privileged user, and username vyatta with password of vyatta for your non-privileged user. Now let’s check our connectivity and see if we can talk to the network we are plugged into. Vyatta has the familiar tab completion for commands found in both UNIX systems and commercial routers, which helps you muttle your way through with minimal referencing of the docs. Logged in as the root user I did the following…..

Last login: Fri Aug 8 01:28:13 2008 from 192.168.60.1
Linux vyatta 2.6.23-1-486-vyatta #1 SMP Sat Apr 19 12:37:43 PDT 2008 i686
Welcome to Vyatta.
This system is open-source software. The exact distribution terms for
each module comprising the full system are described in the individual
files in /usr/share/doc/*/copyright.
vyatta:~# show interfaces ethernet
Interface IP Address State Link Description
eth0 192.168.60.252/24 up up
eth1 - up down
vyatta:~#

Now you can see in this terminal output that I already have an address, but it didn’t to start with, so I need to configure that……

vyatta:~# configure
[edit]
root@vyatta# set interfaces ethernet eth0 address dhcp
[edit]
root@vyatta#

Ok so far so good. Now let’s setup ssh so we don’t need a monitor and keyboard attached to it.

root@vyatta# set service ssh port 22
[edit]
root@vyatta# set service ssh allow-root
[edit]
root@vyatta# commit
There should be some text here about generating the ssh keys and restarting the service.
root@vyatta# exit
exit
vyatta:~#

Ok so now we should be able to login to this thing. Let’s go find the IP address and check the interface.

vyatta:~# show interfaces ethernet detail
eth0: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:16:ec:54:fd:e8 brd ff:ff:ff:ff:ff:ff
inet 192.168.60.252/24 brd 192.168.60.255 scope global eth0
inet6 fe80::216:ecff:fe54:fde8/64 scope link
valid_lft forever preferred_lft forever

RX: bytes packets errors dropped overrun mcast
76484 719 0 0 0 0
TX: bytes packets errors dropped carrier collisions
54652 443 0 0 0 0

eth1: mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:40:05:08:9e:26 brd ff:ff:ff:ff:ff:ff

RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collisions
0 0 0 0 0 0

vyatta:~#

Looks good to me. Now go ssh over to it and play. I will post more to come1、准备工作
到vyatta网站下载软件http://www.vyatta.com/download/,有两个版本可以下载,一个是iso版本,另一个是虚拟机版本。
2、安装系统
iso版本安装,将ISO文件通过nero刻录到光盘;然后进入CMOS设置为CDROM为第一启动设备,这需要你的机器真的拥有两块以上的网卡。
虚拟机版,直接在vmware中打开就可以可了,系统引导完毕后,将出现:
vyatta login: root  
Password:vyatta
    ~ # 进入linux 的shell模式下
接着输入xorpsh,进入路由器配置模式。
root@vyatta>
如果,
vyatta login: vyatta  
Password:vyatta
会直接进入路由配置模式。
3、配置路由器
我们需要实现的任务很简单,就是在路由器上做个nat,让藏在后面的多台pc可以共享上网。

将eth0作为外网口,eth1作为内网口,本人用的光电的小区宽带且分配的是私有IP网段:10.113.18.244。
外网eth0的IP为10.113.18.244,其网关是10.113.18.254。内网eth1的IP为10.113.19.244。
root@vyatta#set interfaces ethernet eth0 address 10.113.18.244 prefix-length 24 //外网端口ip地址配置
root@vyatta#set interfaces ethernet eth1 address 10.113.19.244 prefix-length 24 //内网端口ip地址配置
root@vyatta#set set protocols static route 0.0.0.0/0 next-hop 10.113.18.254       //静态路由
root@vyatta# set service nat rule 1      //建立nat
root@vyatta# edit service nat rule 1
[edit service nat rule 1]
root@vyatta# set type source
[edit service nat rule 1]
root@vyatta# set translation-type masquerade              //转换类型,还有dynamic、static可选
[edit service nat rule 1]
root@vyatta# set outbound-interface eth0                  //定义出口
[edit service nat rule 1]
root@vyatta# set protocols all                            //允许通过协议
[edit service nat rule 1]
root@vyatta# set source network 10.113.19.0/24            //需要转换的地址段
[edit service nat rule 1]
root@vyatta# set destination network 0.0.0.0/0     //需要到达的网络
[edit service nat rule 1]
root@vyatta#top        //返回顶端目录下
root@vyatta#commit        //最后需要通过这个命令使刚才的配置生效,比思科人性化的地方
配置好后,可以ping 10.113.18.254,然后把eth1接到另一个虚拟机windows2003上,Win2003只需要配置ip:10.113.19.246
gateway:10.113.19.244即可,ping 10.113.18.254,路由器上可以通过show nat statistic看一下有无转换。
这个路由器还可以实现如dhcp DMZ firewall等功能,大家可以自己配置一下。

常用的命令
*、show查看配置信息
*、commit提交配置
*、exit discard退出不保存
*、set service http port 80打开web管理功能
*、set service telnet port 23打开telnet管理功能
*、exit或者 quit退出
*、up或top返回上一级或顶级

配置缩略图:

vyatta虚拟机安装2007年02月25日 星期日 11:23

下载官方的最新镜像  我用的是vyatta-livecd-VC2.iso

虚拟机上,不需要多大的内存,但是要保证两个网卡,毕竟我们是做路由(外网+内网)最基本的,

如何设置这些,我就不详细说了,有不明白的可以到QQ群:1343380 找我,或者直接给我邮件

ty2002520@sohu.com  tangyucheng@piertek.cn  都可以,注明vyatta就可以了。

光盘启动到最后应该是下面的界面:

这时登录进去,设置下ip就可以领略下vyatta的风采了! 这要介绍硬盘安装,这里略过,继续执行:root   密码:vyatta

vyatta:~#  install-system

后面需要注意的就是,根分区和配置分区,根分区大于450M就可以了,剩下的空间给配置用。

一路回车,最后在把光盘拿出来就可以了,重启和上面一样的界面。

现在我们开始设置下这个路由。

用root 密码 vyatta登录

vyatta:~#  xorpsh   (登录到路由的shell)

vyatta:~# configure (TAB键可以补全)

开始设置:

1、路由器的名字

root@vyatta# set system host-name loveflagR1  (名字随便写 呵呵)
[edit]
root@vyatta# set system domain-name loveflag.cn

[edit]
root@vyatta# commit     (相当于保存退出)
OK
[edit]
root@loveflagR1# 

2、设置内外网络环境

假设我的网络环境是:内网 192.168.10.1/24  外网:192.168.1.147/24  还可以在web界面修改。

root@loveflagR1# set interfaces ethernet eth0 address 192.168.1.147 prefix-length 24
[edit]
root@loveflagR1# set interfaces ethernet eth1 address 192.168.10.1prefix-length 24
[edit]
root@loveflagR1# commit
OK
[edit]
root@loveflagR1# show interfaces  应该看见刚才设置的IP地址

为了以后管理路由,还可以在这里设置下连接方式  telnet  ssh http 1、telnet 设置 root@loveflagR1# set service telnet
[edit]
root@loveflagR1# commit
OK
[edit]
root@loveflagR1# 2、ssh设置 root@loveflagR1# set service ssh port 8022  端口写个你自己知道的就行。
[edit]
root@loveflagR1# commit
OK
[edit] 用SSH登录工具可以登录
Last login: Wed Feb 28 10:13:07 2007
Linux vyatta.vyatta.com 2.6.16 #1 Wed Feb 7 15:05:17 PST 2007 i686
Welcome to the Open Flexible Router. The programs included with the OFR system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright. vyatta:~# 

3、http设置 root@loveflagR1# set service http port 8080
[edit]
root@loveflagR1# commit
[edit]
OK
root@loveflagR1#  exit

用vyatta做NAT转发


用vyatta做NAT转发
参考资料 http://space.netexpert.cn/index.php/3371/action_viewspace_itemid_419.html
和情灭的资料 http://hi.baidu.com/%C7%E9%C3%F0%D4%B5%BE%A1
在网盟的论坛上看到情灭提到这个vyatta开源路由软件,情灭说不错的,应该是很有前途的.后来查下资料,说这个开源路由对思科为代表的闭源器产生了不小的冲击,今天晚上就开始用研究一下用vyatta做NAT转发.
首先来做准备工作,我这VM是现成的,就不多说了,要是实际操作的话,应该找个p3级别的CPU.128M内存.810级别的主板.再加上两块8139网卡就行了.一般情况下配置高的机器用来做路由真是一种浪费!闲话少说,书归正传!从http://www.vyatta.com/download/dl_log.php?d=1.0.3/vyatta-livecd-1.0.3.iso 下载vyatta1.0.3版的iso镜像,大家可以直接刻录镜像,在VM下直接导入ISO文件就可以了.不过记着应该在cmos中做光盘启动.
接下来安装系统,开机用光盘引导,

vyatta login: root
Password: vyatta

下面我们在硬盘中安装vyatta,执行如下命令install-system
出现Would you like to continue? [Yes]:
问你是否继续,此步骤将清空你的硬盘上的所有资料,请输入Yes然后回车以继续进行
出现Partition (Auto/Parted/Skip) [Auto]:
询问分区方式,非高手,请选择Auto来自动分区
出现I found the following drives on your system:
hda

Install the image one [hda]:
这里选择你安装的磁盘,这里说一下,1.03不支持scsi和sata的硬盘,所以请使用ide模式的硬盘或者是dom卡,强烈建立使用dom卡,抗震比普通ide硬盘好的多,单硬盘安装,出现了hda了以后直接回车继续,不建议多磁盘安装(完全没这个必要,除非你钱多了需要摆显)

This will destroy all data on /dev/hda.
Continue? (Yes/No)  [No]:
再次强调操作会清空原有磁盘数据,问你是否继续,这里输入Yes回车继续

How big of a root partition should i create ? [256]MB:
问root分区大小,直接默认,回车继续

Which drive should GRUB modify the boot partition on? [hda]:
询问引导信息写到哪个磁盘,单盘直接回车继续

Setting up grub: OK
Done!
/ #

安装完成中,我们用命令reboot重启,
重新启动系统,输入用户名,密码登陆,在终端中输入xorpsh,将进入shell模式.告诉大家个技巧,在终端中(也就是/ #) 输入"?"便可以查看vyatta的命令.
 root@vyatta>
我们先看下网卡是否能正常工作中,在shell中输入命令root@vyatta>show interface ethernet ?,注意要有个问号,回车之后,系统将有如下显示:
root@vyatta>show interface ethernet ?
   Possible completions:
     eth0    show ethernet interface information
     eht1    show ethernet interface information
上面出现eth0和eth1字样,可以作为两张网卡安装成功的依据.
 输入configure进入配置模式: 
   root@vyatta>configure
   root@vyatta#
假设将eth0作为外网口,eth1作为内网口。由于本人用的小区宽带且分配的是私有IP网段:192.168.10.x,故本文中将192.168.10.x作为公网ip地址。
     外网eth0的IP为192.168.10.20,其网关是192.168.10.1
     内网eth1的IP为192.168.1.1
1、配置eth0
 
   root@vyatta#set interfaces ethernet eth0 address 192.168.10.20 prefix-length 24
  上面的命令设置eth0接口的ip地址为192.168.10.20 掩码255.255.255.0写为24,表示24位掩码。
 
2、配置eth1
   root@vyatta#set interfaces ethernet eth1 address 192.168.1.1 prefix-length 24
   上面的命令设置eth1接口的ip地址为192.168.1.1 掩码255.255.255.0写为24,表示24位掩码。
3、添加静态路由
   root@vyatta#set set protocols static route 0.0.0.0/0 next-hop 192.168.10.1
  上面的命令设置静态路由,0.0.0.0/0 next-hop 192.168.10.1表示到达外网任意地址,都通过网关192.168.10.1出去。
4、设置NAT
root@vyatta# create service nat rule 1
[edit]
root@vyatta# edit service nat rule 1
[edit service nat rule 1]
root@vyatta# set type source
[edit service nat rule 1]
root@vyatta# set translation-type masquerade
    指定NAT转换的模式为隐藏内网模式,通俗点讲就是所有内网地址都可通过这种方式访问外网。
[edit service nat rule 1]
root@vyatta# set outbound-interface eth0
    指定外网口为eth0
[edit service nat rule 1]
root@vyatta# set protocols all
[edit service nat rule 1]
root@vyatta# set source network 192.168.1.0/24
    表示源网络为192.168.1.x网段的所有地址
[edit service nat rule 1]
root@vyatta# set destination network 0.0.0.0/0
    表示目的网络为任意地址
[edit service nat rule 1]
root@vyatta# top
[edit]
root@vyatta#commit
接着使用save来保存设置
save filename,来保存一个设置,如果想保存为开机调用的设置文件,请使用如下命令
save config.boot
下面的设置hostname以及保存设置的过程
vyatta@vyatta# set system host-name myrouter
[edit]
vyatta@vyatta# commit
OK
[edit]
vyatta@myrouter# save config.boot
Save done.

vyatta@myrouter# show system host-name
    host-name: "myrouter"
 
[edit]

  附录:常用命令
1、查看配置信息
 vyatta@vyatta# show
2、提交配置
 vyatta@vyatta# commit
3、退出不保存
 vyatta@vyatta# exit discard
4、打开web管理功能
 vyatta@vyatta#set service http port 80
5、打开telnet管理功能
 vyatta@vyatta#set service telnet port 23
6、退出
 vyatta@vyatta# exit或者root@vyatta# quit
7、up或者top退出命令
 root@vyatta# up  /逐层退出,类似于exit或quit
 root@vyatta# top /一步退出,类似于DOS命令下的cd \命令
8、退出show模式
  ctrl+c