Using vtysh

The vtysh tool provides an interactive interface into the zebra routing manager and each routing daemon. vtysh allows you to examine and modify the configuration of each program in the Zebra suite. Listing 7.6 shows a vtysh session in which the current zebra configuration is examined. In a later example, this configuration will be modified with vtysh.

Listing 7.6: Examining zebra.conf through the vtysh Interface

[root]# cat /etc/zebra/zebra.conf password Wats?Watt? enable password CHLLlns [root]# service zebra start Starting zebra: [ OK ] [root]# telnet localhost zebra Trying Connected to localhost. Escape character is IA]'.

Hello, this is zebra (version 0.91a). Copyright 1996-2001 Kunihiro Ishiguro.

User Access Verification Password: Wats?Watt?> enable Password: CHLLlns write terminal

Current configuration: !

password Wats?Watt? enable password CHLLlns !

interface lo !

interface eth0 !

line vty

Listing 7.6 starts our sample vtysh session. We begin by displaying the current zebra.conf file. A minimal zebra.conf file must exist before zebra can be configured through the vtysh interface. The minimal configuration file must contain the passwords required for vtysh access. The first password is required to start the vtysh session. The second password is required to enter enable mode. You must be in enable mode to view or modify the configuration.

In addition to requiring a minimal configuration, the daemon must be up and running before it can be configured from the vtysh interface, as illustrated by the service zebra start command shown in Listing 7.6. The vtysh interface is invoked by making a telnet connection to the running daemon. Notice in Listing 7.6, we telnet to the zebra port on the local host. For this to work, the port number must be defined in the /etc/services file. If the zebra port is not defined on your system, you must telnet to port 2601. The port numbers from the services file on our sample system are shown in Listing 7.7.

Listing 7.7: The Port Numbers Used by the Zebra Suite

$ tail -8


# Local services


2 600/tcp

# zebra service


2 601/tcp

# zebra vty


2 602/tcp

# RIPd vty


2 603/tcp

# RIPngd vty


2 604/tcp

# OSPFd vty


2 605/tcp

# BGPd vty


2 60 6/tcp

# OSPF6d vty

Every routing daemon has its own port number. Before any of these can be configured by vtysh, a minimal configuration file containing the necessary passwords must be created for the daemon, and the daemon must be up and running. For example, to use the vtysh interface with ripd, you must first create a minimal ripd.conf file and start ripd. The first two steps shown in Listing 7.6 apply to all of the daemons.

After connecting to the zebra routing manager in Listing 7.6, the first password is entered in response to the Password: prompt. This password starts the vtysh session. The enable command is entered to invoke enable mode. We again receive a password prompt, but this time it is for the password defined by the enable password command in the zebra.conf configuration file. After that password is entered, enable mode commands can be used.

The first enable mode command in Listing 7.6 is write terminal, which displays the current configuration on the terminal screen. Notice that this configuration is different from the two-line configuration shown in response to the cat command. The write terminal command displays the configuration that is being used, which includes various defaults. Notice that all of the interfaces on the system, lo and eth0, are used by default. Also note the line vty command. This command appears in the configuration file when the configuration can be modified from the vtysh interface, which is the default.

Having examined the existing configuration, we are ready to customize it to our needs. Listing 7.8 is a continuation of the session shown in Listing 7.6.

Listing 7.8: Reconfiguring zebra.conf through the vtysh Interface configure terminal hostname junko junko(config)# log file /var/log/zebra.log junko(config)# interface eth0 junko(config-if)# ip address

junko(config-if)# multicast junko(config-if)# exit junko(config)# exit junko# write file

Configuration saved to /etc/zebra/zebra.conf junko# exit

Connection closed by foreign host. [root]# cat /etc/zebra/zebra.conf !

! Zebra configuration saved from vty

hostname junko password Wats?Watt? enable password CHLLlns log file /var/log/zebra.log !

interface lo !

interface eth0 ip address multicast

line vty

Listing 7.8 picks up where Listing 7.6 ended. We are still in enable mode, and all of the vtysh commands in Listing 7.8, except for the exit commands, can be entered only in enable mode.

The configure terminal command tells the system that configuration commands will be entered from the vtysh interface. As each configuration command is entered, vtysh checks it for syntax errors, which is one of the best reasons for entering configuration commands through the vtysh interface. The commands hostname, interface, ip address, and multicast (shown in Listing 7.8) are basic configuration commands found in the zebra.conf file. In fact, all of these commands were discussed earlier when we looked at the zebra.conf example in Listing 7.5.

Notice how the vtysh command prompt changes to indicate the different modes of operation. Listing 7.6 shows that the prompt for standard mode, called view mode, is a dollar sign ($), and that the prompt for enable mode is a hash mark (#). When the session enters configuration mode in Listing 7.8, the prompt indicates this with a (config) string. Furthermore, the prompt string changes to indicate what is being configured. For example, the string (config-if)indicates that an interface is being configured. Also notice that each time an exit command is entered, vtysh exits the current mode until the final exit command ends the session.

The new configuration is stored in the zebra.conf file by the write file command. The final exit command in Listing 7.8 ends the session that began in Listing 7.6. A cat of the zebra.conf file shows that it has changed substantially from the zebra.conf file that was displayed at the start of Listing 7.6. The original zebra.conf file is not gone, however. vtysh saves the previous configuration file with a .sav extension when it writes the new file. The old zebra.conf file is now stored in /etc/zebra with the name zebra.conf.sav.

The vtysh interface is a tool intended to simplify a complex configuration problem. In general, however, Linux routers do not have highly complex configurations; and the configurations, once set, do not change frequently. Additionally, a small configuration file must be created before vtysh can be used, and the final configuration files are often not much larger than the minimal ones that must be created by hand. For these reasons, you may find vtysh more useful as a tool for examining the router configuration than as a tool for modifying the configuration. Personally, I like vtysh; but if you prefer, you can build Zebra configuration files with your favorite text editor. It's up to you.

The following sections show a few reasonable Linux Zebra configurations. We configure a host to run RIPv2, an interior router to run RIPv2 and OSPF, and an exterior router to run OSPF and BGP.

Was this article helpful?

0 0

Post a comment